因此,在Solr中,我们有以下用例:
关键字的集合,关键字(我们查询的实际短语),match_type(可以是否定的,精确的或广泛的)。目前,我们有2个字段类型,具有不同的查询和索引过滤器集,一个用于精确和否定(它们是相同的),一个用于广泛。文档看起来像这样:
{
kw_exact: "pink dress",
match_type: "exact",
adset_id: 1
},
{
kw_broad: "pink dress",
match_type: "broad",
adset_id: 1,
},
{
kw_negative: "red dress",
match_type: "negative",
adset_id: 1
}
我们想要的是获得每个广告集得分最高的关键字,如果一个否定的关键字获胜,则将其从结果中排除。
`/select
?group.field=adset_id
&group.limit=1
&sort=score desc
&group=true
&defType=edismax
&qf=kw_exact_test_bool2^6 kw_broad_test_bool2 kw_negative_test_bool2^7
&rows=200
&fl=adset_id,kw_broad,kw_exact,kw_negative,match_type
&q=dress
&fq=NOT match_type:2`
该策略不起作用,因为在分组之前应用RQ,并且如果否定关键字在广告集内具有最高得分,我们将不知道。以上面的例子为例:如果用户搜索红色连衣裙,则阴性和宽型将匹配,其中阴性具有较高分数,则上述查询将在结果中返回以下内容:
{
"groupValue": null,
"doclist": {
"numFound": 2,
"start": 0,
"maxScore": 18.0,
"numFoundExact": true,
"docs": [
{
"kw_broad": "pink dress",
"adset_id": 1,
"match_type": "broad"
}
]
}
}
同时我们不需要adset_id的值:1在这种情况下
我们还尝试了嵌套文档,但块和连接查询解析器有时似乎相当慢,我们读到solr实际上不支持嵌套文档,它们仍然被单独存储。我们也不能提出一个查询,将呈现我们想要的结果。
嵌套的docs模式看起来像这样:
{
adset_id: 1,
keywords: [
{
kw_exact: "pink dress",
match_type: "exact",
adset_id: 1
},
{
kw_broad: "pink dress",
match_type: "broad",
adset_id: 1,
},
{
kw_negative: "red dress",
match_type: "negative",
adset_id: 1
}]
}
我们愿意为这两种模式提供解决方案,有什么想法吗?
1条答案
按热度按时间8gsdolmq1#
我们通过使用各种查询解析器来解决它,最终查询看起来像这样:
选择?fl=kw_exact,kw_broad,kw_negative&cache=false&fq={!collapse field=adset_id max=cscore()}&q=-{!加入从=adset_id到=adset_id}{!df=kw_negative v=$qq} AND {!dismax qf=kw_broad qf=kw_exact^6 v=$qq}&qq=mySearchPhrase
虽然有一个限制,因为我们在kw_exact和kw_negative上有shingles,我们很快就会进入maxBooleanClauses错误。