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


Reply via email to