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

Wildcards

Lucene supports single and multiple character wildcard searches within single terms (but not within phrase queries).

To perform a single character wildcard search use the "?" symbol.

To perform a multiple character wildcard search use the "*" symbol.

The single character wildcard search looks for string that match the term with the "?" replaced by any single character. For example, to search for "text" or "test" you can use the search:

te?t

Multiple character wildcard searches look for 0 or more characters when matching strings against terms. For example, to search for test, tests or tester, you can use the search:

test*

You can use "?", "*" or both at any place of the term:

*wr?t*

It searches for "write", "wrote", "written", "rewrite", "rewrote" and so on.

Starting from ZF 1.7.7 wildcard patterns need some non-wildcard prefix. Default prefix length is 3 (like in Java Lucene). So "*", "te?t", "*wr?t*" terms will cause an exception [14].

It can be altered using Zend_Search_Lucene_Search_Query_Wildcard::getMinPrefixLength() and Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength() methods.



[14] Please note, that it's not a Zend_Search_Lucene_Search_QueryParserException, but a Zend_Search_Lucene_Exception. It's thrown during query rewrite (execution) operation.

Zend Framework