Hello, Otis!
I believe the best approach would be hacking the SolrIndexSearcher in
our case. Let me explain further what we want to know with a Car ad
website example.
Imagine that you have a website called CarStores and that you let people
search by brand, sorting by price etc.
So I'm looking for a Ferrari. CarStore says that there are 5 ads for
Ferrari, but one ad has 2 Ferraris being sold, the other ad has 3
Ferraris and all the others have 1 Ferrari each, meaning that there are
5 ads and 8 Ferraris. And yes, I'm doing an example with Fibonacci
numbers. ;)
Since I believe this could be a solution not only for us, maybe it's a
simple feature SOLR could have embedded in its code base.
If you guys think this is a good idea, please let me know. I believe it
would be very useful to let people understand what are they finding when
they search.
Best,
Leonardo.
Otis Gospodnetic escreveu:
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