0

Let say below are my documents in 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"]}]

And my query is fq=items:(i_123 i_1234 i_12345) Then resultant pages should give the matching items count with queried items.

The result should be with one extra field 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}]

Raj
  • 313
  • 2
  • 9
  • See https://stackoverflow.com/questions/25038080/how-can-i-tell-solr-to-return-the-hit-search-terms-per-document for how to possibly solve this - there is still no automagic way of doing it as far as I know – MatsLindh Apr 16 '20 at 08:36

1 Answers1

0

In this case, you could use Function queries to get the count.

In the Filed list (fl), you could write, besides url and items field -

url,items,count:sum(termfreq(items,"i_123"),termfreq(items,"i_1234"),termfreq(items,"i_12345"))
atinjanki
  • 483
  • 3
  • 13