[英]Lucene.NET & Facete Search Solution
嘿,剛開始使用Lucene.NET,有人想知道是否有人對Lucene.NET進行了多面搜索。
我知道以下鏈接http://www.devatwork.nl/articles/lucenenet/faceted-search-and-drill-down-lucenenet/
看起來不錯,但它所做的只是告訴我多面搜索的結果數量,但實際上卻不告訴我如何檢索這些結果的索引和詳細信息。 即與在Lucene.NET中進行常規搜索一樣。
即從該鏈接,他有以下片段
private static void FacetedSearch(string indexPath, string genre, string term){
var searcher = new IndexSearcher(indexPath);
// first get the BitArray result from the genre query
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);
// Now do the faceted search magic, combine the two bit arrays using a binary AND operation
BitArray combinedResults = searchBitArray.And(genreBitArray);
Console.WriteLine("There are " + GetCardinality(combinedResults) + " document containing the term " + term + " and which are in the genre " + genre);
}
哪個會告訴我,即搜索詞“ Dublin”有2條記錄,而類別為“ Financial”,這是完美的記錄,但本文似乎跳過了該部分,它說了如何檢索這些結果的索引並顯示在屏幕。
他的確在下面的鏈接中對此進行了說明,以進行常規搜索,但不進行面搜索。
即普通搜索
private static void Search(string indexPath, string term)
{
// create searcher
var searcher = new IndexSearcher(indexPath);
// create a query which searches through the title and description, the term can be in the title or the description
Query searchQuery = MultiFieldQueryParser.Parse(term, new[] {"title", "description"}, new[] {BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD}, new StandardAnalyzer());
// perform the search
Hits hits = searcher.Search(searchQuery);
// loop through all the hits and show their title
for (int hitIndex = 0; hitIndex < hits.Length(); hitIndex++)
{
// get the corresponding document
Document hitDocument = hits.Doc(hitIndex);
// write its title to the console
Console.WriteLine(hitDocument.GetField("title").StringValue());
}
}
http://www.devatwork.nl/articles/lucenenet/search-basics-lucenenet/
任何幫助將不勝感激
編輯:
還是應該執行搜索查詢,然后對結果進行過濾?
BitArray表示匹配。 每個1都有一個索引,等於文檔ID
因此1001001表示索引中位置為0、3和6的文檔與您的搜索匹配。 您只需要從Lucene索引中檢索它們即可。
var searcher = new IndexSearcher(indexPath);
// get document at position 0
var doc = searcher.Doc( 0 );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.