Lucene.NET 2.9 and BitArray/DocIdSet

Posted by Paul Knopf on Stack Overflow See other posts from Stack Overflow or by Paul Knopf
Published on 2010-06-01T00:14:12Z Indexed on 2010/06/01 0:23 UTC
Read the original article Hit count: 711

Filed under:
|

I found a great example on grabbing facet counts on a base query. It stores the bitarray of the base query to improve the performance each time the a facet gets counted.

        var genreQuery = new TermQuery(new Term("genre", genre));
        var genreQueryFilter = new QueryFilter(genreQuery);
        BitArray genreBitArray = genreQueryFilter.Bits(searcher.GetIndexReader());
        Console.WriteLine("There are " + GetCardinality(genreBitArray) + " document with the genre " + genre);

        // Next perform a regular search and get its BitArray result
        Query searchQuery = MultiFieldQueryParser.Parse(term, new[] {"title", "description"}, new[] {BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD}, new StandardAnalyzer());
        var searchQueryFilter = new QueryFilter(searchQuery);
        BitArray searchBitArray = searchQueryFilter.Bits(searcher.GetIndexReader());
        Console.WriteLine("There are " + GetCardinality(searchBitArray) + " document containing the term " + term);

The only problem is that I am using a newer version of Lucene.NET (2.9) and Filter.Bits is obsolete. We are told to use DocIdSet instead (rather than BitArray).

I cannot found out how to do the bitArray.And(bitArray) with a docIdSet. I looked in reflector and found OpenIdSet which has And operations. Not sure if OpenIdSet is the route to go, I'm just stating.

Thanks in advance!

© Stack Overflow or respective owner

Related posts about lucene.net

Related posts about faceted-search