lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Solr Wiki] Update of "CurrencyField" by JanHoydahl
Date Fri, 09 Mar 2012 16:50:21 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Solr Wiki" for change notification.

The "CurrencyField" page has been changed by JanHoydahl:
http://wiki.apache.org/solr/CurrencyField?action=diff&rev1=1&rev2=2

Comment:
Updated to reflect last patch

  
  The CurrencyField type was created by Greg Fodor in [[https://issues.apache.org/jira/browse/SOLR-2202|SOLR-2202]],
and is an advanced poly field type indexing a monetary value as both value and currency. It
lets e.g. an e-commerce site to display and query prices in many currencies, while only indexing
the price in one field/currency.
  
- The field type is backed by an XML file {{{currency.xml}}} specifying exchange rates. This
file may be updated without need for reindexing, and a reload-core will set live the updated
exchange rates.
+ The field type is backed by a pluggable !ExchangeRateProvider. The provider shipping with
Solr as default is the {{{FileExchangeRateProvider}}}. Changes in exchange rates from the
provider does not require re-indexing, since all conversions are done query-time. You simply
choose for each document which currency to index, and this will be fixed.
  
  === Configuration ===
  See example schema for example of how to use the field type. The field type and field is
defined in schema.xml as follows:
  {{{
-   <fieldType name="currency" class="solr.CurrencyField" currencyConfig="currency.xml"
/>
+   <fieldType name="currency" class="solr.CurrencyField" currencyConfig="currency.xml"
defaultCurrency="EUR" />
  
-   <dynamicField name="*_c" type="currency" defaultCurrency="EUR" />
+   <dynamicField name="*_c" type="currency" />
  }}}
  
  !DefaultCurrency will be used if you do not specify a currency. The default defaultCurrency
is {{{USD}}}, if not specified. Note that defaultCurrency cannot be changed unless followed
by a full re-index.
  
- You then need to point to a {{{currency.xml}}} file specifying the exchange rates:
+ === Indexing ===
+ When you index e.g. a price, you specify value and currency separated by comma. We use the
dynamicField {{{*_c}}} in our examples:
+ {{{
+ <doc>
+   <field name="id">1</field>
+   <field name="myprice_c">1.00,USD</field>
+ </doc>
+ }}}
+ 
+ Here, 1.00,USD is assumed to mean $1.00. Note that regardless of the currency being indexed,
you must encode the value as a floating point value (with a decimal point.) The fractional
portion of the floating point value is interpreted based upon the currency, via Currency.getDefaultFractionDigits().
+ 
+ 
+ === Querying ===
+ The !CurrencyField supports both point queries and range queries. Here are some valid money
queries. Assume default currency is {{{USD}}}.
+ In the example schema there is a copyField from "price" to "price_c", meaning that you can
test this on the example data:
+ {{{
+ price_c:25.00,USD                 or price_c:25.00               Both of these will query
for USD 25.00 since USD is default
+ price_c:[* TO 10.00,USD]          or price_c:[* TO 10.00]
+ price_c:[10.00,EUR TO 100.00,EUR]
+ price_c:10.00,NOK
+ }}}
+ 
+ === ExchangeRateProviders ===
+ You may plug in your own provider class through implementing the interface {{{ExchangeRateProvider}}}.
It may be backed by a web-service, by a flat file, a DB or what have you.
+ 
+ You specify which provider class to use through the parameter {{{providerClass}}} on the
fieldType.
+ If no provider is specified in the fieldType config, {{{FileExchangeRateProvider}}} is used
as default.
+ 
+ ==== FileExchangeRateProvider ====
+ This provider ships with Solr and is backed by an XML file {{{currency.xml}}}, and a fieldType
using this provider. It requires one parameter {{{currencyConfig}}} which should point to
your XML file. This config is looked up through Solr's !ResourceLoader.
+ 
+ The example {{{currency.xml}}} file in "conf" folder shows how the config could look. Here's
an example:
  
  {{{
  <currencyConfig version="1.0">
@@ -39, +70 @@

  
  By default the rate will be symmetrical, but you may override this by explicitly specifying
the reverse rate.
  
- !CurrencyField supports replication, given that you explicitly configure replication for
{{{currency.xml}}}. Upon the arrival of a new version of currency.xml, Solr slaves will do
a core reload and begin using the new exchange rates. See [[SolrReplication#How_are_configuration_files_replicated.3F|SolrReplication]]
for more.
+ Replication is supported, given that you explicitly configure replication for {{{currency.xml}}}.
Upon the arrival of a new version of currency.xml, Solr slaves will do a core reload and begin
using the new exchange rates. See [[SolrReplication#How_are_configuration_files_replicated.3F|SolrReplication]]
for more. SolrCloud is also supported since we use !ResourceLoader to load the file.
- 
- === Indexing ===
- When you index e.g. a price, you specify value and currency separated by comma:
- {{{
- <doc>
-   <field name="id">1</field>
-   <field name="price">1.00,USD</field>
- </doc>
- }}}
- 
- Here, 1.00,USD is assumed to mean $1.00. Note that regardless of the currency being indexed,
you must encode the value as a floating point value (with a decimal point.) The fractional
portion of the floating point value is interpreted based upon the currency, via Currency.getDefaultFractionDigits().
- 
- 
- === Querying ===
- The !CurrencyField supports both point queries and range queries. Here are some valid money
queries. Assume default currency is {{{USD}}}.
- In the example schema there is a copyField from "price" to "price_c", meaning that you can
test this on the example data:
- {{{
- price_c:25.00,USD                 or price_c:25.00               Both of these will query
for USD 25.00 since USD is default
- price_c:[* TO 10.00,USD]          or price_c:[* TO 10.00]
- price_c:[10.00,EUR TO 100.00,EUR]
- price_c:10.00,NOK
- }}}
  
  === Usage ===
  

Mime
View raw message