lucene.netの検索結果のページ付けをしたい。インデックスからデータをフェッチする場合、各ページで10レコードのみをフェッチする必要があります。だから私はlucene.netページングトリックを検索しました、そして私は私には明確ではない答えを得ました。こちらです...ご覧ください。
Hits hits = searcher.search(query);
int offset = page * recordsPerPage;
int count = Math.min(hits.length() - offset, recordsPerPage);
for (int i = 0; i < count; ++i) {
Document doc = hits.doc(offset + i);
}
TopDocs topDocs = indexSearcher.Search(query, null, 150);
for(int i=100, i<min(topDocs.totalHits,150); i++) {
Document doc = indexSearcher.doc(topDocs.scoreDocs[i]);
// Do something with the doc
}
私はそれのためのより良い技術があるかどうかを知る必要があります。話し合ってください。ありがとう
ここから私の更新開始
インデックスを検索するために使用していた別の方法。コードを取得した後、コードに取り込もうとしましたが、エラーが発生しました。私のコードを見て、ページングロジックを使用できるように変換してください。
これが私のコードです
int PageIndex=0;
int PageSize=10;
searcher = new IndexSearcher(_directory, false);
Query qry = MultiFieldQueryParser.Parse(Version.LUCENE_29, multiWordPhrase, fieldList, occurs.ToArray(), new StandardAnalyzer(Version.LUCENE_29));
TopDocs topDocs = searcher.Search(qry, null, ((PageIndex + 1) * PageSize), Sort.RELEVANCE);
int resultsCount = topDocs.TotalHits;
lblMatchFound.Text = "Match Found " + resultsCount.ToString();
List<SearchResult> list = new List<SearchResult>();
SearchResult oSr = null;
if (topDocs != null)
{
ScoreDoc[] scoreDocs = topDocs.ScoreDocs;
foreach (ScoreDoc scoreDoc in scoreDocs)
{
Document doc = searcher.Doc(scoreDoc.doc);
oSr = new SearchResult();
oSr.ID = doc.Get("ID");
oSr.Title = doc.Get("Title");
oSr.Description = doc.Get("Description");
//oSr.WordCount = AllExtension.WordCount(oSr.Description, WordExist(oSr.Title, multiWordPhrase));
string preview =
oSr.Description = AllExtension.HighlightKeywords(oSr.Description, multiWordPhrase); //sr.Description;
oSr.Url = doc.Get("Url");
list.Add(oSr);
}
}
ページングを実行できるように、コードを確認して再構築してください。ありがとう