The problem with your code is , that the IndexSearcher.search() method works per segment, but in your cardinality code you are using top-level-readers, so it will cache two times (once per segments and once for the top-level MultiReader/DirectoryReader). Also not all DocIdSet implementations extend OpenBitSet, so cardinality is not always available and for some queries you might get a ClassCastException.
To just count the results use TotalHitCountCollector (since Lucene Core 3.1) with IndexSaercher.search(). Uwe ----- Uwe Schindler H.-H.-Meier-Allee 63, D-28213 Bremen http://www.thetaphi.de eMail: u...@thetaphi.de > -----Original Message----- > From: Konstantyn Smirnov [mailto:inject...@yahoo.com] > Sent: Monday, July 25, 2011 11:08 AM > To: java-user@lucene.apache.org > Subject: Reusing a CachingWrapperFilter > > Hi all! > > are there any limitations or implications on reusing a CWF? > > In my app I'm doing the following: > > Filter filter = new BooleanFilter(...) > // initialized with a couple of Term-, Range-, Boolean- and PrefixFilter > > CachingWrapperFilter cwf = new CachingWrapperFilter( filter ) > > searcher.search( query, cwf ... ) // << here, the filter's docIdSet gets cached, > right? > > // now I need to iterate over a list of categories and calculate the number of > goods in each of them > > for( cat in categories ){ > Filter catFilter = new BooleanFilter() > TermsFilter tf = new TermsFilter() > tf.addTerm new Term( 'category, cat ) > > catFilter.add new FilterClause( cwf, ... ) > catFilter.add new FilterClause( tf, ... ) > > long freq = catFilter.getDocIdSet( indexReader ).cardinality() > > //do stuff with freq > } > > Is this a correct use? Shall the filter with a pre-cached bitSet be combined > with the new one inside the BooleanFilter like that? > Or maybe should I use searcher.search( query, filter, ... ).totalCount instead > of catFilter.getDocIdSet( indexReader ).cardinality()? > > TIA > > Konstantyn > > -- > View this message in context: http://lucene.472066.n3.nabble.com/Reusing- > a-CachingWrapperFilter-tp3196928p3196928.html > Sent from the Lucene - Java Users mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org > For additional commands, e-mail: java-user-h...@lucene.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org