简体   繁体   English

lucene.net不相关的搜索结果

[英]Irrelevant search results with lucene.net

I have been developing a search engine for a business directory application using Lucene.net. 我一直在使用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 因此,我如何确定其应返回与关键字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. 但是,从阅读您的问题后,我认为您需要的是短语查询,以使Sports Shop的销售额更高。

My implementation of this query is this: 我对此查询的实现是这样的:

public List QueryToPhraseQuery(string pQuery) { 公共列表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 如果您希望我通过您的代码为您提供示例,就在eit过去之后,我可以对其进行修改以更好地适合您的考试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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