You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Faire Mii <fa...@gmail.com> on 2009/12/19 21:20:19 UTC

get field values from solr and highlight text?

Ive got the following code.

     $params = array('defType' => 'dismax', 'qf' => 'threads.title  
posts.body tags.name', 'hl' => 'true');

     $results = $solr->search($query, $offset, $limit, $params);

So the keywords will be highlighted. What i dont know how to do is  
pulling the data out from $results. How do I get a documents field  
values and then show the body and hightlight it like google/SO search?  
Im using solr client php but i find it difficult to understand how to  
use it. There is so few example codes.

could someone guide me a little...

Re: get field values from solr and highlight text?

Posted by Shalin Shekhar Mangar <sh...@gmail.com>.
On Sun, Dec 20, 2009 at 1:50 AM, Faire Mii <fa...@gmail.com> wrote:

> Ive got the following code.
>
>    $params = array('defType' => 'dismax', 'qf' => 'threads.title posts.body
> tags.name', 'hl' => 'true');
>
>    $results = $solr->search($query, $offset, $limit, $params);
>
> So the keywords will be highlighted. What i dont know how to do is pulling
> the data out from $results. How do I get a documents field values and then
> show the body and hightlight it like google/SO search? Im using solr client
> php but i find it difficult to understand how to use it. There is so few
> example codes.
>

The highlighting response comes as a node separate from the main results but
items in both of them are presented in the same order. You'd need to match
the highlighting snippet with the current document either through the
uniqueKey or through position. So one way to do it would be to read the
snippets out of the response completely and put them in a map with the key
being the unique key and then for each document, lookup the unique key in
the map and print out the highlighted snippet. The other way would be to go
through the result set and highlighting response one item at a time.

-- 
Regards,
Shalin Shekhar Mangar.