newbie newbie - 1 year ago 86
PHP Question

Combine a range query with a multi-term query in Zend Lucene

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?

Answer Source

Use a boolean query.

$query = new Zend_Search_Lucene_Search_Query_Boolean();
$rangeQuery = ...
$multiTermQuery = ...
$query->addSubquery($rangeQuery, true)
$query->addSubquery($multiTermQuery, true)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download