[英]Solr search : count of matching multivalued field with search query
假設下面是我在 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}]
在這種情況下,您可以使用 Function 查詢來獲取計數。
在歸檔列表 (fl) 中,除了url和項目字段之外,您還可以編寫 -
url,items,count:sum(termfreq(items,"i_123"),termfreq(items,"i_1234"),termfreq(items,"i_12345"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.