Lucene.NET 2.9和BitArray / DocIdSet

时间:2010-06-01 00:14:13

标签: lucene.net faceted-search

我找到了一个关于在基本查询上获取构面计数的好例子。它存储基本查询的bitarray,以便在每次计算facet时提高性能。

        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);

唯一的问题是我使用的是较新版本的Lucene.NET(2.9)和Filter.Bits已经过时了。我们被告知使用DocIdSet(而不是BitArray)。

我无法找到如何使用docIdSet执行bitArray.And(bitArray)。我查看了反射器并找到了具有And操作的OpenIdSet。不确定OpenIdSet是不是要走的路,我只是在陈述。

提前致谢!

1 个答案:

答案 0 :(得分:14)

找到它。

            var productsDISI = new OpenBitSetDISI(productResults.Iterator(), 25000);
            var termQuery = new TermQuery(new Term("Spec" + expectedFacet.SpecificationId, expectedFacet.SpecificationOptionId.ToString()));
            var termQueryFilter = new QueryWrapperFilter(termQuery);
            var termIterator = termQueryFilter.GetDocIdSet(productReader).Iterator();
            productsDISI.InPlaceAnd(termIterator);
            var total = productsDISI.Cardinality();

也变得更快。