org.apache.solr.schema
Class CurrencyField

java.lang.Object
  extended by org.apache.solr.schema.FieldProperties
      extended by org.apache.solr.schema.FieldType
          extended by org.apache.solr.schema.CurrencyField
All Implemented Interfaces:
ResourceLoaderAware, SchemaAware

public class CurrencyField
extends FieldType
implements SchemaAware, ResourceLoaderAware

Field type for support of monetary values.

See http://wiki.apache.org/solr/CurrencyField


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.solr.schema.FieldType
FieldType.DefaultAnalyzer
 
Field Summary
protected static String DEFAULT_DEFAULT_CURRENCY
           
protected static String DEFAULT_PRECISION_STEP
           
protected static String DEFAULT_RATE_PROVIDER_CLASS
           
protected static String FIELD_SUFFIX_AMOUNT_RAW
           
protected static String FIELD_SUFFIX_CURRENCY
           
protected  FieldType fieldTypeAmountRaw
           
protected  FieldType fieldTypeCurrency
           
static org.slf4j.Logger log
           
protected static String PARAM_DEFAULT_CURRENCY
           
protected static Object PARAM_PRECISION_STEP
           
protected static String PARAM_RATE_PROVIDER_CLASS
           
 
Fields inherited from class org.apache.solr.schema.FieldType
analyzer, ANALYZER, args, CHAR_FILTER, CHAR_FILTERS, CLASS_NAME, docValuesFormat, falseProperties, FILTER, FILTERS, INDEX, INDEX_ANALYZER, MULTI_TERM, MULTI_TERM_ANALYZER, POLY_FIELD_SEPARATOR, postingsFormat, properties, QUERY, QUERY_ANALYZER, queryAnalyzer, similarity, SIMILARITY, similarityFactory, TOKENIZER, trueProperties, TYPE, TYPE_NAME, typeName
 
Fields inherited from class org.apache.solr.schema.FieldProperties
BINARY, DOC_VALUES, INDEXED, MULTIVALUED, OMIT_NORMS, OMIT_POSITIONS, OMIT_TF_POSITIONS, REQUIRED, SORT_MISSING_FIRST, SORT_MISSING_LAST, STORE_OFFSETS, STORE_TERMOFFSETS, STORE_TERMPOSITIONS, STORE_TERMVECTORS, STORED, TOKENIZED
 
Constructor Summary
CurrencyField()
           
 
Method Summary
 void checkSchemaField(SchemaField field)
          Check's SchemaField instances constructed using this field type to ensure that they are valid.
 List<IndexableField> createFields(SchemaField field, Object externalVal, float boost)
          Given a SchemaField, create one or more IndexableField instances
 ValueSource getConvertedValueSource(String targetCurrencyCode, org.apache.solr.schema.CurrencyField.RawCurrencyValueSource source)
           Returns a ValueSource over this field in which the numeric value for each document represents the value from the underlying RawCurrencyValueSource as converted to the specified target Currency.
static Currency getCurrency(String code)
          A wrapper arround Currency.getInstance that returns null instead of throwing IllegalArgumentException if the specified Currency does not exist in this JVM.
 Query getFieldQuery(QParser parser, SchemaField field, String externalVal)
          Returns a Query instance for doing searches against a field.
 ExchangeRateProvider getProvider()
           
 Query getRangeQuery(QParser parser, SchemaField field, org.apache.solr.schema.CurrencyValue p1, org.apache.solr.schema.CurrencyValue p2, boolean minInclusive, boolean maxInclusive)
           
 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.
 SortField getSortField(SchemaField field, boolean reverse)
          Returns the SortField instance that should be used to sort fields of this type.
 org.apache.solr.schema.CurrencyField.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 it's most granular form based on the default fractional digits.
 void inform(IndexSchema schema)
          When index schema is informed, add dynamic fields "*____currency" and "*____amount_raw".
 void inform(ResourceLoader resourceLoader)
          Load the currency config when resource loader initialized.
protected  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 the FieldType.createFields(org.apache.solr.schema.SchemaField, Object, float) method.
 void write(TextResponseWriter writer, String name, IndexableField field)
          calls back to TextResponseWriter to write the field value
 void write(XMLWriter xmlWriter, String name, IndexableField field)
           
 
Methods inherited from class org.apache.solr.schema.FieldType
createField, createField, getAnalyzer, getAnalyzerProperties, getClassArg, getDocValuesFormat, getIndexOptions, getNamedPropertyValues, getNonFieldPropertyArgs, getNumericType, getPostingsFormat, getQueryAnalyzer, getRewriteMethod, getSimilarity, getSimilarityFactory, getStringSort, getTypeName, hasProperty, indexedToReadable, indexedToReadable, isExplicitAnalyzer, isExplicitQueryAnalyzer, isMultiValued, isTokenized, multiValuedFieldCache, readableToIndexed, readableToIndexed, restrictProps, setAnalyzer, setArgs, setIsExplicitAnalyzer, setIsExplicitQueryAnalyzer, setQueryAnalyzer, setSimilarity, storedToIndexed, storedToReadable, toExternal, toInternal, toObject, toObject, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PARAM_DEFAULT_CURRENCY

protected static final String PARAM_DEFAULT_CURRENCY
See Also:
Constant Field Values

PARAM_RATE_PROVIDER_CLASS

protected static final String PARAM_RATE_PROVIDER_CLASS
See Also:
Constant Field Values

PARAM_PRECISION_STEP

protected static final Object PARAM_PRECISION_STEP

DEFAULT_RATE_PROVIDER_CLASS

protected static final String DEFAULT_RATE_PROVIDER_CLASS
See Also:
Constant Field Values

DEFAULT_DEFAULT_CURRENCY

protected static final String DEFAULT_DEFAULT_CURRENCY
See Also:
Constant Field Values

DEFAULT_PRECISION_STEP

protected static final String DEFAULT_PRECISION_STEP
See Also:
Constant Field Values

FIELD_SUFFIX_AMOUNT_RAW

protected static final String FIELD_SUFFIX_AMOUNT_RAW
See Also:
Constant Field Values

FIELD_SUFFIX_CURRENCY

protected static final String FIELD_SUFFIX_CURRENCY
See Also:
Constant Field Values

fieldTypeCurrency

protected FieldType fieldTypeCurrency

fieldTypeAmountRaw

protected FieldType fieldTypeAmountRaw

log

public static org.slf4j.Logger log
Constructor Detail

CurrencyField

public CurrencyField()
Method Detail

getCurrency

public static Currency getCurrency(String code)
A wrapper arround Currency.getInstance that returns null instead of throwing IllegalArgumentException if the specified Currency does not exist in this JVM.

See Also:
Currency.getInstance(String)

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.

Overrides:
init in class FieldType

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 the FieldType.createFields(org.apache.solr.schema.SchemaField, Object, float) 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 class FieldType
Returns:
true if the FieldType.createFields(org.apache.solr.schema.SchemaField, Object, float) method may return more than one field

checkSchemaField

public void checkSchemaField(SchemaField field)
                      throws SolrException
Description copied from class: FieldType
Check's SchemaField instances constructed using this field type to ensure that they are valid.

This method is called by the SchemaField constructor to check that it's initialization does not violate any fundemental requirements of the FieldType. The default implementation does nothing, but subclasses may chose to throw a SolrException if invariants are violated by the SchemaField.

Overrides:
checkSchemaField in class FieldType
Throws:
SolrException

createFields

public List<IndexableField> createFields(SchemaField field,
                                         Object externalVal,
                                         float boost)
Description copied from class: FieldType
Given a SchemaField, create one or more IndexableField instances

Overrides:
createFields in class FieldType
Parameters:
field - the SchemaField
externalVal - The value to add to the field
boost - The boost to apply
Returns:
An array of IndexableField
See Also:
FieldType.createField(SchemaField, Object, float), FieldType.isPolyField()

inform

public void inform(IndexSchema schema)
When index schema is informed, add dynamic fields "*____currency" and "*____amount_raw". Informs the IndexSchema provided by the schema parameter of an event (e.g., a new FieldType was added, etc.

Specified by:
inform in interface SchemaAware
Parameters:
schema - The IndexSchema instance that inform of the update to.

inform

public void inform(ResourceLoader resourceLoader)
Load the currency config when resource loader initialized.

Specified by:
inform in interface ResourceLoaderAware
Parameters:
resourceLoader - The resource loader.

getFieldQuery

public 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 class FieldType
Parameters:
parser - The QParser calling the method
field - The SchemaField of the field to search
externalVal - The String representation of the value to search
Returns:
The Query instance. This implementation returns a TermQuery but overriding queries may not

getValueSource

public org.apache.solr.schema.CurrencyField.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 it's 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 equivilent number of "cents" (ie: value in dollars * 100) after converting each document's native currency to USD -- because the default fractional digits for USD is "2". So for a document whose indexed value was currently equivilent to "5.43,USD" using the the exchange provider for this field, this ValueSource would return a value of "543"

Overrides:
getValueSource in class FieldType
See Also:
PARAM_DEFAULT_CURRENCY, DEFAULT_DEFAULT_CURRENCY, Currency.getDefaultFractionDigits(), getConvertedValueSource(java.lang.String, org.apache.solr.schema.CurrencyField.RawCurrencyValueSource)

getConvertedValueSource

public ValueSource getConvertedValueSource(String targetCurrencyCode,
                                           org.apache.solr.schema.CurrencyField.RawCurrencyValueSource source)

Returns a ValueSource over this field in which the numeric value for each document represents the value from the underlying RawCurrencyValueSource as converted to the specified target Currency.

For example: If the targetCurrencyCode param is set to USD, then the values returned by this value source would represent the equivilent number of dollars after converting each document's raw value to USD. So for a document whose indexed value was currently equivilent 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 used
source - the raw ValueSource to wrap
See Also:
PARAM_DEFAULT_CURRENCY, DEFAULT_DEFAULT_CURRENCY, getValueSource(org.apache.solr.schema.SchemaField, org.apache.solr.search.QParser)

getRangeQuery

public Query getRangeQuery(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 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.

Overrides:
getRangeQuery in class FieldType
Parameters:
parser - the QParser calling the method
field - the schema field
part1 - the lower boundary of the range, nulls are allowed.
part2 - the upper boundary of the range, nulls are allowed
minInclusive - whether the minimum of the range is inclusive or not
maxInclusive - whether the maximum of the range is inclusive or not
Returns:
a Query instance to perform range search according to given parameters

getRangeQuery

public Query getRangeQuery(QParser parser,
                           SchemaField field,
                           org.apache.solr.schema.CurrencyValue p1,
                           org.apache.solr.schema.CurrencyValue p2,
                           boolean minInclusive,
                           boolean maxInclusive)

getSortField

public 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.

Specified by:
getSortField in class FieldType
See Also:
SchemaField.checkSortability()

write

public void write(XMLWriter xmlWriter,
                  String name,
                  IndexableField field)
           throws IOException
Throws:
IOException

write

public void write(TextResponseWriter writer,
                  String name,
                  IndexableField field)
           throws IOException
Description copied from class: FieldType
calls back to TextResponseWriter to write the field value

Specified by:
write in class FieldType
Throws:
IOException

getProvider

public ExchangeRateProvider getProvider()


Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.