在查询中按单词顺序对文档进行排序
Sort documents by words order in query
你能告诉我如何根据查询中的单词顺序对 Solr 中的文档结果进行排序吗?
例如,如果我输入查询 2 个词 milk
和 chocolate
,我想要以相同顺序包含这些词的增强文档。
在我的查询中:
http://localhost:8983/solr/product/select?defType=edismax&fl=*%2C%20score&q.op=AND&q=chocolate+milk&qf=title_token%5E10
您可以看到我有查询 chocolate milk
并且该查询的结果是:
{
id: 3346664,
title: "Milk with chocolate",
_version_: 1648030883251224600,
score: 79.53341
},
{
id: 8754567,
title: "Chocolate of Milk",
_version_: 1648030883402219500,
score: 79.53341
},
{
id: 345428,
title: "Delicious Thins Milk Chocolate",
_version_: 1648030884582916000,
score: 74.86635
}
如您所见,我的前 2 个文档具有相同的 score
,但第一个文档的匹配词顺序与我查询中的词不同。你能告诉我如何提升匹配查询词顺序的文档吗?谢谢。
我的 title token 字段有这样的配置:
<fieldType name="text_token" class="solr.TextField">
<analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.WordDelimiterFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ASCIIFoldingFilterFactory" preserveOriginal="true"/>
<filter class="solr.TrimFilterFactory"/>
<filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.WordDelimiterFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ASCIIFoldingFilterFactory" preserveOriginal="true"/>
<filter class="solr.TrimFilterFactory"/>
<filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
</analyzer>
</fieldType>
您可以将 pf2
和 pf3
参数用于 edismax 查询解析器:
The pf2 Parameter
A multivalued list of fields with optional weights, based on pairs of word shingles.
The pf3 Parameter
A multivalued list of fields with optional weights, based on triplets of word shingles. Similar to pf, except that instead of building a phrase per field out of all the words in the input, it builds a set of phrases for each field out of each triplet of word shingles.
木瓦是两个词的组合,即“巧克力牛奶”。您还想添加停用词过滤器,以便从令牌流中删除 of
。
pf2=title^5
.. 将对查询中的单词依次出现的那些应用 5 倍的提升。
您还可以添加一个明确的 shingle 过滤器,它在您编制索引时组合标记集,然后对该字段应用提升。
你能告诉我如何根据查询中的单词顺序对 Solr 中的文档结果进行排序吗?
例如,如果我输入查询 2 个词 milk
和 chocolate
,我想要以相同顺序包含这些词的增强文档。
在我的查询中:
http://localhost:8983/solr/product/select?defType=edismax&fl=*%2C%20score&q.op=AND&q=chocolate+milk&qf=title_token%5E10
您可以看到我有查询 chocolate milk
并且该查询的结果是:
{
id: 3346664,
title: "Milk with chocolate",
_version_: 1648030883251224600,
score: 79.53341
},
{
id: 8754567,
title: "Chocolate of Milk",
_version_: 1648030883402219500,
score: 79.53341
},
{
id: 345428,
title: "Delicious Thins Milk Chocolate",
_version_: 1648030884582916000,
score: 74.86635
}
如您所见,我的前 2 个文档具有相同的 score
,但第一个文档的匹配词顺序与我查询中的词不同。你能告诉我如何提升匹配查询词顺序的文档吗?谢谢。
我的 title token 字段有这样的配置:
<fieldType name="text_token" class="solr.TextField">
<analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.WordDelimiterFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ASCIIFoldingFilterFactory" preserveOriginal="true"/>
<filter class="solr.TrimFilterFactory"/>
<filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.WordDelimiterFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ASCIIFoldingFilterFactory" preserveOriginal="true"/>
<filter class="solr.TrimFilterFactory"/>
<filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
</analyzer>
</fieldType>
您可以将 pf2
和 pf3
参数用于 edismax 查询解析器:
The pf2 Parameter
A multivalued list of fields with optional weights, based on pairs of word shingles.
The pf3 Parameter
A multivalued list of fields with optional weights, based on triplets of word shingles. Similar to pf, except that instead of building a phrase per field out of all the words in the input, it builds a set of phrases for each field out of each triplet of word shingles.
木瓦是两个词的组合,即“巧克力牛奶”。您还想添加停用词过滤器,以便从令牌流中删除 of
。
pf2=title^5
.. 将对查询中的单词依次出现的那些应用 5 倍的提升。
您还可以添加一个明确的 shingle 过滤器,它在您编制索引时组合标记集,然后对该字段应用提升。