剛剛開始使用Lucene.NET,任何人都想知道是否有人用分面搜索的Lucene.NET的工作示例。Lucene.NET&Facete搜索解決方案
我知道這下面的鏈接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);
}
它會告訴我即有2個記錄搜索詞「都柏林」,並且即是在體裁「金融」,這是完美的,但文章似乎跳過了它說我如何檢索這些結果的索引並顯示在屏幕上的部分。
他沒有解釋在下面的鏈接,正常的搜索,但沒有facete搜索..
即普通搜索
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/
任何幫助,將不勝感激
編輯:
或s我應該做一個搜索查詢,然後對結果進行過濾嗎?
這就是我沒有得到的部分,即如何從Lucene中檢索它們。如何將位數組索引傳遞給Hits hit = searcher.Search(searchQuery); 這樣我就可以循環點擊文檔。 – StevieB 2011-04-13 13:15:47
你必須逐個獲取文檔 – mathieu 2011-04-13 14:53:55
感謝mathieu啊很酷,還可以解釋我如何得到這些索引? – StevieB 2011-04-13 15:02:00