Class CurrencyFieldType
- java.lang.Object
-
- org.apache.solr.schema.FieldProperties
-
- org.apache.solr.schema.FieldType
-
- org.apache.solr.schema.CurrencyFieldType
-
- All Implemented Interfaces:
org.apache.lucene.util.ResourceLoaderAware
,SchemaAware
- Direct Known Subclasses:
CurrencyField
public class CurrencyFieldType extends FieldType implements SchemaAware, org.apache.lucene.util.ResourceLoaderAware
Field type for support of monetary values.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
Fields Modifier and Type Field Description protected static String
DEFAULT_DEFAULT_CURRENCY
protected static String
DEFAULT_RATE_PROVIDER_CLASS
protected String
fieldSuffixAmountRaw
protected String
fieldSuffixCurrency
protected FieldType
fieldTypeAmountRaw
protected FieldType
fieldTypeCurrency
protected static String
PARAM_DEFAULT_CURRENCY
protected static String
PARAM_FIELD_SUFFIX_AMOUNT_RAW
protected static String
PARAM_FIELD_SUFFIX_CURRENCY
protected static String
PARAM_RATE_PROVIDER_CLASS
protected IndexSchema
schema
-
Fields 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, typeName
-
Fields 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 Constructor Description CurrencyFieldType()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkSchemaField(SchemaField field)
Check'sSchemaField
instances 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 moreIndexableField
instancesorg.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 underlyingRawCurrencyValueSource
as converted to the specified target Currency.static Currency
getCurrency(String code)
A wrapper aroundCurrency.getInstance
that returns null instead of throwingIllegalArgumentException
if the specified Currency does not exist in this JVM.String
getDefaultCurrency()
The identifier code for the default currency of this field typeorg.apache.lucene.search.Query
getExistenceQuery(QParser parser, SchemaField field)
Override the default existenceQuery implementation to run an existence query on the underlying amountField instead.org.apache.lucene.search.Query
getFieldQuery(QParser parser, SchemaField field, String externalVal)
Returns a Query instance for doing searches against a field.ExchangeRateProvider
getProvider()
org.apache.lucene.search.SortField
getSortField(SchemaField field, boolean reverse)
Returns the SortField instance that should be used to sort fields of this type.protected org.apache.lucene.search.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.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.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.void
inform(org.apache.lucene.util.ResourceLoader resourceLoader)
Load the currency config when resource loader initialized.void
inform(IndexSchema schema)
When index schema is informed, get field types for the configured dynamic sub-fieldsprotected void
init(IndexSchema schema, Map<String,String> args)
subclasses should initialize themselves with the args provided and remove valid arguments.boolean
isPolyField()
A "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.void
write(TextResponseWriter writer, String name, org.apache.lucene.index.IndexableField field)
calls back to TextResponseWriter to write the field value-
Methods inherited from class org.apache.solr.schema.FieldType
checkSupportsDocValues, createField, createField, 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 Detail
-
PARAM_DEFAULT_CURRENCY
protected static final String PARAM_DEFAULT_CURRENCY
- See Also:
- Constant Field Values
-
DEFAULT_DEFAULT_CURRENCY
protected static final String DEFAULT_DEFAULT_CURRENCY
- See Also:
- Constant Field Values
-
PARAM_RATE_PROVIDER_CLASS
protected static final String PARAM_RATE_PROVIDER_CLASS
- See Also:
- Constant Field Values
-
DEFAULT_RATE_PROVIDER_CLASS
protected static final String DEFAULT_RATE_PROVIDER_CLASS
- See Also:
- Constant Field Values
-
PARAM_FIELD_SUFFIX_AMOUNT_RAW
protected static final String PARAM_FIELD_SUFFIX_AMOUNT_RAW
- See Also:
- Constant Field Values
-
PARAM_FIELD_SUFFIX_CURRENCY
protected static final String PARAM_FIELD_SUFFIX_CURRENCY
- See Also:
- Constant Field Values
-
schema
protected IndexSchema schema
-
fieldTypeCurrency
protected FieldType fieldTypeCurrency
-
fieldTypeAmountRaw
protected FieldType fieldTypeAmountRaw
-
fieldSuffixAmountRaw
protected String fieldSuffixAmountRaw
-
fieldSuffixCurrency
protected String fieldSuffixCurrency
-
-
Method Detail
-
getCurrency
public static Currency getCurrency(String code)
A wrapper aroundCurrency.getInstance
that returns null instead of throwingIllegalArgumentException
if the specified Currency does not exist in this JVM.- See Also:
Currency.getInstance(String)
-
getDefaultCurrency
public String getDefaultCurrency()
The identifier code for the default currency of this field type
-
init
protected void init(IndexSchema schema, Map<String,String> args)
Description copied from class:FieldType
subclasses 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:FieldType
A "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:
isPolyField
in classFieldType
- Returns:
- true if the
FieldType.createFields(org.apache.solr.schema.SchemaField, Object)
method may return more than one field
-
checkSchemaField
public void checkSchemaField(SchemaField field) throws org.apache.solr.common.SolrException
Description copied from class:FieldType
Check'sSchemaField
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 theFieldType
. Subclasses may choose to throw aSolrException
if invariants are violated by theSchemaField.
- Overrides:
checkSchemaField
in classFieldType
- Throws:
org.apache.solr.common.SolrException
-
createFields
public List<org.apache.lucene.index.IndexableField> createFields(SchemaField field, Object externalVal)
Description copied from class:FieldType
Given aSchemaField
, create one or moreIndexableField
instances- Overrides:
createFields
in classFieldType
- Parameters:
field
- theSchemaField
externalVal
- The value to add to the field- Returns:
- An array of
IndexableField
- See Also:
FieldType.createField(SchemaField, Object)
,FieldType.isPolyField()
-
inform
public void inform(IndexSchema schema)
When index schema is informed, get field types for the configured dynamic sub-fieldsInforms the
IndexSchema
provided by theschema
parameter of an event (e.g., a newFieldType
was added, etc.- Specified by:
inform
in interfaceSchemaAware
- Parameters:
schema
- TheIndexSchema
instance 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:
inform
in 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:FieldType
Returns a Query instance for doing searches against a field.- Overrides:
getFieldQuery
in classFieldType
- Parameters:
parser
- TheQParser
calling the methodfield
- TheSchemaField
of the field to searchexternalVal
- The String representation of the value to search- Returns:
- The
Query
instance. This implementation returns aTermQuery
but 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 forUSD
is "2
". So for a document whose indexed value was currently equivalent to "5.43,USD
" using the the exchange provider for this field, this ValueSource would return a value of "543
"
-
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 underlyingRawCurrencyValueSource
as converted to the specified target Currency.For example: If the
targetCurrencyCode
param 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 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:
PARAM_DEFAULT_CURRENCY
,DEFAULT_DEFAULT_CURRENCY
,getValueSource(org.apache.solr.schema.SchemaField, org.apache.solr.search.QParser)
-
getExistenceQuery
public org.apache.lucene.search.Query getExistenceQuery(QParser parser, SchemaField field)
Override the default existenceQuery implementation to run an existence query on the underlying amountField instead.- Overrides:
getExistenceQuery
in classFieldType
- Parameters:
parser
- TheQParser
calling the methodfield
- TheSchemaField
of the field to search- Returns:
- The
Query
instance.
-
getSpecializedRangeQuery
protected org.apache.lucene.search.Query getSpecializedRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive)
Description copied from class:FieldType
Returns a Query instance for doing range searches on this field type.SolrQueryParser
currently passespart1
andpart2
as null if they are '*' respectively.minInclusive
andmaxInclusive
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/orpart2
as well as unequalminInclusive
andmaxInclusive
parameters 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:
getSpecializedRangeQuery
in classFieldType
- Parameters:
parser
- theQParser
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 not- Returns:
- a Query instance to perform range search according to given parameters
-
getSortField
public org.apache.lucene.search.SortField getSortField(SchemaField field, boolean reverse)
Description copied from class:FieldType
Returns the SortField instance that should be used to sort fields of this type.
-
getUninversionType
public UninvertingReader.Type getUninversionType(SchemaField sf)
Description copied from class:FieldType
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"
- Specified by:
getUninversionType
in classFieldType
- Parameters:
sf
- field instance- Returns:
- type to uninvert, or
null
(to disallow uninversion for the field) - See Also:
SchemaField.isUninvertible()
-
write
public void write(TextResponseWriter writer, String name, org.apache.lucene.index.IndexableField field) throws IOException
Description copied from class:FieldType
calls back to TextResponseWriter to write the field valueSub-classes should prefer using
FieldType.toExternal(IndexableField)
orFieldType.toObject(IndexableField)
to get the writeable external value off
instead of directly usingf.stringValue()
orf.binaryValue()
- Specified by:
write
in classFieldType
- Throws:
IOException
-
getProvider
public ExchangeRateProvider getProvider()
-
-