Class CurrencyFieldType

All Implemented Interfaces:
org.apache.lucene.util.ResourceLoaderAware, SchemaAware

public class CurrencyFieldType extends FieldType implements SchemaAware, org.apache.lucene.util.ResourceLoaderAware
  • Field Details

  • Constructor Details

    • CurrencyFieldType

      public CurrencyFieldType()
  • Method Details

    • getCurrency

      public static Currency getCurrency(String code)
      A wrapper around Currency.getInstance that returns null instead of throwing IllegalArgumentException if the specified Currency does not exist in this JVM.
      See Also:
    • 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.
      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) 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) 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'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 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.

      Overrides:
      checkSchemaField in class FieldType
      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 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
      Returns:
      An array of IndexableField
      See Also:
    • inform

      public void inform(IndexSchema schema)
      When index schema is informed, get field types for the configured dynamic sub-fields

      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(org.apache.lucene.util.ResourceLoader resourceLoader)
      Load the currency config when resource loader initialized.
      Specified by:
      inform in interface org.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 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.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 for USD is "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:
      getValueSource in class FieldType
      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 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 equivalent number of dollars after converting each document's raw value to USD. 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 used
      source - the raw ValueSource to wrap
      See Also:
    • 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 class FieldType
      Parameters:
      parser - The QParser calling the method
      field - The SchemaField 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 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 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 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
    • 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.
      Specified by:
      getSortField in class FieldType
      See Also:
    • 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 class FieldType
      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: FieldType
      calls back to TextResponseWriter to write the field value

      Sub-classes should prefer using FieldType.toExternal(IndexableField) or FieldType.toObject(IndexableField) to get the writeable external value of f instead of directly using f.stringValue() or f.binaryValue()

      Specified by:
      write in class FieldType
      Throws:
      IOException
    • getProvider

      public ExchangeRateProvider getProvider()