Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top