PhpRiot
Follow phpriot on Twitter
Sponsored Link
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
Free iPad/iPhone App
Available on the App Store

  • PHP manual
  • Zend Framework manual
  • Smarty manual
  • PHP articles
  • PHP training

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