Lucene-查询字段中的多个术语 [英] Lucene - Querying multiple terms in a field

查看:93
本文介绍了Lucene-查询字段中的多个术语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为简单起见,请考虑两个具有以下字段和值的文档:

For simplicity sake, consider two documents with the following fields and values:

RecordId: "12345"
CreatedAt: "27/02/1992"
Event: "Manchester, Dubai, Paris"
Event: "Manchester, Rome, Madrid"
Event: "Madrid, Sidney"


RecordId: "99999"
CreatedAt: "27/02/1992"
Event: "Manchester, Barcelona, Rome"
Event: "Rome, Paris"
Event: "Milan, Barcelona"

是否可以在事件"字段的单个实例中搜索多个术语?

Is it possible to perform a search for multiple terms within a single instance of a "Event" field ?

让我们说我想搜索曼彻斯特"和巴黎"以出现在同一字段中. 第二条记录包含曼彻斯特"和巴黎",但是在事件"字段的不同实例上,这不应该是结果集的一部分.

Lets say I want to search for "Manchester" and "Paris" to appear in the same field. The second record contains "Manchester" and "Paris" but on different instances of the Event field, which is not supposed to be part of the resultset.

理想情况下,结果集将只是第一条记录(12345).

Ideally, the resultset would only be the first record (12345).

推荐答案

取决于您用于该字段的分析器(它需要标记化并删除标点符号).您可以使用草率短语查询.

Depending on the analyser you use for the field (it would need to tokenise and remove the punctuation). You could use a slop phrase query.

"manchester paris"〜2应该只能找到12345.根据每个字段中值的数量和顺序,您可能需要使用更大的斜率.

"manchester paris"~2 should find just 12345. Depending on the number and order of values in each field you may need to use a larger slop.

斜率定义了允许匹配的短语上的操作"数.这可以是重新排序,也可以是词组中的其他术语.

The slop defines the number of "operations" on the phrase allowable to match. This can be reordering or additional terms within the phrase.

所以"x y"〜1可以匹配

So "x y"~1 could match

  • "y x"
  • "x fred y"
  • 但不包括"y fred x"(这需要两个操作:沼泽加一个附加项)

为满足您的需要,斜率可能应等于字段中允许的最大术语数.我还没有解决,但是我认为即使您查询两个以上的词也足够了.

For your need the slop probably ought to be equal to the maximum number of terms allowed in a field. I haven't worked it through but I think that would suffice even if you query for more than 2 terms.

这篇关于Lucene-查询字段中的多个术语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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