2
votes

I'm using Zend Lucene and wondering if it is possible to combine a range query with a multi-term query to perform a single search operation.

For example you construct a range query like the below:

$from = new Zend_Search_Lucene_Index_Term('20020101', 'mod_date');
$range = new Zend_Search_Lucene_Search_Query_Range(
             $from, null, true // inclusive
         );

and then construct a multi-term query like this:

//this example uses only 1 term but the real use case has many terms forming the multiterm
$multi_term = Zend_Search_Lucene_Search_Query_MultiTerm(new Zend_Search_Lucene_Index_Term('foo','title'));

Then somehow,

$combined = combine($range,$multi_term);
$hits  = $index->find($combined);

Is something like that possible with Zend Lucene?

2

2 Answers

4
votes

Use a boolean query.

$query = new Zend_Search_Lucene_Search_Query_Boolean();
$rangeQuery = ...
$multiTermQuery = ...
$query->addSubquery($rangeQuery, true)
$query->addSubquery($multiTermQuery, true)
0
votes

A less programatical way but just as valid (and this relates to current ZendSearch) is to build the query string dynamically rather than in code.

For example:

+mod_date:[20020101 TO 20030101] +foo:bar

Pass that to the query function and that allows it. From my perspective the issue was fuzzy queries and keywords in the same query. In code it wasn't possible but can be done with query strings.