lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <hossman_luc...@fucit.org>
Subject RE: Announcement: Lucene powering CNET.com Product Category Listings
Date Wed, 31 Aug 2005 22:54:37 GMT

Zach,

Let's simplify the issue to displaying counts for a single "Attribute"
-- manufacturer.

Imagine that the main search you are executing is "+category:cameras
+price:[0 to 10]" and you want to sort it by name.  You also want to
display the counts per manufacturer for all products that match that query
(ie: mfg:cannon, mfg:kodak, mfg:hp, mfg:sony, etc...

First you make a Query object for "+category:cameras +price:[0 to 10]" and
you do a search on it sorted by name.  Now 90% of the page is done.  Next
you mke a QueryFilter out of that Query object, and you call the bits
method on it and you hang on to it.

Next you make a QueryFilter for each of the manufacturers you have that
you want counts for, and you call the bits method on each of them.  For
each of those BitSets, you intersect each one with the BitSet you got from
the orriginal query and then then cardinality tells you the number of
products in your result that match.

it might make more sense in psuedo-java...

  String[] mfgs = ...;
  String query = "+category:cameras +price:[0 to 10]";
  Query q = QueryParser.parse(query);
  Hits results = searcher.search(q, mySort)
  BitSet all = (new QueryFilter(q)).bits(reader)
  int[] mfg_counts = new int[mfgs.length];
  for i in (0 to mfgs.length) {
     BitSet these = (new QueryFilter(new TermQuery("mfg",mfgs[i]))).bits(reader);
     these.and(all)
     mfg_counts[i] = these.cardinality();
  }

Now results contains what you need to display the main results, and
mfgs and mfg_counts contain what you need to display the manufacturer
counts.



: Date: Wed, 31 Aug 2005 09:35:13 -0400
: From: "Friedland, Zachary (EDS - Strategy)"
: To: Chris Hostetter
: Subject: RE: Announcement: Lucene powering CNET.com Product Category
:     Listings
:
: Hoss -
:
: I'm interested in doing counts of various categories, but I didn't
: understand this statement:
:
: " For each Filter in each Attribute found in the Category's
: document, the Query is extracted, and again a QueryFilter is built to
: obtain a BitSet of all products which match.  The intersection of that
: BitSet with the BitSet from the initial Category Query is computed to
: determine the "count" to display next to the Filter label.  "
:
: Can you explain this a bit more?
:
: Thanks,
: Zach


-Hoss


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message