lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Otis Gospodnetic <>
Subject Re: Sum of one field
Date Mon, 04 Aug 2008 19:47:25 GMT
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.

Sematext -- -- Lucene - Solr - Nutch

----- Original Message ----
> From: Leonardo Dias <>
> To:
> 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

View raw message