我第一次使用 lucene.net。它工作正常。我用 jcb geo 关键字搜索数据,结果出来了。我的第一个结果与 JCB 关键字有关,接下来的几个数据与 GEO 关键字有关。我只是不明白为什么 JCB 名列前茅。另一方面,最大结果与 GEO 有关。我认为 GEO 相关数据应该排在首位,然后 JCB 应该排在首位。
在这里,我给出了我用来搜索的代码。
string multiWordPhrase = "";
multiWordPhrase = txtSearch.Text.Trim().Replace("*", "").Replace("?", "").Replace("~", "");
IndexSearcher searcher = null;
List<SearchResult> list = new List<SearchResult>();
SearchResult oSr = null;
if (!string.IsNullOrEmpty(multiWordPhrase))
{
string[] fieldList = { "Title", "Description", "Url" };
List<BooleanClause.Occur> occurs = new List<BooleanClause.Occur>();
foreach (string field in fieldList)
{
occurs.Add(BooleanClause.Occur.SHOULD);
}
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);
ScoreDoc[] scoreDocs = topDocs.ScoreDocs;
int resultsCount = topDocs.TotalHits;
if (topDocs != null)
{
for (int i = (PageIndex * PageSize); i <= ((PageIndex + 1) * PageSize) && i < topDocs.ScoreDocs.Length; i++)
{
Document doc = searcher.Doc(topDocs.ScoreDocs[i].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);
}
}
lblMatchFound.Text = "Match Found " + resultsCount.ToString();
Pagination pagination = new Pagination();
pagination.BaseUrl = "/Search.aspx";
pagination.TotalRows = resultsCount;
pagination.CurPage = (PageIndex+1);
pagination.PerPage = PageSize;
pagination.PrevLink = "Prev";
pagination.NextLink = "Next";
pagination.SearchTerm = multiWordPhrase;
lblPager.Text = pagination.GetPageLinks(); ;
rptResult.DataSource = list;
rptResult.DataBind();
searcher.Close();
如果可能的话,请讨论为什么 JCB 相关数据排在首位,并告诉我如何自定义搜索结果,结果这些记录应该排在最前面,其中包含最大搜索词词.....就像 GEO。所以请建议如何自定义我的搜索结果,如果可能的话,请提供一些示例代码,因为我是 lucene.net 的新手,因此我可以更好地可视化。多谢