8
我發現了一個很好的例子,在基本查詢上獲取方面計數。它存儲基本查詢的比特數,以在每一個方面被計數時提高性能。Lucene.NET 2.9和BitArray/DocIdSet
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)。我看着反射器,發現有OpenIdSet和操作。不知道是否OpenIdSet是要走的路線,我只是說。
在此先感謝!
感謝您分享答案,爲我節省了許多小時的研究 – Woland 2013-11-16 06:02:24