Package org.apache.lucene.document
Class KeywordField
java.lang.Object
org.apache.lucene.document.Field
org.apache.lucene.document.KeywordField
- All Implemented Interfaces:
IndexableField
Field that indexes a per-document String or
BytesRef into an inverted index for fast
filtering, stores values in a columnar fashion using DocValuesType.SORTED_SET doc values
for sorting and faceting, and optionally stores values as stored fields for top-hits retrieval.
This field does not support scoring: queries produce constant scores. If you need more
fine-grained control you can use StringField, SortedDocValuesField or SortedSetDocValuesField, and StoredField.
This field defines static factory methods for creating common query objects:
newExactQuery(java.lang.String, org.apache.lucene.util.BytesRef)for matching a value.newSetQuery(java.lang.String, java.util.Collection<org.apache.lucene.util.BytesRef>)for matching any of the values coming from a set.newSortField(java.lang.String, boolean, org.apache.lucene.search.SortedSetSelector.Type)for matching a value.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.document.Field
Field.Store -
Field Summary
Fields inherited from class org.apache.lucene.document.Field
fieldsData, name, type -
Constructor Summary
ConstructorsConstructorDescriptionKeywordField(String name, String value, Field.Store stored) Creates a new KeywordField from a String value, by indexing its UTF-8 representation.KeywordField(String name, BytesRef value, Field.Store stored) Creates a new KeywordField. -
Method Summary
Modifier and TypeMethodDescriptionNon-null if this field has a binary valueDescribes how this field should be inverted.static QuerynewExactQuery(String field, String value) Create a query for matching an exactStringvalue.static QuerynewExactQuery(String field, BytesRef value) Create a query for matching an exactBytesRefvalue.static QuerynewSetQuery(String field, Collection<BytesRef> values) Create a query for matching any of a set of providedBytesRefvalues.static SortFieldnewSortField(String field, boolean reverse, SortedSetSelector.Type selector) voidsetBytesValue(BytesRef value) Expert: change the value of this field.voidsetStringValue(String value) Expert: change the value of this field.Stored value.Methods inherited from class org.apache.lucene.document.Field
fieldType, getCharSequenceValue, name, numericValue, readerValue, setBytesValue, setByteValue, setDoubleValue, setFloatValue, setIntValue, setLongValue, setReaderValue, setShortValue, setTokenStream, stringValue, tokenStream, tokenStreamValue, toString
-
Constructor Details
-
KeywordField
Creates a new KeywordField.- Parameters:
name- field namevalue- the BytesRef valuestored- whether to store the field- Throws:
IllegalArgumentException- if the field name or value is null.
-
KeywordField
Creates a new KeywordField from a String value, by indexing its UTF-8 representation.- Parameters:
name- field namevalue- the BytesRef valuestored- whether to store the field- Throws:
IllegalArgumentException- if the field name or value is null.
-
-
Method Details
-
binaryValue
Description copied from interface:IndexableFieldNon-null if this field has a binary value- Specified by:
binaryValuein interfaceIndexableField- Overrides:
binaryValuein classField
-
invertableType
Description copied from interface:IndexableFieldDescribes how this field should be inverted. This must return a non-null value if the field indexes terms and postings.- Specified by:
invertableTypein interfaceIndexableField- Overrides:
invertableTypein classField
-
setStringValue
Description copied from class:FieldExpert: change the value of this field. This can be used during indexing to re-use a single Field instance to improve indexing speed by avoiding GC cost of new'ing and reclaiming Field instances. Typically a singleDocumentinstance is re-used as well. This helps most on small documents.Each Field instance should only be used once within a single
Documentinstance. See ImproveIndexingSpeed for details.- Overrides:
setStringValuein classField
-
setBytesValue
Description copied from class:FieldExpert: change the value of this field. SeeField.setStringValue(String).NOTE: the provided BytesRef is not copied so be sure not to change it until you're done with this field.
- Overrides:
setBytesValuein classField
-
storedValue
Description copied from interface:IndexableFieldStored value. This method is called to populate stored fields and must return a non-null value if the field stored.- Specified by:
storedValuein interfaceIndexableField- Overrides:
storedValuein classField
-
newExactQuery
Create a query for matching an exactBytesRefvalue.- Parameters:
field- field name. must not benull.value- exact value- Returns:
- a query matching documents with this exact value
- Throws:
NullPointerException- iffieldis null.
-
newExactQuery
Create a query for matching an exactStringvalue.- Parameters:
field- field name. must not benull.value- exact value- Returns:
- a query matching documents with this exact value
- Throws:
NullPointerException- iffieldis null.
-
newSetQuery
Create a query for matching any of a set of providedBytesRefvalues.- Parameters:
field- field name. must not benull.values- the set of values to match- Returns:
- a query matching documents with this exact value
- Throws:
NullPointerException- iffieldis null.
-
newSortField
public static SortField newSortField(String field, boolean reverse, SortedSetSelector.Type selector) - Parameters:
field- field name. must not benull.reverse- true if natural order should be reversed.selector- custom selector type for choosing the sort value from the set.
-