FieldInfospublic final class FieldInfos extends Object Access to the Field Info file that describes document fields and whether or
not they are indexed. Each segment has a separate Field Info file. Objects
of this class are thread-safe for multiple readers, but only one thread can
be adding documents at a time, with no other reader or writer threads
accessing this object. |
Fields Summary |
---|
static final byte | IS_INDEXED | static final byte | STORE_TERMVECTOR | static final byte | STORE_POSITIONS_WITH_TERMVECTOR | static final byte | STORE_OFFSET_WITH_TERMVECTOR | static final byte | OMIT_NORMS | private ArrayList | byNumber | private HashMap | byName |
Constructors Summary |
---|
FieldInfos()
| FieldInfos(Directory d, String name)Construct a FieldInfos object using the directory and the name of the file
IndexInput
IndexInput input = d.openInput(name);
try {
read(input);
} finally {
input.close();
}
|
Methods Summary |
---|
public void | add(org.apache.lucene.document.Document doc)Adds field info for a Document.
Enumeration fields = doc.fields();
while (fields.hasMoreElements()) {
Field field = (Field) fields.nextElement();
add(field.name(), field.isIndexed(), field.isTermVectorStored(), field.isStorePositionWithTermVector(),
field.isStoreOffsetWithTermVector(), field.getOmitNorms());
}
| public void | add(java.util.Collection names, boolean isIndexed)Assumes the fields are not storing term vectors.
Iterator i = names.iterator();
while (i.hasNext()) {
add((String)i.next(), isIndexed);
}
| public void | add(java.lang.String name, boolean isIndexed)Calls 5 parameter add with false for all TermVector parameters.
add(name, isIndexed, false, false, false, false);
| public void | add(java.lang.String name, boolean isIndexed, boolean storeTermVector)Calls 5 parameter add with false for term vector positions and offsets.
add(name, isIndexed, storeTermVector, false, false, false);
| public void | add(java.lang.String name, boolean isIndexed, boolean storeTermVector, boolean storePositionWithTermVector, boolean storeOffsetWithTermVector)If the field is not yet known, adds it. If it is known, checks to make
sure that the isIndexed flag is the same as was given previously for this
field. If not - marks it as being indexed. Same goes for the TermVector
parameters.
add(name, isIndexed, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, false);
| public void | add(java.lang.String name, boolean isIndexed, boolean storeTermVector, boolean storePositionWithTermVector, boolean storeOffsetWithTermVector, boolean omitNorms)If the field is not yet known, adds it. If it is known, checks to make
sure that the isIndexed flag is the same as was given previously for this
field. If not - marks it as being indexed. Same goes for the TermVector
parameters.
FieldInfo fi = fieldInfo(name);
if (fi == null) {
addInternal(name, isIndexed, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms);
} else {
if (fi.isIndexed != isIndexed) {
fi.isIndexed = true; // once indexed, always index
}
if (fi.storeTermVector != storeTermVector) {
fi.storeTermVector = true; // once vector, always vector
}
if (fi.storePositionWithTermVector != storePositionWithTermVector) {
fi.storePositionWithTermVector = true; // once vector, always vector
}
if (fi.storeOffsetWithTermVector != storeOffsetWithTermVector) {
fi.storeOffsetWithTermVector = true; // once vector, always vector
}
if (fi.omitNorms != omitNorms) {
fi.omitNorms = false; // once norms are stored, always store
}
}
| public void | addIndexed(java.util.Collection names, boolean storeTermVectors, boolean storePositionWithTermVector, boolean storeOffsetWithTermVector)Add fields that are indexed. Whether they have termvectors has to be specified.
Iterator i = names.iterator();
while (i.hasNext()) {
add((String)i.next(), true, storeTermVectors, storePositionWithTermVector, storeOffsetWithTermVector);
}
| private void | addInternal(java.lang.String name, boolean isIndexed, boolean storeTermVector, boolean storePositionWithTermVector, boolean storeOffsetWithTermVector, boolean omitNorms)
FieldInfo fi =
new FieldInfo(name, isIndexed, byNumber.size(), storeTermVector, storePositionWithTermVector,
storeOffsetWithTermVector, omitNorms);
byNumber.add(fi);
byName.put(name, fi);
| public org.apache.lucene.index.FieldInfo | fieldInfo(java.lang.String fieldName)
return (FieldInfo) byName.get(fieldName);
| public org.apache.lucene.index.FieldInfo | fieldInfo(int fieldNumber)Return the fieldinfo object referenced by the fieldNumber.
try {
return (FieldInfo) byNumber.get(fieldNumber);
}
catch (IndexOutOfBoundsException ioobe) {
return null;
}
| public java.lang.String | fieldName(int fieldNumber)Return the fieldName identified by its number.
try {
return fieldInfo(fieldNumber).name;
}
catch (NullPointerException npe) {
return "";
}
| public int | fieldNumber(java.lang.String fieldName)
try {
FieldInfo fi = fieldInfo(fieldName);
if (fi != null)
return fi.number;
}
catch (IndexOutOfBoundsException ioobe) {
return -1;
}
return -1;
| public boolean | hasVectors()
boolean hasVectors = false;
for (int i = 0; i < size(); i++) {
if (fieldInfo(i).storeTermVector) {
hasVectors = true;
break;
}
}
return hasVectors;
| private void | read(org.apache.lucene.store.IndexInput input)
int size = input.readVInt();//read in the size
for (int i = 0; i < size; i++) {
String name = input.readString().intern();
byte bits = input.readByte();
boolean isIndexed = (bits & IS_INDEXED) != 0;
boolean storeTermVector = (bits & STORE_TERMVECTOR) != 0;
boolean storePositionsWithTermVector = (bits & STORE_POSITIONS_WITH_TERMVECTOR) != 0;
boolean storeOffsetWithTermVector = (bits & STORE_OFFSET_WITH_TERMVECTOR) != 0;
boolean omitNorms = (bits & OMIT_NORMS) != 0;
addInternal(name, isIndexed, storeTermVector, storePositionsWithTermVector, storeOffsetWithTermVector, omitNorms);
}
| public int | size()
return byNumber.size();
| public void | write(org.apache.lucene.store.Directory d, java.lang.String name)
IndexOutput output = d.createOutput(name);
try {
write(output);
} finally {
output.close();
}
| public void | write(org.apache.lucene.store.IndexOutput output)
output.writeVInt(size());
for (int i = 0; i < size(); i++) {
FieldInfo fi = fieldInfo(i);
byte bits = 0x0;
if (fi.isIndexed) bits |= IS_INDEXED;
if (fi.storeTermVector) bits |= STORE_TERMVECTOR;
if (fi.storePositionWithTermVector) bits |= STORE_POSITIONS_WITH_TERMVECTOR;
if (fi.storeOffsetWithTermVector) bits |= STORE_OFFSET_WITH_TERMVECTOR;
if (fi.omitNorms) bits |= OMIT_NORMS;
output.writeString(fi.name);
output.writeByte(bits);
}
|
|