0

I'm trying to use Zend Lucene for matching a query phrase, but I want a fuzzy match.

At the moment, if I use PhraseQuery and search for "valentin rossi", (and in DB there is "valentino rossi") I have no results, because PhraseQuery searches for the string "valentin rossi" exactly, without fuzzy matching or similarity between words.

Please give me a hint where I have to look for a working solution. Thanks in advance!

user1487934
  • 11
  • 1
  • 1
  • 4
  • I am little confused you said that you use Zend Lucene and than said '..and in DB there is "valentino rossi"' - so, are you using DB or Zend Lucene ??? – tasmaniski Jun 29 '12 at 11:12

3 Answers3

2

Zend Lucene seems to support fuzzy searching. The docs are here.

You just need to do something like this:

$queryString = 'search terms here';
//add the '~' to make it fuzzy if there is a query string
$queryString = $queryString ? $queryString . '~' : $queryString;
$index = Zend_Search_Lucene::open('/path/to/index');
$results = $this->_index->find(queryString);
Rupert
  • 1,629
  • 11
  • 23
0

If you are using Zend Lucene you need to prepare text you want to search, so:

$texttosearch = 'valentin rossi';
$query = Zend_Search_Lucene_Search_QueryParser::parse($texttosearch);

//you can echo $query to see result
echo $query;

and so on ...

Look at this great book for Zend_Search_Lucene

tasmaniski
  • 4,767
  • 3
  • 33
  • 65
0

Lucene PhraseQuery does not support wildcard and fuzzy queries. I don't know much about Zend Lucene. In lucene, you can use ComplexPhraseQueryParser to perform phrase search with fuzzy or wildcards. It internally uses SpanQueries. If you can utilize ComplexPhraseQueryParser or SpanQueries with Zend you should be good.

ali
  • 88
  • 1