lucene-SpanNotQuery和SpanOrQuery交迭与全局跨度

本文详细介绍了如何使用Elasticsearch中的SpanQuery和SpanNotQuery进行匹配结果的排除与筛选,以及如何利用SpanOrQuery实现近似匹配查询。通过实例演示了如何构建并应用这些查询来获取特定条件下的文档。了解如何优化搜索结果以提高检索效率。

1、在匹配结果中排除相互交迭的跨度

SpanNotQuery构造函数的第一个参数表示要包含的跨度对象,第二个参数表示要排除的跨度对象。

1)

SpanNearQuery quick_fox=new SpanNearQuery(new SpanQuery[]{quick,fox},1,true);

dumpSpans查询时输出

the <quick brown fox> jumps over the lazy dog (0.18461232)

the <quick red fox> jumps over the sleep cat (0.18461232)

2)

SpanNotQuery quick_fox_dog=new SpanNotQuery(quick_fox,dog);

dumpSpans查询时输出

the <quick brown fox> jumps over the lazy dog (0.18461232)

the <quick red fox> jumps over the sleep cat (0.18461232)

3)只匹配了第一个文档,因为第二个文档包括red

SpanNotQuery no_quick_red_fox=new SpanNotQuery(quick_fox,red);

dumpSpans查询时输出

the <quick red fox> jumps over the sleep cat (0.18461232)

2、SpanOrQuery,在构造函数中对一个SpanQuery对象的集合进行封装

1)

SpanNearQuery qf_near_ld=new SpanNearQuery(new SpanQuery[]{quick_fox,lazy_dog},3,true);

dumpSpans查询时输出

the <quick brown fox jumps over the lazy dog> (0.38461232)

2)

SpanNearQuery qf_near_sc=new SpanNearQuery(new SpanQuery[]{quick_fox,sleep_cat},3,true);

dumpSpans查询时输出

the <quick red fox jumps over the sleep cat> (0.38461232)

3)查询这样一些文档,这些文档或者包括"quick fox" near "lazy dog"或者包括"quick fox" near "sleep cat"

dumpSpans查询时输出

the <quick brown fox jumps over the lazy dog> (0.38461232)

the <quick red fox jumps over the sleep cat> (0.38461232)

转载于:https://www.cnblogs.com/1130136248wlxk/p/5031089.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值