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
9
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
package org.apache.solr.schema;
21
import java.util.HashMap;
24
* @version $Id: FieldProperties.java 1145645 2011-07-12 16:12:49Z rmuir $
28
public abstract class FieldProperties {
30
// use a bitfield instead of many different boolean variables since
31
// many of the variables are independent or semi-independent.
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;
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;
49
protected final static int REQUIRED = 0x00001000;
50
protected final static int OMIT_POSITIONS = 0x00002000;
52
static final String[] propertyNames = {
53
"indexed", "tokenized", "stored",
54
"binary", "omitNorms", "omitTermFreqAndPositions",
55
"termVectors", "termPositions", "termOffsets",
57
"sortMissingFirst","sortMissingLast","required", "omitPositions"
60
static final Map<String,Integer> propertyMap = new HashMap<String,Integer>();
62
for (String prop : propertyNames) {
63
propertyMap.put(prop, propertyNameToInt(prop));
68
/** Returns the symbolic name for the property. */
69
static String getPropertyName(int property) {
70
return propertyNames[ Integer.numberOfTrailingZeros(property) ];
73
static int propertyNameToInt(String name) {
74
for (int i=0; i<propertyNames.length; i++) {
75
if (propertyNames[i].equals(name)) {
83
static String propertiesToString(int properties) {
84
StringBuilder sb = new StringBuilder();
86
while (properties != 0) {
87
if (!first) sb.append(',');
89
int bitpos = Integer.numberOfTrailingZeros(properties);
90
sb.append(getPropertyName(1 << bitpos));
91
properties &= ~(1<<bitpos); // clear that bit position
96
static boolean on(int bitfield, int props) {
97
return (bitfield & props) != 0;
100
static boolean off(int bitfield, int props) {
101
return (bitfield & props) == 0;
104
static int parseProperties(Map<String,String> properties, boolean which) {
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());