http://quranx.com/Search?q=oh+people+of+heaven&context=Quran
谁能告诉我如何更改以下代码以显示每个匹配结果的文本片段?我试过阅读示例等,但只能找到更新版本的 Lucene for Java 的相关信息。Lucene 对我来说似乎是一个魔法黑盒子。
public static IEnumerable<SearchResult> Search(
string queryString,
out int totalResults,
int maxResults = 100)
{
totalResults = 0;
if (string.IsNullOrEmpty(queryString))
return new List<SearchResult>();
var query = new MultiFieldQueryParser(
Lucene.Net.Util.Version.LUCENE_30,
new string[] { "Body", "SecondaryReferences" },
Analyzer
).Parse(queryString);
var indexReader = DirectoryReader.Open(
directory: Index,
readOnly: true);
var indexSearcher = new IndexSearcher(indexReader);
var resultsCollector = TopScoreDocCollector.Create(
numHits: maxResults,
docsScoredInOrder: true
);
indexSearcher.Search(
query: query,
results: resultsCollector
);
totalResults = resultsCollector.TotalHits;
var result = new List<SearchResult>();
foreach (var scoreDoc in resultsCollector.TopDocs().ScoreDocs)
{
var snippets = new List<SearchResultSnippet>();
var doc = indexSearcher.Doc(scoreDoc.Doc);
var searchResult = new SearchResult(
type: doc.Get("Type"),
id: doc.Get("ID"),
snippets: snippets
);
result.Add(searchResult);
}
return result;
}