Class CurrencyFieldType
- All Implemented Interfaces:
org.apache.lucene.util.ResourceLoaderAware,SchemaAware
See https://solr.apache.org/guide/solr/latest/indexing-guide/currencies-exchange-rates.html
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.solr.schema.FieldType
FieldType.DefaultAnalyzer, FieldType.MultiValueSelector -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected static final Stringprotected Stringprotected Stringprotected FieldTypeprotected FieldTypeprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected IndexSchemaFields inherited from class org.apache.solr.schema.FieldType
ANALYZER, args, AUTO_GENERATE_PHRASE_QUERIES, CHAR_FILTER, CHAR_FILTERS, CLASS_NAME, docValuesFormat, ENABLE_GRAPH_QUERIES, falseProperties, FILTER, FILTERS, INDEX, INDEX_ANALYZER, MULTI_TERM, MULTI_TERM_ANALYZER, POLY_FIELD_SEPARATOR, postingsFormat, properties, QUERY, QUERY_ANALYZER, similarity, SIMILARITY, similarityFactory, SYNONYM_QUERY_STYLE, TOKENIZER, trueProperties, TYPE, TYPE_NAME, typeNameFields inherited from class org.apache.solr.schema.FieldProperties
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckSchemaField(SchemaField field) Check'sSchemaFieldinstances constructed using this field type to ensure that they are valid.List<org.apache.lucene.index.IndexableField> createFields(SchemaField field, Object externalVal) Given aSchemaField, create one or moreIndexableFieldinstancesorg.apache.lucene.queries.function.ValueSourcegetConvertedValueSource(String targetCurrencyCode, org.apache.solr.schema.CurrencyFieldType.RawCurrencyValueSource source) Returns a ValueSource over this field in which the numeric value for each document represents the value from the underlyingRawCurrencyValueSourceas converted to the specified target Currency.static CurrencygetCurrency(String code) A wrapper aroundCurrency.getInstancethat returns null instead of throwingIllegalArgumentExceptionif the specified Currency does not exist in this JVM.The identifier code for the default currency of this field typeorg.apache.lucene.search.QuerygetExistenceQuery(QParser parser, SchemaField field) Override the default existenceQuery implementation to run an existence query on the underlying amountField instead.org.apache.lucene.search.QuerygetFieldQuery(QParser parser, SchemaField field, String externalVal) Returns a Query instance for doing searches against a field.org.apache.lucene.search.SortFieldgetSortField(SchemaField field, boolean reverse) Returns the SortField instance that should be used to sort fields of this type.protected org.apache.lucene.search.QuerygetSpecializedRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) Returns a Query instance for doing range searches on this field type.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.org.apache.solr.schema.CurrencyFieldType.RawCurrencyValueSourcegetValueSource(SchemaField field, QParser parser) Returns a ValueSource over this field in which the numeric value for each document represents the indexed value as converted to the default currency for the field, normalized to its most granular form based on the default fractional digits.voidinform(org.apache.lucene.util.ResourceLoader resourceLoader) Load the currency config when resource loader initialized.voidinform(IndexSchema schema) When index schema is informed, get field types for the configured dynamic sub-fieldsprotected voidinit(IndexSchema schema, Map<String, String> args) subclasses should initialize themselves with the args provided and remove valid arguments.booleanA "polyField" is a FieldType that can produce more than one IndexableField instance for a single value, via theFieldType.createFields(org.apache.solr.schema.SchemaField, Object)method.voidwrite(TextResponseWriter writer, String name, org.apache.lucene.index.IndexableField field) calls back to TextResponseWriter to write the field valueMethods inherited from class org.apache.solr.schema.FieldType
checkSupportsDocValues, createField, createField, enableDocValuesByDefault, getAnalyzerProperties, getClassArg, getDefaultMultiValueSelectorForSort, getDocValuesFormat, getFieldTermQuery, getIndexAnalyzer, getNamedPropertyValues, getNonFieldPropertyArgs, getNumberType, getNumericSort, getPostingsFormat, getPrefixQuery, getQueryAnalyzer, getRangeQuery, getRewriteMethod, getSetQuery, getSimilarity, getSimilarityFactory, getSingleValueSource, getSortedNumericSortField, getSortedSetSortField, getSortField, getSpecializedExistenceQuery, getStringSort, getTypeName, hasProperty, indexedToReadable, indexedToReadable, isExplicitAnalyzer, isExplicitQueryAnalyzer, isMultiValued, isPointField, isTokenized, isUtf8Field, marshalBase64SortValue, marshalSortValue, marshalStringSortValue, multiValuedFieldCache, readableToIndexed, readableToIndexed, restrictProps, setArgs, setIndexAnalyzer, setIsExplicitAnalyzer, setIsExplicitQueryAnalyzer, setQueryAnalyzer, setSimilarity, storedToIndexed, storedToReadable, supportsAnalyzers, toExternal, toInternal, toNativeType, toObject, toObject, toString, treatUnboundedRangeAsExistence, unmarshalBase64SortValue, unmarshalSortValue, unmarshalStringSortValue, useDocValuesAsStored, write
-
Field Details
-
PARAM_DEFAULT_CURRENCY
- See Also:
-
DEFAULT_DEFAULT_CURRENCY
- See Also:
-
PARAM_RATE_PROVIDER_CLASS
- See Also:
-
DEFAULT_RATE_PROVIDER_CLASS
- See Also:
-
PARAM_FIELD_SUFFIX_AMOUNT_RAW
- See Also:
-
PARAM_FIELD_SUFFIX_CURRENCY
- See Also:
-
schema
-
fieldTypeCurrency
-
fieldTypeAmountRaw
-
fieldSuffixAmountRaw
-
fieldSuffixCurrency
-
-
Constructor Details
-
CurrencyFieldType
public CurrencyFieldType()
-
-
Method Details
-
getCurrency
A wrapper aroundCurrency.getInstancethat returns null instead of throwingIllegalArgumentExceptionif the specified Currency does not exist in this JVM.- See Also:
-
getDefaultCurrency
The identifier code for the default currency of this field type -
init
Description copied from class:FieldTypesubclasses should initialize themselves with the args provided and remove valid arguments. leftover arguments will cause an exception. Common boolean properties have already been handled. -
isPolyField
public boolean isPolyField()Description copied from class:FieldTypeA "polyField" is a FieldType that can produce more than one IndexableField instance for a single value, via theFieldType.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.- Overrides:
isPolyFieldin classFieldType- Returns:
- true if the
FieldType.createFields(org.apache.solr.schema.SchemaField, Object)method may return more than one field
-
checkSchemaField
Description copied from class:FieldTypeCheck'sSchemaFieldinstances constructed using this field type to ensure that they are valid.This method is called by the
SchemaFieldconstructor to check that its initialization does not violate any fundamental requirements of theFieldType. Subclasses may choose to throw aSolrExceptionif invariants are violated by theSchemaField.- Overrides:
checkSchemaFieldin classFieldType- Throws:
org.apache.solr.common.SolrException
-
createFields
public List<org.apache.lucene.index.IndexableField> createFields(SchemaField field, Object externalVal) Description copied from class:FieldTypeGiven aSchemaField, create one or moreIndexableFieldinstances- Overrides:
createFieldsin classFieldType- Parameters:
field- theSchemaFieldexternalVal- The value to add to the field- Returns:
- An array of
IndexableField - See Also:
-
inform
When index schema is informed, get field types for the configured dynamic sub-fieldsInforms the
IndexSchemaprovided by theschemaparameter of an event (e.g., a newFieldTypewas added, etc.- Specified by:
informin interfaceSchemaAware- Parameters:
schema- TheIndexSchemainstance that inform of the update to.
-
inform
public void inform(org.apache.lucene.util.ResourceLoader resourceLoader) Load the currency config when resource loader initialized.- Specified by:
informin interfaceorg.apache.lucene.util.ResourceLoaderAware- Parameters:
resourceLoader- The resource loader.
-
getFieldQuery
public org.apache.lucene.search.Query getFieldQuery(QParser parser, SchemaField field, String externalVal) Description copied from class:FieldTypeReturns a Query instance for doing searches against a field.- Overrides:
getFieldQueryin classFieldType- Parameters:
parser- TheQParsercalling the methodfield- TheSchemaFieldof the field to searchexternalVal- The String representation of the value to search- Returns:
- The
Queryinstance. This implementation returns aTermQuerybut overriding queries may not
-
getValueSource
public org.apache.solr.schema.CurrencyFieldType.RawCurrencyValueSource getValueSource(SchemaField field, QParser parser) Returns a ValueSource over this field in which the numeric value for each document represents the indexed value as converted to the default currency for the field, normalized to its most granular form based on the default fractional digits.For example: If the default Currency specified for a field is
USD, then the values returned by this value source would represent the equivalent number of "cents" (ie: value in dollars * 100) after converting each document's native currency to USD -- because the default fractional digits forUSDis "2". So for a document whose indexed value was currently equivalent to "5.43,USD" using the exchange provider for this field, this ValueSource would return a value of "543"- Overrides:
getValueSourcein classFieldType- See Also:
-
getConvertedValueSource
public org.apache.lucene.queries.function.ValueSource getConvertedValueSource(String targetCurrencyCode, org.apache.solr.schema.CurrencyFieldType.RawCurrencyValueSource source) Returns a ValueSource over this field in which the numeric value for each document represents the value from the underlyingRawCurrencyValueSourceas converted to the specified target Currency.For example: If the
targetCurrencyCodeparam is set toUSD, then the values returned by this value source would represent the equivalent number of dollars after converting each document's raw value toUSD. So for a document whose indexed value was currently equivalent to "5.43,USD" using the exchange provider for this field, this ValueSource would return a value of "5.43"- Parameters:
targetCurrencyCode- The target currency for the resulting value source, if null the defaultCurrency for this field type will be usedsource- the raw ValueSource to wrap- See Also:
-
getExistenceQuery
Override the default existenceQuery implementation to run an existence query on the underlying amountField instead.- Overrides:
getExistenceQueryin classFieldType- Parameters:
parser- TheQParsercalling the methodfield- TheSchemaFieldof the field to search- Returns:
- The
Queryinstance.
-
getSpecializedRangeQuery
protected org.apache.lucene.search.Query getSpecializedRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) Description copied from class:FieldTypeReturns a Query instance for doing range searches on this field type.SolrQueryParsercurrently passespart1andpart2as null if they are '*' respectively.minInclusiveandmaxInclusiveare 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
part1and/orpart2as well as unequalminInclusiveandmaxInclusiveparameters gracefully.This method does not, and should not, check for or handle existence queries, please look at
FieldType.getRangeQuery(org.apache.solr.search.QParser, org.apache.solr.schema.SchemaField, java.lang.String, java.lang.String, boolean, boolean)for that logic.- Overrides:
getSpecializedRangeQueryin classFieldType- Parameters:
parser- theQParsercalling 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 not- Returns:
- a Query instance to perform range search according to given parameters
-
getSortField
Description copied from class:FieldTypeReturns the SortField instance that should be used to sort fields of this type.- Specified by:
getSortFieldin classFieldType- See Also:
-
getUninversionType
Description copied from class:FieldTypeIf 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"- Specified by:
getUninversionTypein classFieldType- Parameters:
sf- field instance- Returns:
- type to uninvert, or
null(to disallow uninversion for the field) - See Also:
-
write
public void write(TextResponseWriter writer, String name, org.apache.lucene.index.IndexableField field) throws IOException Description copied from class:FieldTypecalls back to TextResponseWriter to write the field valueSub-classes should prefer using
FieldType.toExternal(IndexableField)orFieldType.toObject(IndexableField)to get the writeable external value offinstead of directly usingf.stringValue()orf.binaryValue()- Specified by:
writein classFieldType- Throws:
IOException
-
getProvider
-