简体   繁体   中英

Zend_Lucene: How to combine multiple terms?

I am searching in an index using two different approaches, one is working, one is not (but should be from reading the documentation). I am wondering what my mistake is.

Here is my first approach which works fine:

$query = '+language:EN +country:US';
$hits = $index->find($query);

I tried to do the same using Zend_Search_Lucene_Index_Term :

$query = new Zend_Search_Lucene_Search_Query_MultiTerm();
$query->addTerm(new Zend_Search_Lucene_Index_Term('EN', 'language'), true);
$query->addTerm(new Zend_Search_Lucene_Index_Term('US', 'country'), true);
$hits  = $index->find($query);

This won't create a result. Removing the true option converts the search into an OR search (country=US OR language=EN).

I based the creation of the second approach on the documentation found at http://framework.zend.com/manual/1.12/de/zend.search.lucene.query-api.html

I found the solution by not using any UPPERCASE characters in the search.

Searching for lowercase characters, even if the data fields are uppercase, solved it.

Example code that worked:

$query = new Zend_Search_Lucene_Search_Query_MultiTerm();
$query->addTerm(new Zend_Search_Lucene_Index_Term('en', 'language'), true);
$query->addTerm(new Zend_Search_Lucene_Index_Term('us', 'country'), true);
$hits  = $index->find($query);

The data fields have the values "EN" and "US" and have been indexed as such and the document output confirms this but the search requires a lower case input for some reason.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM