如何仅返回 SOLR 中字段的截断部分? [英] How do I return only a truncated portion of a field in SOLR?

查看:19
本文介绍了如何仅返回 SOLR 中字段的截断部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 SOLR 中有一个非常大(5000 多个字符)的文本字段,名为描述.到目前为止,它非常适合搜索和突出显示.如果我执行搜索并且没有突出显示的部分,那么我只显示前 300 个字符.我想要做的只是从 SOLR 返回结果中的 300 个字符.

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.

我想这样做是因为在测试时,如果返回较小的结果,我的性能会有所提高.这可能是因为 XML 文档更小,所以在线时间更少,然后处理速度更快,因为文档更小.

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.

我想过使用一个只存储前 300 个字符的新字段.我认为这会奏效,但我想知道是否有更好或更原生的解决方案.

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.

推荐答案

你要找的是高亮 hl.maxAlternateFieldLength (http://wiki.apache.org/solr/HighlightingParameters#hl.maxAlternateFieldLength).

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

您需要将该字段定义为其自己的备用字段.如果要突出显示字段Description,突出显示查询参数为:

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

最后,要从查询结果中省略Description 字段,您必须将其从fl 查询参数中排除:

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

这篇关于如何仅返回 SOLR 中字段的截断部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆