public abstract class FieldType extends FieldProperties
Modifier and Type | Class and Description |
---|---|
protected class |
FieldType.DefaultAnalyzer
Default analyzer for types that only produce 1 verbatim token...
|
static class |
FieldType.MultiValueSelector
An enumeration representing various options that may exist for selecting a single value from a
multivalued field.
|
Modifier and Type | Field and Description |
---|---|
static String |
ANALYZER |
protected Map<String,String> |
args
additional arguments specified in the field type declaration
|
protected static String |
AUTO_GENERATE_PHRASE_QUERIES |
static String |
CHAR_FILTER |
static String |
CHAR_FILTERS |
static String |
CLASS_NAME |
protected String |
docValuesFormat
The docvalues format used for this field type
|
protected static String |
ENABLE_GRAPH_QUERIES |
protected int |
falseProperties
properties explicitly set to false
|
static String |
FILTER |
static String |
FILTERS |
static String |
INDEX |
static String |
INDEX_ANALYZER |
static String |
MULTI_TERM |
static String |
MULTI_TERM_ANALYZER |
static String |
POLY_FIELD_SEPARATOR
The default poly field separator.
|
protected String |
postingsFormat
The postings format used for this field type
|
protected int |
properties |
static String |
QUERY |
static String |
QUERY_ANALYZER |
protected Similarity |
similarity |
static String |
SIMILARITY |
protected SimilarityFactory |
similarityFactory |
protected static String |
SYNONYM_QUERY_STYLE |
static String |
TOKENIZER |
protected int |
trueProperties
properties explicitly set to true
|
static String |
TYPE |
static String |
TYPE_NAME |
protected String |
typeName
The name of the type (not the name of the field)
|
BINARY, DOC_VALUES, INDEXED, LARGE_FIELD, MULTIVALUED, OMIT_NORMS, OMIT_POSITIONS, OMIT_TF_POSITIONS, REQUIRED, SORT_MISSING_FIRST, SORT_MISSING_LAST, STORE_OFFSETS, STORE_TERMOFFSETS, STORE_TERMPAYLOADS, STORE_TERMPOSITIONS, STORE_TERMVECTORS, STORED, TOKENIZED, UNINVERTIBLE, USE_DOCVALUES_AS_STORED
Constructor and Description |
---|
FieldType() |
Modifier and Type | Method and Description |
---|---|
void |
checkSchemaField(SchemaField field)
Check's
SchemaField instances constructed
using this field type to ensure that they are valid. |
protected void |
checkSupportsDocValues()
Called by
checkSchemaField(SchemaField) if the field has docValues. |
IndexableField |
createField(SchemaField field,
Object value)
Used for adding a document when a field needs to be created from a
type and a string.
|
protected IndexableField |
createField(String name,
String val,
IndexableFieldType type)
Create the field from native Lucene parts.
|
List<IndexableField> |
createFields(SchemaField field,
Object value)
Given a
SchemaField , create one or more IndexableField instances |
protected static SimpleOrderedMap<Object> |
getAnalyzerProperties(Analyzer analyzer)
Returns a description of the given analyzer, by either reporting the Analyzer class
name (and optionally luceneMatchVersion) if it's not a TokenizerChain, or if it is,
querying each analysis factory for its name and args.
|
String |
getClassArg() |
FieldType.MultiValueSelector |
getDefaultMultiValueSelectorForSort(SchemaField field,
boolean reverse)
Method for indicating which
FieldType.MultiValueSelector (if any) should be used when
sorting on a multivalued field of this type for the specified direction (asc/desc). |
String |
getDocValuesFormat() |
Query |
getExistenceQuery(QParser parser,
SchemaField field)
Returns a Query instance for doing existence searches for a field.
|
Query |
getFieldQuery(QParser parser,
SchemaField field,
String externalVal)
Returns a Query instance for doing searches against a field.
|
Analyzer |
getIndexAnalyzer()
Returns the Analyzer to be used when indexing fields of this type.
|
SimpleOrderedMap<Object> |
getNamedPropertyValues(boolean showDefaults)
Get a map of property name -> value for this field type.
|
protected Map<String,String> |
getNonFieldPropertyArgs()
Returns args to this field type that aren't standard field properties
|
NumberType |
getNumberType()
Return the numeric type of this field, or null if this field is not a
numeric field.
|
protected SortField |
getNumericSort(SchemaField field,
NumberType type,
boolean reverse)
Utility usable by subclasses when they want to get basic Numeric sorting
using common checks.
|
String |
getPostingsFormat() |
Query |
getPrefixQuery(QParser parser,
SchemaField sf,
String termStr)
Returns a Query instance for doing prefix searches on this field type.
|
Analyzer |
getQueryAnalyzer()
Returns the Analyzer to be used when searching fields of this type.
|
Query |
getRangeQuery(QParser parser,
SchemaField field,
String part1,
String part2,
boolean minInclusive,
boolean maxInclusive)
Returns a Query instance for doing range searches on this field type.
|
MultiTermQuery.RewriteMethod |
getRewriteMethod(QParser parser,
SchemaField field)
Expert: Returns the rewrite method for multiterm queries such as wildcards.
|
Query |
getSetQuery(QParser parser,
SchemaField field,
Collection<String> externalVals) |
Similarity |
getSimilarity()
Gets the Similarity used when scoring fields of this type
|
SimilarityFactory |
getSimilarityFactory()
Gets the factory for the Similarity used when scoring fields of this type
|
ValueSource |
getSingleValueSource(FieldType.MultiValueSelector choice,
SchemaField field,
QParser parser)
Method for dynamically building a ValueSource based on a single value of a multivalued field.
|
protected static SortField |
getSortedNumericSortField(SchemaField field,
SortField.Type sortType,
SortedNumericSelector.Type selector,
boolean reverse,
Object missingLow,
Object missingHigh)
Same as
getSortField(org.apache.solr.schema.SchemaField, boolean) but using SortedNumericSortField . |
protected static SortField |
getSortedSetSortField(SchemaField field,
SortedSetSelector.Type selector,
boolean reverse,
Object missingLow,
Object missingHigh)
Same as
getSortField(org.apache.solr.schema.SchemaField, boolean) but using SortedSetSortField |
abstract SortField |
getSortField(SchemaField field,
boolean top)
Returns the SortField instance that should be used to sort fields
of this type.
|
protected static SortField |
getSortField(SchemaField field,
SortField.Type sortType,
boolean reverse,
Object missingLow,
Object missingHigh)
A Helper utility method for use by subclasses.
|
protected Query |
getSpecializedExistenceQuery(QParser parser,
SchemaField field)
Returns a Query instance for doing existence searches for a field without certain options, such as docValues or norms.
|
protected Query |
getSpecializedRangeQuery(QParser parser,
SchemaField field,
String part1,
String part2,
boolean minInclusive,
boolean maxInclusive)
Returns a Query instance for doing range searches on this field type.
|
protected SortField |
getStringSort(SchemaField field,
boolean reverse)
Utility usable by subclasses when they want to get basic String sorting
using common checks.
|
String |
getTypeName()
The Name of this FieldType as specified in the schema file
|
abstract UninvertingReader.Type |
getUninversionType(SchemaField sf)
If DocValues is not enabled for a field, but it's indexed, docvalues can be constructed
on the fly (uninverted, aka fieldcache) on the first request to sort, facet, etc.
|
ValueSource |
getValueSource(SchemaField field,
QParser parser)
called to get the default value source (normally, from the
Lucene FieldCache.)
|
protected boolean |
hasProperty(int p)
Check if a property is set
|
CharsRef |
indexedToReadable(BytesRef input,
CharsRefBuilder output)
Given an indexed term, append the human readable representation
|
String |
indexedToReadable(String indexedForm)
Given an indexed term, return the human readable representation
|
protected void |
init(IndexSchema schema,
Map<String,String> args)
subclasses should initialize themselves with the args provided
and remove valid arguments.
|
boolean |
isExplicitAnalyzer() |
boolean |
isExplicitQueryAnalyzer() |
boolean |
isMultiValued()
Returns true if fields can have multiple values
|
boolean |
isPointField() |
boolean |
isPolyField()
A "polyField" is a FieldType that can produce more than one IndexableField instance for a single value, via the
createFields(org.apache.solr.schema.SchemaField, Object) method. |
boolean |
isTokenized()
Returns true if fields of this type should be tokenized
|
boolean |
isUtf8Field() |
protected static Object |
marshalBase64SortValue(Object value)
Marshals a binary field value.
|
Object |
marshalSortValue(Object value)
Convert a value used by the FieldComparator for this FieldType's SortField
into a marshalable value for distributed sorting.
|
protected static Object |
marshalStringSortValue(Object value)
Marshals a string-based field value.
|
boolean |
multiValuedFieldCache()
Returns true if a single field value of this type has multiple logical values
for the purposes of faceting, sorting, etc.
|
void |
readableToIndexed(CharSequence val,
BytesRefBuilder result)
Given the readable value, return the term value that will match it.
|
String |
readableToIndexed(String val)
Given the readable value, return the term value that will match it.
|
protected void |
restrictProps(int props)
:TODO: document this method
|
protected void |
setArgs(IndexSchema schema,
Map<String,String> args)
Initializes the field type.
|
void |
setIndexAnalyzer(Analyzer analyzer)
Sets the Analyzer to be used when indexing fields of this type.
|
void |
setIsExplicitAnalyzer(boolean explicitAnalyzer) |
void |
setIsExplicitQueryAnalyzer(boolean isExplicitQueryAnalyzer) |
void |
setQueryAnalyzer(Analyzer analyzer)
Sets the Analyzer to be used when querying fields of this type.
|
void |
setSimilarity(SimilarityFactory similarityFactory)
Sets the Similarity used when scoring fields of this type
|
String |
storedToIndexed(IndexableField f)
Given the stored field, return the indexed form
|
String |
storedToReadable(IndexableField f)
Given the stored field, return the human readable representation
|
protected boolean |
supportsAnalyzers()
Returns true if this type supports index and query analyzers, false otherwise.
|
String |
toExternal(IndexableField f)
Convert the stored-field format to an external (string, human readable)
value
|
String |
toInternal(String val)
Convert an external value (from XML update command or from query string)
into the internal format for both storing and indexing (which can be modified by any analyzers).
|
Object |
toNativeType(Object val)
Converts any Object to a java Object native to this field type
|
Object |
toObject(IndexableField f)
Convert the stored-field format to an external object.
|
Object |
toObject(SchemaField sf,
BytesRef term) |
String |
toString() |
protected boolean |
treatUnboundedRangeAsExistence(SchemaField field)
Returns whether an unbounded range query should be treated the same as an existence query for the given field type.
|
protected static Object |
unmarshalBase64SortValue(Object value)
Unmarshals a binary field value.
|
Object |
unmarshalSortValue(Object value)
Convert a value marshaled via
marshalSortValue(java.lang.Object) back
into a value usable by the FieldComparator for this FieldType's SortField |
protected static Object |
unmarshalStringSortValue(Object value)
Unmarshals a string-based field value.
|
boolean |
useDocValuesAsStored()
Returns true if the fields' docValues should be used for obtaining stored value
|
boolean |
write(IteratorWriter.ItemWriter itemWriter) |
abstract void |
write(TextResponseWriter writer,
String name,
IndexableField f)
calls back to TextResponseWriter to write the field value
|
public static final String POLY_FIELD_SEPARATOR
protected String typeName
protected int trueProperties
protected int falseProperties
protected int properties
protected SimilarityFactory similarityFactory
protected Similarity similarity
protected String postingsFormat
protected String docValuesFormat
public static final String TYPE
public static final String TYPE_NAME
public static final String CLASS_NAME
public static final String ANALYZER
public static final String INDEX
public static final String INDEX_ANALYZER
public static final String QUERY
public static final String QUERY_ANALYZER
public static final String MULTI_TERM
public static final String MULTI_TERM_ANALYZER
public static final String SIMILARITY
public static final String CHAR_FILTER
public static final String CHAR_FILTERS
public static final String TOKENIZER
public static final String FILTER
public static final String FILTERS
protected static final String AUTO_GENERATE_PHRASE_QUERIES
protected static final String ENABLE_GRAPH_QUERIES
protected static final String SYNONYM_QUERY_STYLE
public boolean isTokenized()
public boolean isMultiValued()
protected boolean hasProperty(int p)
public boolean isPolyField()
createFields(org.apache.solr.schema.SchemaField, Object)
method. This is useful
when hiding the implementation details of a field from the Solr end user. For instance, a spatial point may be represented by multiple different fields.createFields(org.apache.solr.schema.SchemaField, Object)
method may return more than one fieldpublic boolean isPointField()
public boolean isUtf8Field()
public boolean useDocValuesAsStored()
public boolean multiValuedFieldCache()
protected void init(IndexSchema schema, Map<String,String> args)
public boolean write(IteratorWriter.ItemWriter itemWriter)
protected void setArgs(IndexSchema schema, Map<String,String> args)
init(IndexSchema, Map)
which is called by this method.protected void restrictProps(int props)
public String getTypeName()
public IndexableField createField(SchemaField field, Object value)
By default, the indexed value is the same as the stored value (taken from toInternal()). Having a different representation for external, internal, and indexed would present quite a few problems given the current Lucene architecture. An analyzer for adding docs would need to translate internal->indexed while an analyzer for querying would need to translate external->indexed.
The only other alternative to having internal==indexed would be to have internal==external. In this case, toInternal should convert to the indexed representation, toExternal() should do nothing, and createField() should *not* call toInternal, but use the external value and set tokenized=true to get Lucene to convert to the internal(indexed) form.
:TODO: clean up and clarify this explanation.toInternal(java.lang.String)
protected IndexableField createField(String name, String val, IndexableFieldType type)
name
- The name of the fieldval
- The _internal_ value to indextype
- FieldType
IndexableField
.public List<IndexableField> createFields(SchemaField field, Object value)
SchemaField
, create one or more IndexableField
instancesfield
- the SchemaField
value
- The value to add to the fieldIndexableField
createField(SchemaField, Object)
,
isPolyField()
public String toInternal(String val)
public String toExternal(IndexableField f)
toInternal(java.lang.String)
public Object toObject(IndexableField f)
toInternal(java.lang.String)
public Object toObject(SchemaField sf, BytesRef term)
public String indexedToReadable(String indexedForm)
public CharsRef indexedToReadable(BytesRef input, CharsRefBuilder output)
public String storedToReadable(IndexableField f)
public String storedToIndexed(IndexableField f)
public String readableToIndexed(String val)
public void readableToIndexed(CharSequence val, BytesRefBuilder result)
result
parameter and write from offset 0public void setIsExplicitQueryAnalyzer(boolean isExplicitQueryAnalyzer)
public boolean isExplicitQueryAnalyzer()
public void setIsExplicitAnalyzer(boolean explicitAnalyzer)
public boolean isExplicitAnalyzer()
public String getClassArg()
getClass().getName()
.public Query getPrefixQuery(QParser parser, SchemaField sf, String termStr)
Sub-classes should override this method to provide their own range query implementation.
parser
- the QParser
calling the methodsf
- the schema fieldtermStr
- the term string for prefix query, if blank then this query should match all docs with this fieldpublic abstract UninvertingReader.Type getUninversionType(SchemaField sf)
If DocValues is not enabled for a field, but it's indexed, docvalues can be constructed on the fly (uninverted, aka fieldcache) on the first request to sort, facet, etc. This specifies the structure to use.
This method will not be used if the field is (effectively) uninvertible="false"
sf
- field instancenull
(to disallow uninversion for the field)SchemaField.isUninvertible()
public Analyzer getIndexAnalyzer()
This method may be called many times, at any time.
getQueryAnalyzer()
public Analyzer getQueryAnalyzer()
This method may be called many times, at any time.
getIndexAnalyzer()
protected boolean supportsAnalyzers()
public final void setIndexAnalyzer(Analyzer analyzer)
Subclasses should override supportsAnalyzers()
to
enable this function.
public final void setQueryAnalyzer(Analyzer analyzer)
Subclasses should override supportsAnalyzers()
to
enable this function.
public Similarity getSimilarity()
The default implementation returns null, which means this type has no custom similarity associated with it.
public SimilarityFactory getSimilarityFactory()
The default implementation returns null, which means this type has no custom similarity factory associated with it.
public NumberType getNumberType()
public void setSimilarity(SimilarityFactory similarityFactory)
public String getPostingsFormat()
public final String getDocValuesFormat()
public abstract void write(TextResponseWriter writer, String name, IndexableField f) throws IOException
Sub-classes should prefer using toExternal(IndexableField)
or toObject(IndexableField)
to get the writeable external value of f
instead of directly using f.stringValue()
or f.binaryValue()
IOException
public abstract SortField getSortField(SchemaField field, boolean top)
protected static SortField getSortField(SchemaField field, SortField.Type sortType, boolean reverse, Object missingLow, Object missingHigh)
A Helper utility method for use by subclasses.
This method deals with:
SchemaField.checkSortability()
SortField
on field
with the specified
reverse
& sortType
SortField.setMissingValue(java.lang.Object)
to missingLow
or missingHigh
as appropriate based on the value of reverse
and the
sortMissingFirst
& sortMissingLast
properties of the
field
field
- The SchemaField to sort on. May use sortMissingFirst
or sortMissingLast
or neither.sortType
- The sort Type of the underlying values in the field
reverse
- True if natural order of the sortType
should be reversedmissingLow
- The missingValue
to be used if the other params indicate that docs w/o values should sort as "low" as possible.missingHigh
- The missingValue
to be used if the other params indicate that docs w/o values should sort as "high" as possible.getSortedSetSortField(org.apache.solr.schema.SchemaField, org.apache.lucene.search.SortedSetSelector.Type, boolean, java.lang.Object, java.lang.Object)
protected static SortField getSortedSetSortField(SchemaField field, SortedSetSelector.Type selector, boolean reverse, Object missingLow, Object missingHigh)
getSortField(org.apache.solr.schema.SchemaField, boolean)
but using SortedSetSortField
protected static SortField getSortedNumericSortField(SchemaField field, SortField.Type sortType, SortedNumericSelector.Type selector, boolean reverse, Object missingLow, Object missingHigh)
getSortField(org.apache.solr.schema.SchemaField, boolean)
but using SortedNumericSortField
.protected SortField getStringSort(SchemaField field, boolean reverse)
protected SortField getNumericSort(SchemaField field, NumberType type, boolean reverse)
SchemaField.checkSortability()
,
getSortedNumericSortField(org.apache.solr.schema.SchemaField, org.apache.lucene.search.SortField.Type, org.apache.lucene.search.SortedNumericSelector.Type, boolean, java.lang.Object, java.lang.Object)
,
getSortField(org.apache.solr.schema.SchemaField, boolean)
public ValueSource getValueSource(SchemaField field, QParser parser)
public ValueSource getSingleValueSource(FieldType.MultiValueSelector choice, SchemaField field, QParser parser)
SchemaField
that is in fact not-multivalued, in which case it delegates to
getValueSource(org.apache.solr.schema.SchemaField, org.apache.solr.search.QParser)
FieldType.MultiValueSelector
public FieldType.MultiValueSelector getDefaultMultiValueSelectorForSort(SchemaField field, boolean reverse)
FieldType.MultiValueSelector
(if any) should be used when
sorting on a multivalued field of this type for the specified direction (asc/desc).
The default implementation returns null
(for all inputs).field
- The SchemaField (of this type) in questionreverse
- false if this is an ascending sort, true if this is a descending sort.FieldType.MultiValueSelector
public Query getRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive)
SolrQueryParser
currently passes part1
and part2
as null if they are '*' respectively. minInclusive
and maxInclusive
are both true
currently by SolrQueryParser but that may change in the future. Also, other QueryParser implementations may have
different semantics.
By default range queries with '*'s or nulls on either side are treated as existence queries and are created with getExistenceQuery(org.apache.solr.search.QParser, org.apache.solr.schema.SchemaField)
.
If unbounded range queries should not be treated as existence queries for a certain fieldType, then treatUnboundedRangeAsExistence(org.apache.solr.schema.SchemaField)
should be overriden.
Sub-classes should override the getSpecializedRangeQuery(org.apache.solr.search.QParser, org.apache.solr.schema.SchemaField, java.lang.String, java.lang.String, boolean, boolean)
method to provide their own range query implementation.
parser
- the QParser
calling the methodfield
- the schema fieldpart1
- the lower boundary of the range, nulls are allowed.part2
- the upper boundary of the range, nulls are alloweminInclusive
- whether the minimum of the range is inclusive or notmaxInclusive
- whether the maximum of the range is inclusive or notprotected boolean treatUnboundedRangeAsExistence(SchemaField field)
field
- the schema fieldprotected Query getSpecializedRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive)
SolrQueryParser
currently passes part1
and part2
as null if they are '*' respectively. minInclusive
and maxInclusive
are both true
currently by SolrQueryParser but that may change in the future. Also, other QueryParser implementations may have
different semantics.
Sub-classes should override this method to provide their own range query implementation. They should strive to
handle nulls in part1
and/or part2
as well as unequal minInclusive
and maxInclusive
parameters gracefully.
This method does not, and should not, check for or handle existence queries, please look at getRangeQuery(org.apache.solr.search.QParser, org.apache.solr.schema.SchemaField, java.lang.String, java.lang.String, boolean, boolean)
for that logic.
parser
- the QParser
calling the methodfield
- the schema fieldpart1
- the lower boundary of the range, nulls are allowed.part2
- the upper boundary of the range, nulls are allowedminInclusive
- whether the minimum of the range is inclusive or notmaxInclusive
- whether the maximum of the range is inclusive or notpublic Query getExistenceQuery(QParser parser, SchemaField field)
getSpecializedExistenceQuery(org.apache.solr.search.QParser, org.apache.solr.schema.SchemaField)
, which defaults to an unbounded rangeQuery.
This method should only be overriden whenever a fieldType does not support DocValuesFieldExistsQuery
or NormsFieldExistsQuery
.
If a fieldType does not support an unbounded rangeQuery as an existenceQuery (such as double
or float
fields), getSpecializedExistenceQuery(org.apache.solr.search.QParser, org.apache.solr.schema.SchemaField)
should be overriden.
parser
- The QParser
calling the methodfield
- The SchemaField
of the field to searchQuery
instance.protected Query getSpecializedExistenceQuery(QParser parser, SchemaField field)
This method can be overriden to implement specialized existence logic for fieldTypes. The default query returned is an unbounded range query.
parser
- The QParser
calling the methodfield
- The SchemaField
of the field to searchQuery
instance.public Query getFieldQuery(QParser parser, SchemaField field, String externalVal)
parser
- The QParser
calling the methodfield
- The SchemaField
of the field to searchexternalVal
- The String representation of the value to searchQuery
instance. This implementation returns a TermQuery
but overriding queries may notpublic Query getSetQuery(QParser parser, SchemaField field, Collection<String> externalVals)
public MultiTermQuery.RewriteMethod getRewriteMethod(QParser parser, SchemaField field)
parser
- The QParser
calling the methodfield
- The SchemaField
of the field to searchpublic void checkSchemaField(SchemaField field)
SchemaField
instances constructed
using this field type to ensure that they are valid.
This method is called by the SchemaField
constructor to
check that its initialization does not violate any fundamental
requirements of the FieldType
.
Subclasses may choose to throw a SolrException
if invariants are violated by the SchemaField.
protected void checkSupportsDocValues()
checkSchemaField(SchemaField)
if the field has docValues. By default none do.public SimpleOrderedMap<Object> getNamedPropertyValues(boolean showDefaults)
showDefaults
- if true, include default properties.protected Map<String,String> getNonFieldPropertyArgs()
protected static SimpleOrderedMap<Object> getAnalyzerProperties(Analyzer analyzer)
public Object toNativeType(Object val)
public Object marshalSortValue(Object value)
public Object unmarshalSortValue(Object value)
marshalSortValue(java.lang.Object)
back
into a value usable by the FieldComparator for this FieldType's SortFieldprotected static Object marshalStringSortValue(Object value)
protected static Object unmarshalStringSortValue(Object value)
protected static Object marshalBase64SortValue(Object value)
Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.