简体   繁体   中英

Irrelevant search results with lucene.net

I have been developing a search engine for a business directory application using Lucene.net. However when i search for Sports shop it returns the result of other shops including the sports shops because the key word shop matches with that. So how can i prioritize that it should return the results which is matches with the keyword sport

If anyone have solution for this please share here. Any helpful example or links will be appreciated.

I would very much appreciate it if you could paste some code to give you a better example.

However, from reading your question I think that what you need is a phrase query to give Sports Shop a higher boost.

My implementation of this query is this:

public List QueryToPhraseQuery(string pQuery) {

QueryParsers.Classic.MultiFieldQueryParser oPhraseParser = new QueryParsers.Classic.MultiFieldQueryParser(Version, FieldArray, Analyzer, BoostDictionary);
List<PhraseQuery> lstPhraseQuery = new List<PhraseQuery>();
HashSet<Term> lstTerms = new HashSet<Term>();
oPhraseParser.Parse(pQuery).ExtractTerms(lstTerms);


foreach (var group in lstTerms.GroupBy(x => x.Field))
{
    PhraseQuery oPhraseQuery = new PhraseQuery() { Boost = 10, Slop = 3 };
    foreach (var oTerm in group.ToList())
    {
        oPhraseQuery.Add(oTerm);
        if (oTerm.Field == Field.ImportantField)
            oPhraseQuery.Boost = 30;
    }
    lstPhraseQuery.Add(oPhraseQuery);
}

return lstPhraseQuery;

}

This would search for thing like this in your index which will match exactly and will return better results with more relevance

attributedescriptions:"something something"~3^10.0 attributemajor:"something something"~3^30.0 description:"something something"~3^10.0 edescription:"something something"~3^10.0

If you want me to give you an example using your code, just past eit and I can modify it to better fit your exam

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM