Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Multi-Term Query

Multi-term queries can be used for searching with a set of terms.

Each term in a set can be defined as required, prohibited, or neither.

  • required means that documents not matching this term will not match the query;

  • prohibited means that documents matching this term will not match the query;

  • neither, in which case matched documents are neither prohibited from, nor required to, match the term. A document must match at least 1 term, however, to match the query.

If optional terms are added to a query with required terms, both queries will have the same result set but the optional terms may affect the score of the matched documents.

Both search methods can be used for multi-term queries.

Query string:

+word1 author:word2 -word3
  • '+' is used to define a required term.

  • '-' is used to define a prohibited term.

  • 'field:' prefix is used to indicate a document field for a search. If it's omitted, then all fields are searched.


Query construction by API:

= new Zend_Search_Lucene_Search_Query_MultiTerm();

$query->addTerm(new Zend_Search_Lucene_Index_Term('word1'), true);
$query->addTerm(new Zend_Search_Lucene_Index_Term('word2''author'),
$query->addTerm(new Zend_Search_Lucene_Index_Term('word3'), false);

$hits  $index->find($query);

It's also possible to specify terms list within MultiTerm query constructor:

= array(new Zend_Search_Lucene_Index_Term('word1'),
$signs = array(truenullfalse);

$query = new Zend_Search_Lucene_Search_Query_MultiTerm($terms$signs);

$hits  $index->find($query);

The $signs array contains information about the term type:

  • TRUE is used to define required term.

  • FALSE is used to define prohibited term.

  • NULL is used to define a term that is neither required nor prohibited.

Zend Framework