Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I return only a truncated portion of a field in SOLR?

Tags:

solr

I have a really large (5000+ characters) text field in SOLR named Description. So far it works great for searching and highlighting. If I perform a search and there are no highlighted portions then I just show the first 300 characters. What I would like to do is just return the 300 characters in the result from SOLR.

I would like to do this because when testing I get improved performance if I return a smaller result. This is probably because the XML doc is smaller so less time on the wire and then the processing is faster because the doc is smaller.

I have thought of using a new field that just stored the first 300 characters. I think this would work, but I was wondering if there was a better or more native solution.

like image 875
Aaron D Avatar asked Aug 10 '10 19:08

Aaron D


1 Answers

What you're looking for is the highlighting hl.maxAlternateFieldLength (http://wiki.apache.org/solr/HighlightingParameters#hl.maxAlternateFieldLength).

You will need to define the field as its own alternate field. If you want to highlight the field Description, the highlight query parameters would be:

hl=true
hl.fl=Description
f.Description.hl.alternateField=Description
hl.maxAlternateFieldLength=300

Finally, to omit the Description field from the query result, you will have to exclude it from the fl query parameter:

fl=score,url,title,date,othermetadata
like image 70
Karl Johansson Avatar answered Sep 28 '22 00:09

Karl Johansson