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.
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
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