Lucene:如何在术语内进行通配符搜索?

发布于 2024-07-23 12:10:29 字数 430 浏览 3 评论 0原文

我有以下 lucene 索引:

Document A
item = level:(1)
item = level:(2)
item = level:(3)

Document B
item = level:(1)
item = level:(4)

假设我想搜索包含 level:(1) AND level:(2) 的所有文档?

Lucene 查询可能是这样的:

"item:level\:\(1\) AND level\:\(2\)"

但是否也可以执行这样的操作:

"item:level\:\(1 OR 2\)"

(这样做的原因是我不想重复字符串 "level\:"

I've the following lucene index:

Document A
item = level:(1)
item = level:(2)
item = level:(3)

Document B
item = level:(1)
item = level:(4)

Suppose I want to search for all documents which contain level:(1) AND level:(2) ?

The Lucene query could be like:

"item:level\:\(1\) AND level\:\(2\)"

but is it also possible to do something like this:

"item:level\:\(1 OR 2\)"

?

(The reason for this is that I don't want to repeat the string "level\:")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑忘罢 2024-07-30 12:10:29

最简单的解决方案是将查询解析器的默认字段设为 level ,从而使您的查询简化为:

(1 OR 2)

但是,我怀疑这并不完全是您正在寻找的...

根据Lucene 查询解析器语法文档,您所要求的无法完成使用布尔运算符(ANDOR)。 但是,看起来可以使用加号 (+) 和减号 (-) 运算符。 根据文档:

Lucene 支持使用括号将多个子句分组到单个字段。

要搜索同时包含单词“return”和短语“pink panther”的标题,请使用以下查询:

标题:(+return +“粉红豹”)

这不完全是您想要的正在寻找,但可能合适。 我不确定如何以这种方式编写 OR 子句。

The simplest solution would be to make level your query parser's default field, allowing your query to be reduced to:

(1 OR 2)

However, I suspect that this isn't exactly what you're looking for...

According to the Lucene query parser syntax documentation, what you're asking for cannot be done using the boolean operators (AND and OR). However, it looks like it may be possible using the plus (+) and minus (-) operators. According to the documentation:

Lucene supports using parentheses to group multiple clauses to a single field.

To search for a title that contains both the word "return" and the phrase "pink panther" use the query:

title:(+return +"pink panther")

This is not exactly what you're looking for, but it may be suitable. I am unsure as to how an OR clause would be written in this manner.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文