开发者

Lucene - how to make multiple words within query AND instead of OR together

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 Luc开发者_运维百科ene 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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜