1
votes

I'm new with Zend Framework 2 and ZendSearch Lucene. My database table has three columns with integers, the first one is for the id. In the second is the publish value (1 to 3), in the third is the category value (1 to 5). The Table looks like this:

|id|publish|category|
|1|1|1|
|2|1|2|
|3|1|3|
|4|2|3|
|5|2|4|

I tested this with the following queries:
"publish:1" Return the correct id's 1,2,3;
"publish:2" Return the correct id's 4,5;
"publish:3" Return the incorrect id's 1,2,3,4,5; The result should be empty.
"publish:1 AND category:1" Return the correct id 1;
"publish:1 AND category:3" Return the correct id 3;
"publish:1 AND category:4" Return the correct empty result;
"publish:1 AND category:5" Return the incorrect id's 1,2,3; The result should be empty.

When a number doesn't exist, the result is not empty, it contains all rows. Is there any option, that the result is empty when the number doesn't exist?

The default encoding is UTF-8: \ZendSearch\Lucene\Search\QueryParser::setDefaultEncoding('UTF-8'); \ZendSearch\Lucene\Analysis\Analyzer\Analyzer::setDefault(new \ZendSearch\Lucene\Analysis\Analyzer\Common\Utf8Num\CaseInsensitive());

The id is unindexed, publish and category are keywords.

1

1 Answers

1
votes

I think I found the answer.

When I build the query with the following code the query is "+(publish:1) +(category:1)" and this works.

$query = new \ZendSearch\Lucene\Search\Query\Boolean();

$termPublish = new \ZendSearch\Lucene\Index\Term(1, 'publish' );
$subqueryPublish = new \ZendSearch\Lucene\Search\Query\Term($termPublish);
$query->addSubquery($subqueryPublish, true); // required

$termCategory = new \ZendSearch\Lucene\Index\Term(1, 'category' );
$subqueryCategory = new \ZendSearch\Lucene\Search\Query\Term($termCategory);
$query->addSubquery($subqueryCategory, true); // required