0

让我们说下面是我在 solr 中的文件

[{"url": "/buy/1/", "items": ["i_123", "i_1234", "i_12345", "i_12346"]},  {"url": "/buy/2/", "items": ["i_123", "i_1234", "i_12346"]}, {"url": "/buy/3/","items": ["i_123", "i_12346"]},  {"url": "/buy/4/","items": ["i_123", "i_234", "i_2345"]}]

我的查询是fq=items:(i_123 i_1234 i_12345)然后结果页面应该给与查询项目匹配的项目计数。

结果应该是一个额外的字段matching_items_count

[{"url": "/buy/1/""items": ["i_123", "i_1234", "i_12345", "i_12346"],"matching_items_count" : 3}, {"url": "/buy/2/","items": ["i_123", "i_1234", "i_1234444"],"matching_items_count" : 2}, {"url": "/buy/3/","items": ["i_123", "i_12346"],"matching_items_count" : 1}, { "url": "/buy/4/","items": ["i_123", "i_234", "i_2345"],"matching_items_count" : 1}]

4

1 回答 1

0

在这种情况下,您可以使用函数查询来获取计数。

在归档列表 (fl) 中,除了urlitems字段之外,您还可以编写 -

url,items,count:sum(termfreq(items,"i_123"),termfreq(items,"i_1234"),termfreq(items,"i_12345"))
于 2020-04-19T15:19:04.127 回答