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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]