Lucene - 如何在查询中将多个单词 AND 而不是 OR 在一起
我正在使用 Zend Search Lucene,如果用户在搜索框中输入 Vibrant Bouquet,则会返回带有单词“Vibrant”或单词“bouquet”(或显然两者)的结果。我想要的只是用这两个词返回这些结果。
显然,我可以通过在单词之间键入 AND 来做到这一点,但据我所知,Lucene 会按原样在每个单词之间隐式放置 OR;是否可以更改此设置,以便它在每个单词之间隐式放置“AND”,以便搜索的默认行为是查找所有单词,而不仅仅是一个或多个单词?
我可以通过搜索词上的字符串替换来用 AND 替换空格来实现此目的,但这可能会导致阻止用户输入更复杂的查询。
I am using Zend Search Lucene and if the user types in Vibrant Bouquet into the search box, results with the word "Vibrant" or the word "bouquet" (or both obviously) are returned. What I want is only to return those results with both words.
Obviously I can do this by typing AND between the words, but as far as I can tell Lucene implicitly puts OR between each word as it is; is it possible to change this so that it implicitly puts AND between each word so that the default behaviour for searches is to find all words, not just one or more?
I could do this with a string replace on the search term to replace spaces with AND, but that could cause issues with stopping the user typing in more complex queries.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 google 上搜索了您的信息:
可以使用
Zend_Search_Lucene_Search_QueryParser::setDefaultOperator($operator)
和Zend_Search_Lucene_Search_QueryParser::getDefaultOperator()
方法设置或检索默认布尔运算符,分别。这些方法使用
Zend_Search_Lucene_Search_QueryParser::B_AND
和Zend_Search_Lucene_Search_QueryParser::B_OR
常量进行操作。http://framework.zend.com/manual/ en/zend.search.lucene.query-language.html
I've searched google for you :
The default boolean operator may be set or retrieved with the
Zend_Search_Lucene_Search_QueryParser::setDefaultOperator($operator)
andZend_Search_Lucene_Search_QueryParser::getDefaultOperator()
methods, respectively.These methods operate with the
Zend_Search_Lucene_Search_QueryParser::B_AND
andZend_Search_Lucene_Search_QueryParser::B_OR
constants.http://framework.zend.com/manual/en/zend.search.lucene.query-language.html
我尝试这个代码,这不起作用:
但是这个代码工作:
并且为了获得更大的灵活性:
结果例如:(
一些世界)zend搜索(一些世界)
zend搜索lucence
以获得更多的灵活性使用查询语言:
查询语言
I try this code and this not work:
but this code work:
and for more flexibility:
in result for example:
(some world)zend search(some world)
zend search lucence
for get more flexcibility use Query Language:
Query Language