I would like to dynamically show to the user which field matched the query that was sent to Solr. For example, if I had a document
document
field1: "yay"
field2: "nay"
dynamic_field_hurr_*:
one: "yay"
two: "nay"
and i queried for "yay", would it be possible for me to know that yay was found in field1 and dynamic_field_hurr_one?
I feel like I've been through the whole documentation, and thought I should use highlighting for this, but I can't get it to work on dynamic fields. On normal fields it works fine!
A little background: I'm using Solr.Net and in the class I map to my document I have a IDictionary<string, string>
to dynamically add additional information. After some reading up, I figured dictionaries mapped to dynamicfields, and it works perfectly, except for highlighting.
I also tried copying all data from my dynamic field into a text field, but I don't think there's a way to copy the "actual field name"? I can only get Solr to copy the value, which I guess makes sense.
Any ideas?
just for completeness, there is another way to get this info without using highlighting (highlighting imposes some conditions such as forcing stored fields)
There is an indirect way of doing this using a very interesting tool , hit highlighting.
Do this with default solr schema to understand solution:
http://localhost:8983/solr/collection1/select?q=iPod&wt=xml&indent=true&hl=on&hl.fl=name,description
Look at :
<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 the is the field that matched. You can choose to ignore rest of the actual highlighting part and use only the field names that matched for your purpose.
So you would ask for something like this in your case &hl=on&hl.fl=dynamic_field_hurr_one,dynamic_field_hurr_two
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With