Lucene:如何在术语内进行通配符搜索?
我有以下 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的解决方案是将查询解析器的默认字段设为
level
,从而使您的查询简化为:但是,我怀疑这并不完全是您正在寻找的...
根据Lucene 查询解析器语法文档,您所要求的无法完成使用布尔运算符(
AND
和OR
)。 但是,看起来可以使用加号 (+
) 和减号 (-
) 运算符。 根据文档:这不完全是您想要的正在寻找,但可能合适。 我不确定如何以这种方式编写
OR
子句。The simplest solution would be to make
level
your query parser's default field, allowing your query to be reduced to: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
andOR
). However, it looks like it may be possible using the plus (+
) and minus (-
) operators. According to the documentation: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.