PhpRiot
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

Fuzzy Query

Fuzzy queries can be used to search for documents containing strings matching terms similar to specified term.

Query string:

field1:test~

This query matches documents containing 'test' 'text' 'best' words and others.

or

Query construction by API:

<?php
$term 
= new Zend_Search_Lucene_Index_Term('test''field1');
$query = new Zend_Search_Lucene_Search_Query_Fuzzy($term);
$hits  $index->find($query);

Optional similarity can be specified after "~" sign.

Query string:

field1:test~0.4

or

Query construction by API:

<?php
$term 
= new Zend_Search_Lucene_Index_Term('test''field1');
$query = new Zend_Search_Lucene_Search_Query_Fuzzy($term0.4);
$hits  $index->find($query);

The term field is optional. Zend_Search_Lucene searches through all fields on each document if a field is not specified:

<?php
$term 
= new Zend_Search_Lucene_Index_Term('test');
$query = new Zend_Search_Lucene_Search_Query_Fuzzy($term);
$hits  $index->find($query);

Zend Framework