Эй, только что начал использовать 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);
}
Что скажет мне, т.е. есть 2 записи для поискового термина "Дублин" и которые в жанре "Финансовый", что идеально, но статья пропускает ту часть, где говорится, как я могу получить индексы этих результатов и отображать на экране.
Он объясняет это в приведенной ниже ссылке для обычного поиска, но не для поиска по фасету.
т.е. обычный поиск
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/
Любая помощь будет принята с благодарностью
Редактировать:
Или я должен выполнить поисковый запрос, а затем выполнить фильтр по результатам?