[英]Boosting Starts with and contains search using Elastic/NEST
I am doing a wildcard search as below and I want to have the starts with(her*) results to have more ranking than the contains( her ) search results. 我正在按以下方式进行通配符搜索,并且我希望以(*)开始的结果比包含( 她 )的搜索结果具有更高的排名。 Is there a way to achieve this?
有没有办法做到这一点?
elasticClient.Search<ClientSearchContract>(p =>
p.Query(q => q
.Bool(bq => bq
.Should(mq => mq.QueryString(qs =>
qs.Query(her* *her*))
)
)
)
.Sort(x => x.OnField("_score").Descending())
);
Here is something that could help you : 这可以为您提供帮助:
var result = elasticClient.Search<ClientSearchContract>(q => q
.Index("index")
.Type("type")
.Query(qq =>
{
QueryContainer startsQuery = null;
QueryContainer containQuery = null;
{
startsQuery |= qq.QueryString(qs => qs.OnFields(f => f.Field).Query("her*").Boost(2));
containQuery |= qq.QueryString(qs => qs.OnFields(f => f.Field).Query("*her*").Boost(1.2));
}
return startsQuery || containQuery;
})
.Take(10)
.Sort(x => x.OnField("_score").Descending())
);
We use custom score scripts for this purpose. 为此,我们使用自定义分数脚本。 In JSON it looks like this:
在JSON中,它看起来像这样:
"query":
{
"custom_score":
{
"query": *query* ,
"params" :
{
"streetMultiply": " + ((!searchQuery.HasCityValue()) ? 100 : 0) + @",
"addressMultiply": " + ((!searchQuery.HasStreetValue()) ? 100 : 0) + @"
}
,"script": "if (doc['streetId'].value == 0) { _score * streetMultiply } else { if (doc['addressId'].value == 0) { _score * addressMultiply } else { _score } }"
}
}, "size": 100 }"
We don't use NEST for this, but I've found a pull-requst for implementation this in NEST 我们不使用NEST这一点,但我已经找到了一个拉requst在NEST实现这个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.