ElasticSearch高亮显示之numOfFragment,fragmentSize,noMatchSize方法详解

引子

问题一:明明索引库中文档内容上千字,为什么ES搜索出来的结果字数总是那么少?

问题二:
我们索引库中的文档内容是非常多的,但是我们会发现搜索出来的结果仅仅只有一两百字,恰好这个结果里边有关键字,而不是文档内容从前往后截取了一二百字。
ES中为什么搜索出来的结果,高亮字段优先展示,而不是文档内容从前往后截取几百个字符串显示?

看完下边三个方法介绍你就明白了。

在我们高亮时使用了HighlightBuilder,创建的过程中,有三个默认值。
在这里插入图片描述

fragmentSize

高亮字段内容长度,去除html样式标签,统计字数,默认为100。

numOfFragment

高亮关键字数量,优先显示,当numOfFragment设置为0时,fragmentSize失效,会返回全部内容。默认为5。

实例测试:

为0时,内容全部显示出来。
为1时,显示正常,字段长度低。
为5时,显示正常,字段长度高。

问题:

有的同志发现自己es搜索出来的结果为什么不全,少了很多内容,比如文档本来只有80个字,按理说应该全部显示出来的,但是为什么没有显示出来?

解决:

因为numOfFragment这个方法,有的人建议你将参数设置为0,但是注意上边我写了,为0时,fragmentSize失效,全部内容返回,有问题的。
如果你非常了解这三个方法,那么怎么解决这个问题,一目了然,设置fragmentSize长度为200即可。

问题:

numOfFragment两个参数,好像有点关联,具体是怎么回事?

解决:

作用效果,numOfFragment>fragmentSize。
意思就是,如果你numOfFragment设置了5,fragmentSize设置了50,搜索结果绝对不止50个字。
但是在numOfFragment为5,时,fragmentSize设置200,300是可以的,控制长度是可以做到的。所以说这个fragmentSize这个方法还是有用的。

两个方法相辅相成,HightLightBuilder默认一个5一个100,是有一定道理的,具体业务上,你想怎么展示,自己测试,找一个比较合适的参数大小。

noMatchSize

两个字段参与高亮索引,一个字段匹配到了,另一个字段没有匹配到,那么显示多少文字呢,就是这个方法的作用。未匹配到情况下,字段长度。

实例:
我有两个索引字段,一个文件名,一个文件内容,文件名称匹配到了,文件内容没有匹配到,我给noMatchSize(50),传参50,文件内容就是50个字。

  • 6
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
dialog_fragment_layout 是一个自定义的布局文件,用于显示弹窗的内容。该布局文件可以包含一个 FrameLayout 控件,用来承载需要展示的 Fragment。同时,可以在布局文件中添加上方的两个居中 TextView 以及底部的确定和取消按钮。 以下是一个示例的 dialog_fragment_layout 布局文件: ```xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/title_text_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="18sp" android:textColor="@android:color/black" android:textAlignment="center"/> <TextView android:id="@+id/sub_title_text_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="14sp" android:textColor="@android:color/black" android:textAlignment="center"/> <FrameLayout android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="wrap_content"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/confirm_button" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="确定"/> <Button android:id="@+id/cancel_button" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="取消"/> </LinearLayout> </LinearLayout> ``` 在这个布局文件中,上方的两个居中 TextView 分别是 title_text_view 和 sub_title_text_view;底部的确定和取消按钮分别是 confirm_button 和 cancel_button;FrameLayout 控件是用来承载需要展示的 Fragment 的。注意,在实际使用中,需要根据具体的需求,对该布局文件进行适当的修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值