I developed search page using SOLR with Tomcat servlet container. Using PHP code I post the search query into solrQuery() function and In this function have defined query parameter as follows.
$query = "?q=".trim(urlencode($q)) &version=2.2&start=0&rows=10&indent=on&hl=true&hl.fl=title";
I have passed highlighted "hl=true&hl.fl=title" parameters. I dont know about How to parse/display highlighted results in my search page?
can any one help me?
The way highlighting works in Solr is the following:
At the beggining of the XML response with the results, you see a "result" node with child "doc" nodes which contain your search results. Something like this:
At the end of the XML response with the resutls, you will see a "lst" node with the name "highlighting". You will notice that within each node, you'll see a child "lst" node with the name of the unique identifier that you've chosen for your document. Something like this:
The easiest way for me to do it is just to traverse the "results" node first and set my variables to the content of the search results as such. Then, within the loop to display each item, I loop through the "highlighted" node and search for the item's ID to see if I find a match. If a match is found, I will overwrite the content of the original variables with highlighted content.
This way, you will display results wether there is a highlighted match found or not.
Let me know what you think!