Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 525
  • Last Modified:

Zend_Search_Lucene is bad with numbers

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) {
            self::createIndex();
            $this->__construct();
        }
    }
 
    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

0
hallikpapa
Asked:
hallikpapa
  • 2
  • 2
1 Solution
 
RoonaanCommented:
How do numeric searches perform when you leave out the asterixes?
0
 
hallikpapaAuthor Commented:
It seems to work better, but I need some sort of wildcard operation in there. Any suggestions?
0
 
RoonaanCommented:
You mean adding wildcards for numbers, or is it ok to only use them for non-numeric terms?
0
 
hallikpapaAuthor Commented:
I am going to just upgrade to the newest version and see if this resolves the problem.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now