Is it possible to get the name (s) of the fields that match the query in Solr?

I would like to dynamically show the user which field matched the request sent to Solr. For example, if I had a document

document field1: "yay" field2: "nay" dynamic_field_hurr_*: one: "yay" two: "nay" 

and I asked "yay", is it possible for me to know that yay is found in field1 and dynamic_field_hurr_one?

It seems to me that I went through all the documentation, and thought that I should use the highlight for this, but I can not get it to work with dynamic fields. In normal fields, this is normal!

Small background: I use Solr.Net, and in the class I have for my document I have IDictionary<string, string> to dynamically add additional information. After some reading, I understood the dictionaries mapped to dynamic fields, and it works fine except for highlighting.

I also tried copying all the data from my dynamic field to a text field, but I donโ€™t think there is a way to copy the โ€œactual field nameโ€? I can only get Solr to copy the value, which I think makes sense.

Any ideas?

+6
source share
2 answers

There is an indirect way to do this using a very interesting highlight tool.

Do this using the default solr scheme to understand the solution:

 http://localhost:8983/solr/collection1/select?q=iPod&wt=xml&indent=true&hl=on&hl.fl=name,description 

Take a look:

 <lst name="highlighting"> <lst name="IW-02"> <arr name="name"> <str><em>iPod</em> & <em>iPod</em> Mini USB 2.0 Cable</str> </arr> </lst> <lst name="F8V7067-APL-KIT"> <arr name="name"> <str>Belkin Mobile Power Cord for <em>iPod</em> w/ Dock</str> </arr> </lst> <lst name="MA147LL/A"> <arr name="name"> <str> Apple 60 GB <em>iPod</em> with Video Playback Black </str> </arr> </lst> </lst> 

So here you have a field that matches. You can ignore the rest of the actual highlight and use only the field names that match your purpose.

So you ask for something similar in your case &hl=on&hl.fl=dynamic_field_hurr_one,dynamic_field_hurr_two

+7
source

just for completeness, there is another way to get this information without using the backlight (the selection imposes some conditions, such as forcing the saved fields to be saved)

  • add debugQuery = true to your query
  • get / response / debug / explain info
  • analyze it to find out in which field it maps. Using debug.explain.structured = true changes the format of the element, it may be easier to parse
+2
source

Source: https://habr.com/ru/post/958957/


All Articles