Hi, I have an index of 30 docs, 20 of which have an owner field of "UserA" and 10 of "UserB". I also have a query which consists of:
BooleanQuery: -- Clause 1: TermQuery -- Clause 2: FilteredQuery ----- Branch 1: MatchAllDocsQuery() ----- Branch 2: MyNDVFilter I execute my search as follows: searcher.search( booleanQuery, new TermFilter(new Term("owner", "UserA"), 50); The TermFilter's job is to reduce the number of searchable documents from 30 to 20, which it does for all clauses of the BooleanQuery except for MyNDVFilter which iterates through the full 30 docs, 10 needlessly. How can I restrict it so it behaves the same as the other query branches? MyNDVFilter source code: public class MyNDVFilter extends Filter { private String fieldName; private String matchTag; public TagFilter(String ndvFieldName, String matchTag) { this.fieldName = ndvFieldName; this.matchTag = matchTag; } @Override public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException { AtomicReader reader = context.reader(); int maxDoc = reader.maxDoc(); final FixedBitSet bitSet = new FixedBitSet(maxDoc); BinaryDocValues ndv = reader.getBinaryDocValues(fieldName); if (ndv != null) { for (int i = 0; i < maxDoc; i++) { BytesRef br = ndv.get(i); if (br.length > 0) { String strval = br.utf8ToString(); if (strval.equals(matchTag)) { bitSet.set(i); System.out.println("MyNDVFilter >> " + matchTag + " matched " + i + " [" + strval + "]"); } } } } return new DVDocSetId(bitSet); // just wraps a FixedBitSet } } Chris Bamford Senior Developer m: +44 7860 405292 p: +44 207 847 8700 w: www.mimecast.com Address click here: www.mimecast.com/About-us/Contact-us/