Zend_Search_Lucene is bad with numbers

Posted on 2009-05-03
Last Modified: 2013-12-08
I have a small site I have built using Doctrine and the Zend Framework. the Lucene search within the Zend Framework works great for me, except when the search terms have numbers in them. It hits the max execution time every time. But if I search with just text, it returns immediately.

Any ideas on how I can extend the search to be as efficient with numbers as it is letters/words?
class Search {

    const INDEX_DIR = '../search/data/';

    private $_index;

    static public function createIndex() {

        Zend_Search_Lucene::create( realpath( self::INDEX_DIR ) );


    public function __construct() {

        try {

            $dir = realpath( self::INDEX_DIR );

            $this->_index = Zend_Search_Lucene::open( $dir );

            $analyzer = new Zend_Search_Lucene_Analysis_Analyzer_Common_Text_CaseInsensitive( );

            $analyzer->addFilter( new Search_PorterStemmerFilter( ) );

            Zend_Search_Lucene_Analysis_Analyzer::setDefault( $analyzer );

        } catch (Exception $e) {





    public function find( $query ) {

        return $this->_index->find( $query );





class SearchController extends Zend_Controller_Action {

      $term = $this->_getParam('q');

      $this->view->assign( 'term', ucwords( strtolower( $term ) ) );      


      $searcher = new Search( );

      if ( !empty( $term ) ) {


         $searchTerm = new SearchTerm( );

         $searchTerm->query = $term;

         if(array_key_exists('HTTP_REFERER', $_SERVER)) {

            $searchTerm->referrer = $_SERVER['HTTP_REFERER'];



         $term = str_ireplace(array('bar','club'), '', $term);

         $term = trim($term);

         //$term .= '~.5';


         Zend_Search_Lucene::setResultSetLimit( 15 );


         $results = $searcher->find( '*' . $term . '*' );


         $this->view->assign( 'results', $results );






Open in new window

Question by:hallikpapa
  • 2
  • 2
LVL 49

Expert Comment

ID: 24345609
How do numeric searches perform when you leave out the asterixes?

Author Comment

ID: 24365874
It seems to work better, but I need some sort of wildcard operation in there. Any suggestions?
LVL 49

Accepted Solution

Roonaan earned 500 total points
ID: 24365959
You mean adding wildcards for numbers, or is it ok to only use them for non-numeric terms?

Author Comment

ID: 24460607
I am going to just upgrade to the newest version and see if this resolves the problem.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Php pie charts 3 26
converting numbers with php 3 28
Preventing users manipulating URL strings 10 33
How do I remove all except the numbers?  PHP  Regex 3 3
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now