Reputation: 34208
first time i am using lucene.net. it is working fine. i search the data with jcb geo keyword and result is coming. my first result is coming related with JCB keyword and next few data is coming with GEO keyword. i just do not understand why JCB is coming at top. on the other hand maximum result is related with GEO. i think GEO related data should come at top and then JCB should come.
here i am giving the code which i used to search.
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();
if it would be possible then please discuss why JCB related data is coming at top and also tell me how could i customize search result as a result those records should come at top which has go maximum search term word.....like GEO. so please suggest how to customize my search result and if possible then please come with some sample code because i am new in lucene.net as a result i can better visualize. thanks a lot
Upvotes: 0
Views: 1320
Reputation: 5246
You will need to understand the scoring formula that L.B. linked to have a better understanding of the score, and you will need to implement your own Similarity if you want to modify it.
In your case, what probably happens is that the JCB term is a lot less popular than the GEO term. It could also be that documents containing the JCB term are shorter.
Additionnaly you can also use the Explain method of the IndexSearcher to see how a doc was scored: http://lucene.apache.org/core/old_versioned_docs/versions/2_9_4/api/all/org/apache/lucene/search/IndexSearcher.html#explain(org.apache.lucene.search.Weight, int)
You can also use Luke for that: http://code.google.com/p/luke/downloads/list
With Luke, you do a search, select a result and click the Explain button to show an explanation of the hit.
Upvotes: 1