Lucene - 如何在查询中将多个单词 AND 而不是 OR 在一起

发布于 2024-09-14 12:52:18 字数 308 浏览 12 评论 0原文

我正在使用 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 技术交流群。

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

发布评论

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

评论(2

毁虫ゝ 2024-09-21 12:52:18

我在 google 上搜索了您的信息:

可以使用 Zend_Search_Lucene_Search_QueryParser::setDefaultOperator($operator)Zend_Search_Lucene_Search_QueryParser::getDefaultOperator() 方法设置或检索默认布尔运算符,分别。

这些方法使用 Zend_Search_Lucene_Search_QueryParser::B_ANDZend_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) and Zend_Search_Lucene_Search_QueryParser::getDefaultOperator() methods, respectively.

These methods operate with the Zend_Search_Lucene_Search_QueryParser::B_AND and Zend_Search_Lucene_Search_QueryParser::B_OR constants.

http://framework.zend.com/manual/en/zend.search.lucene.query-language.html

亢潮 2024-09-21 12:52:18

我尝试这个代码,这不起作用:

Zend_Search_Lucene_Search_QueryParser::setDefaultOperator('AND');

但是这个代码工作:

Zend_Search_Lucene_Search_QueryParser::setDefaultOperator(Zend_Search_Lucene_Search_QueryParser::B_AND);

并且为了获得更大的灵活性:

$term='zand search';

Zend_Search_Lucene_Search_QueryParser::setDefaultOperator(Zend_Search_Lucene_Search_QueryParser::B_AND);

$query = Zend_Search_Lucene_Search_QueryParser::parse($term."*",'UTF-8');


$results = $index->find($query );

结果例如:(

一些世界)zend搜索(一些世界)

zend搜索lucence

以获得更多的灵活性使用查询语言:

查询语言

I try this code and this not work:

Zend_Search_Lucene_Search_QueryParser::setDefaultOperator('AND');

but this code work:

Zend_Search_Lucene_Search_QueryParser::setDefaultOperator(Zend_Search_Lucene_Search_QueryParser::B_AND);

and for more flexibility:

$term='zand search';

Zend_Search_Lucene_Search_QueryParser::setDefaultOperator(Zend_Search_Lucene_Search_QueryParser::B_AND);

$query = Zend_Search_Lucene_Search_QueryParser::parse($term."*",'UTF-8');


$results = $index->find($query );

in result for example:

(some world)zend search(some world)

zend search lucence

for get more flexcibility use Query Language:

Query Language

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