lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <cutt...@apache.org>
Subject Re: pre computing possible search results narrowing and hit counts on those
Date Wed, 30 Mar 2005 17:42:32 GMT
Antony Sequeira wrote:
> A user does a search for say "condominium", and i show him the 50,000
> properties that meet that description.
> 
> I need two other pieces of information for display -
> 1. I want to show a "select" box on the UI, which contains all the
> cities that appear in those 50,000 documents
> 2. Against each city I want to show the count of matching documents.
> 
> For example the drop down might look like
> "Los Angeles"  10000
> "San Francisco" 5000
> 
> (But, I do not want to show "San Jose" if none of the 50,000 documents
> contain it)

You can use the FieldCache & HitCollector:

private class Count { int value; }

String[] docToCity = FieldCache.getStrings(indexReader, "city");
Map cityToCount = new HashMap();

searcher.search(query, new HitCollector() {
   public void collect(int doc, float score) {
     String city = docToCity[doc];
     Count count = cityToCount.get(city);
     if (count == null) {
       count = new Count();
       cityToCount.put(city, count);
     }
     count.value++;
   }
});

// sort & display entries in cityToCount

Doug

---------------------------------------------------------------------
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