lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <>
Subject [Solr Wiki] Update of "MoneyFieldType" by JanHoydahl
Date Thu, 08 Mar 2012 23:12:50 GMT
Dear Wiki user,

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

The "MoneyFieldType" page has been changed by JanHoydahl:

- <!> Work in progress at [[|SOLR-2202]]
+ Moved. Please see CurrencyField
- The MoneyFieldType was created by Greg Fodor in [[|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.
- === 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="money" class="solr.MoneyType" currencyConfig="currency.xml" />
-   <field name="price" type="money" defaultCurrency="EUR" />
- }}}
- !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:
- {{{
- <currencyConfig version="1.0">
-   <rates>
-     <!-- Example -->
-     <rate from="USD" to="JPY" rate="81.29"/>
-     <!-- Fake rates for testing -->
-     <rate from="USD" to="EUR" rate="2.5"/>
-     <rate from="USD" to="GBP" rate="0.5"/>
-     <rate from="EUR" to="GBP" rate="0.5"/>
-     <!-- Asymmetric rate -->
-     <rate from="EUR" to="USD" rate="0.5"/>
-   </rates>
- </currencyConfig>
- }}}
- Note that you need a rate entry between every two pairs of currencies you will index or
query. So if you handle USD, EUR and GBP, you need USD->EUR, USD->GBP and EUR->GBP,
so that all possible conversions can be done. If you only index one currency (say USD) but
want to query or convert multiple, it is enough to have rates between USD and all currencies
you'll query or display.
- By default the rate will be symmetrical, but you may override this by explicitly specifying
the reverse rate.
- !MoneyFieldType 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.
- === 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 !MoneyFieldType supports both point queries and range queries. Here are some valid money
queries. Assume default currency is {{{EUR}}}:
- {{{
- price:25.00,EUR                 or price:25.00               Both of these will query for
- price:[* TO 10.00,EUR]          or price:[* TO 10.00]
- price:[10.00,USD TO 100.00,USD]                              Meaning between $10.00 and
- price:10.00,NOK
- }}}
- === Usage ===
- Solr documents will always yield the currency values they were indexed with, regardless
of how they were queried for. For example, a set of documents indexed in USD will yield USD
values for its Money fields regardless if you performed queries in EUR. 
- So, for the display of Money fields to a user, it is often necessary to perform a second
currency conversion once the documents are returned for display purposes. For accuracy, this
conversion should apply the same exchange rates in the currency.xml file available to Solr.
- == TODO ==
-  * facet.range does not work with this field type - this should be fixed

View raw message