Just on I'm working on the similar issue per customer request.
StatsComponent - it will return min,max,sum,qt,avg as follows:
&stats=on&stats.field=price
<stats>
<stats_fields>
<lst name="price">
<double name="min">10</double>
<double name="max">30</double>
<double name="avg">20</double>
<double name="sum">60</double>
<double name="qt">3</double>
</lst>
</stats_fields>
</stats>
WRT "stats", the component can output sum and avg, but not
sd and var. As our main purpose is to get "market price",
the output should be enough.
I'll upload the patch soon.
Koji
Leonardo Dias wrote:
Hi, Svein!
Your approach is a great idea, even though it is not the best yet.
It would be even nicer if we could just tell SOLR to sum up everything
in a facet, already caching that... but this is great and it could
work nicely! Thank you very much. We will try that out.
This is more of a solr-dev question, but I don't subscribe to that
list, so here it goes: where in the SOLR code we could change that
facet behaviour to cope with this idea or a much better one? We have
resources here. With the right hints we could even contribute with
SOLR improvement.
Best,
Leonardo
Svein Parnas escreveu:
The easiest solution would probably be to have a facet on the
quantity field and calculate the total quantity on the client side.
Svein
On 4. aug.. 2008, at 21.47, Otis Gospodnetic wrote:
Leonardo,
You'd have to read that "quantity" fields for all matching documents
one way or the other.
One way is by getting all results and pulling that field out, so you
can get the sum..
Another way is to hack the SolrIndexSearcher and get this value in
one of the HitCollector collect method calls.
Another possibility, if your index is fairly static, might be to
read it all documents' (not just matches') quantity field and store
that in a docID->quantity map structure that lets you look up
quantity for any docID you want.
There may be other/better ways of doing this, but this is what comes
to (my) mind first.
Otis
--
Sematext -- http://sematext.com/ -- Lucene - Solr - Nutch
----- Original Message ----
From: Leonardo Dias <[EMAIL PROTECTED]>
To: solr-user@lucene.apache.org
Sent: Monday, August 4, 2008 1:19:45 PM
Subject: Sum of one field
Everyone exhibits "your search for x has returned y results" on the
top
of the results page, but we need something else, which would be
something like "your search for x returned y results in z records",
being z the numdocs of the SOLR response and y a SUM(quantity) of all
returned records.
In SQL you can do something like:
SELECT count(1), sum(quantity) FROM table
But with SOLR we don't know how can we do the same without having to
return all the XML result for the field "quantity" and then sum it to
show the total. Any hints on how to do it in a better way?
cheers,
Leonardo