lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Nigl <matthew.n...@gmail.com>
Subject Re: Currency calculation does not seem to be using cross-rates
Date Wed, 01 Oct 2014 05:35:42 GMT
For anyone interested, I realised that there are differences between the
various ways of using currency. Not all appear to support asymmetric rates,
and documents that do not need conversion are converted anyway, sometimes
introducing rounding error.

For point queries. e.g. fq=price_c:100,AUD
 - the query value is converted to the default currency and the indexed
value is converted to the default currency, then compared
 - from debug it is: frange(rawcurrency(price_c,target=USD)):[8700 TO 8700]

For range queries. e.g. fq=price_c:[100,AUD TO 200,AUD]
 - the query value is used directly and the indexed value is directly
converted to the target currency, then compared.
 - from debug it is: frange(rawcurrency(price_c,target=AUD)):[10000 TO
20000]

For the currency function. e.g. currency(price_c,AUD)
 - the indexed value is converted to the default currency, then it is
converted again to the target currency

So if you rely on using the currency function, especially to return values
to the view, then this may be inaccurate if the indexed value is in the
same currency as the target currency, where target currency is not the
default currency. I often see a value such as 500,AUD in the index get
returned as 499.99 due to the rounding error when it is converted from AUD
-> USD -> AUD.

If I am using any of the above incorrectly then please let me know.

Regards,
Matt


On 29 August 2014 14:54, Matthew Nigl <matthew.nigl+solr@gmail.com> wrote:

> Hi all,
>
> I have an issue where the currency function is not returning the expected
> value in particular scenarios. I believe my config is correct and I am able
> to replicate the issue over a few machines.
>
> The issue occurs when converting the value of a currency field from the
> source currency into a target currency, where neither are the default
> currency as set in the schema. For example:
> - the schema contains a field called "price" of type "currency", where
> defaultCurrency="USD"
> - the value indexed is "500,EUR"
> - the query string is ?q=*:*&fl=currency(price,AUD)
> - the currency.xml contains the following rates, which are set to
> exaggerate the issue:
>    <rate from="EUR" to="AUD" rate="0.5" />
>    <rate from="EUR" to="USD" rate="0.5" />
>    <rate from="USD" to="AUD" rate="2" />
> - the value returned is "500". The expected value is "250"
>
> So it appears that the value is calculated by converting from source
> currency -> default currency, and then from default currency -> target
> currency. However, the direct conversion from EUR to AUD is available, so I
> expect that it should be used to generate the value instead.
>
> This issue also occurs when the source currency and target currency are
> the same, as long as it is not the default currency. For example, when
> converting from AUD to AUD with a default currency of USD, I often notice
> rounding errors since (source->default rate) * (default->target rate) != 1
> for many cases.
>
> I have included the relevant part of my schema below. I have tested on
> both 4.8.1 and 4.9.0.
>
> <field name="price" type="currency" indexed="true" stored="true"
> multiValued="false"/>
>
> <fieldType name="currency" class="solr.CurrencyField" precisionStep="8"
> defaultCurrency="USD" currencyConfig="currency.xml" />
>
>
> Regards,
> Matt
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message