One trick I use a lot with VwR is simply to do $object.class in a template, hit refresh and see what type of object it is. The consult javadocs/code to see how to navigate that object.

Highlighting support is something that I meant to put into the templates shipped, as it is something I've used in several custom prototypes.

Here's some tricks from one of my VM_global_library.vm files laying around:

#macro(field $f)$!{esc.html($doc.getFirstValue($f))}#end

#macro(field_with_highlighting $f)
  #if($response.highlighting.get($doc.getFieldValue('id')).get($f))
#foreach($fragment in $response.highlighting.get($doc.getFieldValue('id')).get($f))
      ...$fragment...
    #end
  #else
    #field($f)
  #end
#end

Then in your templates you can simply say #field_with_highlighting('title') (within a context where $doc is defined) and if there is highlighting it will show ...fragments... or the entire field value. Or #field('title') for simple unhighlighted single-valued fields. Note that the above also assumes that 'id' is the uniqueKey, though when I eventually get this incorporated into the main templates (patches welcome!) in contrib/velocity we can make it use the schema metadata to get the designated field dynamically.

Again, don't forget about the $object.class trick. $response.class, then see what that returns, then $response.highlighting.class, and so on until the object graph pieces you want are presented. Also, simply $object will dump the toString() of the object, which gives a lot of insight for many objects.

        Erik

On Jan 13, 2010, at 7:28 PM, Sascha Szott wrote:

Hi Qiuyan,

Thanks a lot. It works now. When i added the line
#set($hl = $response.highlighting)
i got the highlighting. But i wonder if there's any document that
describes the usage of that. I mean i didn't know the name of those
methods. Actually i just managed to guess it.
Solritas (aka VelocityResponseWriter) binds a number of objects into a so called VelocityContext (consult [1] for a complete list). You can think of
a map that allows you to access objects by symbolic names, e.g., an
instance of QueryResponse is stored under response (that's why you write
$response in your template).

Since $response is an instance of QueryResponse you can call all methods
on it the API [2] provides. Furthermore, Velocity incorporates a
JavaBean-like introspection mechanism that lets you write
$response.highlighting instead of $response.getHighlighting() (only a bit
of syntactic sugar).

-Sascha

[1] http://wiki.apache.org/solr/VelocityResponseWriter#line-93
[2]
http://lucene.apache.org/solr/api/org/apache/solr/client/solrj/response/QueryResponse.html

Quoting Sascha Szott <sz...@zib.de>:

Qiuyan,

with highlight can also be displayed in the web gui. I've added <bool name="hl">true</bool> into the standard responseHandler and it already works, i.e without velocity. But the same line doesn't take effect in
itas. Should i configure anything else? Thanks in advance.
First of all, just a few notes on the /itas request handler in your
solrconfig.xml:

1. The entry

<arr name="components">
 <str>highlight</str>
</arr>

is obsolete, since the highlighting component is a default search
component [1].

2. Note that since you didn't specify a value for hl.fl highlighting
will only affect the fields listed inside of qf.

3. Why did you override the default value of hl.fragmenter? In most
cases the default fragmenting algorithm (gap) works fine - and maybe
in yours as well?


To make sure all your hl related settings are correct, can you post
an xml output (change the wt parameter to xml) for a search with
highlighted results.

And finally, can you post the vtl code snippet that should produce
the highlighted output.

-Sascha

[1] http://wiki.apache.org/solr/SearchComponent













Reply via email to