Hi Uwe

I was just composing an email to you, so here it is!

You just have to implement the "protected boolean matchDoc(int
docId)" method. You should return this DocIdSet from your filter
instead of the manual code you created.

Yes, I tried that, see below ...

Sorry about earlier, I did manage to find FieldCacheDocIdSet in 4.10.2.

I have to confess that I'm getting a bit confused now with the long email trail! So this is what I have now implemented, but I still get no acceptDocs coming into my filter, I guess I am still missing something fundamental:

Firstly I have created a simple filter which just reports on what it is passed (note that I am using AtomicReaderContext as that is what other 4.10 filters seem to use - is this correct?):

public class MyBinaryDocValuesFilter extends Filter {
    private String fieldName;
    private String matchTag;

    public MyBinaryDocValuesFilter(Term term) {
        this.fieldName = term.field();
        this.matchTag = term.text();
    }

    @Override
public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {

        System.out.println("MyBinaryDocValuesFilter: acceptDocs is "
               + ((acceptDocs == null) ? "NULL" : "ALIVE!!"));

return new FieldCacheDocIdSet(context.reader().maxDoc(), acceptDocs) {
            @Override
            protected final boolean matchDoc(int doc) {
                System.out.println("MyBinaryDocValuesFilter>> " + doc);
                return false;
            }
        };
    }
}

As it stands, getDocIdSet() is reporting acceptDocs=NULL and matchDoc() is being passed all 30 docs :-(

The query / filter now looks like this:

    private int doQuery(Directory dir, Term term) throws Exception {

        DirectoryReader reader = DirectoryReader.open(dir);

Filter myBDVTagFilter = new CachingWrapperFilter(new MyBinaryDocValuesFilter(term));
        Query myBDVTagQuery = new ConstantScoreQuery(myNDVTagFilter);

        BooleanQuery booleanQuery = new BooleanQuery();
        TermQuery tagsTermQuery = new TermQuery(term);
        booleanQuery.add(tagsTermQuery, BooleanClause.Occur.SHOULD);
        booleanQuery.add(myBDVTagQuery, BooleanClause.Occur.SHOULD);

        IndexSearcher searcher = new IndexSearcher(reader);
Filter ownerFilter = new TermFilter(new Term("owner", "Bilbo"));
        TopDocs td = searcher.search(booleanQuery, ownerFilter, 100);

        ScoreDoc[] sd = td.scoreDocs;
        for (int i=0; i < sd.length; i++) {
            Document hitDoc = searcher.doc(sd[i].doc);
            System.out.println("Hit: " + sd[i].doc + " : " + hitDoc);
        }

        reader.close();

        return sd.length;
    }

I have also unsuccessfully tried using a BooleanFilter in place of ownerFilter (combination of
ownerFilter and allDocs, operator=MUST).

I think I must be close now ...

Thanks,

- Chris


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

Reply via email to