Asp.net Lucene.NET&;面搜索解决方案

Asp.net Lucene.NET&;面搜索解决方案,asp.net,search,lucene,lucene.net,Asp.net,Search,Lucene,Lucene.net,他们刚刚开始使用Lucene.NET,任何人都想知道是否有人有一个Lucene.NET的分面搜索示例 我知道下面的链接 这看起来很棒,但它所做的只是告诉我分面搜索中的结果数量,而不是告诉我如何检索这些结果的索引和详细信息。i、 e与Lucene.NET中的正常搜索相同 也就是说,从这个链接中,他有以下代码片段 private static void FacetedSearch(string indexPath, string genre, string term){ var search

他们刚刚开始使用Lucene.NET,任何人都想知道是否有人有一个Lucene.NET的分面搜索示例

我知道下面的链接

这看起来很棒,但它所做的只是告诉我分面搜索中的结果数量,而不是告诉我如何检索这些结果的索引和详细信息。i、 e与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条记录,属于“金融”类型,这是完美的,但文章似乎跳过了说明如何检索这些结果的索引并在屏幕上显示的部分

他在下面的链接中解释了这一点,用于普通搜索,而不是facet搜索

i、 正常搜索

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

任何帮助都将不胜感激

编辑:


或者我应该先进行搜索查询,然后对结果进行筛选?

位数组表示点击数。每个1都有一个索引,该索引等于文档id

所以1001001意味着索引中位置为0、3和6的文档与您的搜索匹配。你只需要从lucene索引中检索它们

var searcher = new IndexSearcher(indexPath);

// get document at position 0
var doc = searcher.Doc( 0 );

这是我不明白的部分,即如何从Lucene那里检索它们。如何将位数组索引传递给Hits=searcher.Search(searchQuery)之类的对象;所以我可以循环浏览hits文档。你必须一个接一个地获取文档啊,很酷,谢谢mathieu,还可以解释我如何获取这些索引吗?谢谢你的帮助mathieu,这让我走上了正确的轨道