You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by "insight49@gmail.com" <in...@gmail.com> on 2011/05/24 04:51:19 UTC
Stats help needed on price field using different currencies
Hi all,
I took a look at:
http://lucene.472066.n3.nabble.com/Tuning-StatsComponent-td2225809.html
which is a similar problem.
I have a "price" field, on which I'm faceting (stats.field=price). But
the currency of those docs is different, so the returned value is
useless without converting the prices to the same currency BEFORE the
returned stats value.
E.g.:
<doc>
<field name="id">1</id>
<field name="price">100.00</id>
<field name="currency">USD</id>
</doc>
<doc>
<field name="id">2</id>
<field name="price">200.00</id>
<field name="currency">GBP</id>
</doc>
<doc>
<field name="id">3</id>
<field name="price">300.00</id>
<field name="currency">AUD</id>
</doc>
The result of the facet returns "200.00" for a mean, which, based on the
price values is correct, yet erroneous.
Is there a way to pass a math function into the facet BEFORE the results?
e.g. if currency='GBP' then sum(price * 1.61) else if currency='HKD'
then sum(price * 1.05) else price
A tedious workaround has been to do a stats.facet=currency, then do my
stats calculations by summing/dividing each returned sub result to find
an aggregate.
Is there an easier solution, or have devs thought of adding the ability
to pass a calculation before the returned stats values, maybe
s.field.pre.math / s.field.post.math in solrconfig or the query?
Thanks for your help,
Dan
Re: Stats help needed on price field using different currencies
Posted by Erick Erickson <er...@gmail.com>.
I suspect that any such change wouldn't be very performant since you'd
somehow have to understand what the currency was for each doc, which
you'd get from the doc somehow...
What I'd do is add something like "normalized_price" at index time that
converted all prices into the currency of your choice and collect stats
on that instead. You wouldn't even have to do that if you were willing
to convert from normalized currency to "original" currency before
displaying the documents....
Best
Erick
On Mon, May 23, 2011 at 7:51 PM, insight49@gmail.com
<in...@gmail.com> wrote:
> Hi all,
>
> I took a look at:
>
> http://lucene.472066.n3.nabble.com/Tuning-StatsComponent-td2225809.html
>
> which is a similar problem.
>
> I have a "price" field, on which I'm faceting (stats.field=price). But the
> currency of those docs is different, so the returned value is useless
> without converting the prices to the same currency BEFORE the returned stats
> value.
>
> E.g.:
>
> <doc>
> <field name="id">1</id>
> <field name="price">100.00</id>
> <field name="currency">USD</id>
> </doc>
> <doc>
> <field name="id">2</id>
> <field name="price">200.00</id>
> <field name="currency">GBP</id>
> </doc>
> <doc>
> <field name="id">3</id>
> <field name="price">300.00</id>
> <field name="currency">AUD</id>
> </doc>
>
> The result of the facet returns "200.00" for a mean, which, based on the
> price values is correct, yet erroneous.
>
> Is there a way to pass a math function into the facet BEFORE the results?
>
> e.g. if currency='GBP' then sum(price * 1.61) else if currency='HKD' then
> sum(price * 1.05) else price
>
> A tedious workaround has been to do a stats.facet=currency, then do my stats
> calculations by summing/dividing each returned sub result to find an
> aggregate.
>
> Is there an easier solution, or have devs thought of adding the ability to
> pass a calculation before the returned stats values, maybe s.field.pre.math
> / s.field.post.math in solrconfig or the query?
>
> Thanks for your help,
>
> Dan
>