~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to solr/core/src/java/org/apache/solr/schema/FieldProperties.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 
 * contributor license agreements.  See the NOTICE file distributed with
4
 
 * this work for additional information regarding copyright ownership.
5
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 
 * (the "License"); you may not use this file except in compliance with
7
 
 * the License.  You may obtain a copy of the License at
8
 
 *
9
 
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 
 *
11
 
 * Unless required by applicable law or agreed to in writing, software
12
 
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 
 * See the License for the specific language governing permissions and
15
 
 * limitations under the License.
16
 
 */
17
 
 
18
 
package org.apache.solr.schema;
19
 
 
20
 
import java.util.Map;
21
 
import java.util.HashMap;
22
 
 
23
 
/**
24
 
 * @version $Id: FieldProperties.java 1145645 2011-07-12 16:12:49Z rmuir $
25
 
 * 
26
 
 * @lucene.internal
27
 
 */
28
 
public abstract class FieldProperties {
29
 
 
30
 
  // use a bitfield instead of many different boolean variables since
31
 
  // many of the variables are independent or semi-independent.
32
 
 
33
 
  // bit values for boolean field properties.
34
 
  protected final static int INDEXED             = 0x00000001;
35
 
  protected final static int TOKENIZED           = 0x00000002;
36
 
  protected final static int STORED              = 0x00000004;
37
 
  protected final static int BINARY              = 0x00000008;
38
 
  protected final static int OMIT_NORMS          = 0x00000010;
39
 
  protected final static int OMIT_TF_POSITIONS   = 0x00000020;
40
 
  protected final static int STORE_TERMVECTORS   = 0x00000040;
41
 
  protected final static int STORE_TERMPOSITIONS = 0x00000080;
42
 
  protected final static int STORE_TERMOFFSETS   = 0x00000100;
43
 
 
44
 
 
45
 
  protected final static int MULTIVALUED         = 0x00000200;
46
 
  protected final static int SORT_MISSING_FIRST  = 0x00000400;
47
 
  protected final static int SORT_MISSING_LAST   = 0x00000800;
48
 
  
49
 
  protected final static int REQUIRED            = 0x00001000;
50
 
  protected final static int OMIT_POSITIONS      = 0x00002000;
51
 
  
52
 
  static final String[] propertyNames = {
53
 
          "indexed", "tokenized", "stored",
54
 
          "binary", "omitNorms", "omitTermFreqAndPositions",
55
 
          "termVectors", "termPositions", "termOffsets",
56
 
          "multiValued",
57
 
          "sortMissingFirst","sortMissingLast","required", "omitPositions"
58
 
  };
59
 
 
60
 
  static final Map<String,Integer> propertyMap = new HashMap<String,Integer>();
61
 
  static {
62
 
    for (String prop : propertyNames) {
63
 
      propertyMap.put(prop, propertyNameToInt(prop));
64
 
    }
65
 
  }
66
 
 
67
 
 
68
 
  /** Returns the symbolic name for the property. */
69
 
  static String getPropertyName(int property) {
70
 
    return propertyNames[ Integer.numberOfTrailingZeros(property) ];
71
 
  }
72
 
 
73
 
  static int propertyNameToInt(String name) {
74
 
    for (int i=0; i<propertyNames.length; i++) {
75
 
      if (propertyNames[i].equals(name)) {
76
 
        return 1 << i;
77
 
      }
78
 
    }
79
 
    return 0;
80
 
  }
81
 
 
82
 
 
83
 
  static String propertiesToString(int properties) {
84
 
    StringBuilder sb = new StringBuilder();
85
 
    boolean first=true;
86
 
    while (properties != 0) {
87
 
      if (!first) sb.append(',');
88
 
      first=false;
89
 
      int bitpos = Integer.numberOfTrailingZeros(properties);
90
 
      sb.append(getPropertyName(1 << bitpos));
91
 
      properties &= ~(1<<bitpos);  // clear that bit position
92
 
    }
93
 
    return sb.toString();
94
 
  }
95
 
 
96
 
  static boolean on(int bitfield, int props) {
97
 
    return (bitfield & props) != 0;
98
 
  }
99
 
 
100
 
  static boolean off(int bitfield, int props) {
101
 
    return (bitfield & props) == 0;
102
 
  }
103
 
 
104
 
  static int parseProperties(Map<String,String> properties, boolean which) {
105
 
    int props = 0;
106
 
    for (Map.Entry<String, String> entry : properties.entrySet()) {
107
 
      String val = entry.getValue();
108
 
      if(val == null) continue;
109
 
      if (Boolean.parseBoolean(val) == which) {
110
 
        props |= propertyNameToInt(entry.getKey());
111
 
      }
112
 
    }
113
 
    return props;
114
 
  }
115
 
 
116
 
}