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

柔情痞子 提交于 2019-12-29 08:35:13

问题


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.


回答1:


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



回答2:


When using the Unified Highlighter, hl.alternateField is not available as a query parameter. Instead you can use the hl.defaultSummary query parameter (available since Solr 4.5)

hl.defaultSummary
If true, use the leading portion of the text as a snippet if a proper highlighted snippet can’t otherwise be generated. The default is false.



来源:https://stackoverflow.com/questions/3452665/how-do-i-return-only-a-truncated-portion-of-a-field-in-solr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!