views:

567

answers:

2

I have very simple company index with Zend Lucene using this to create the index:

// store company primary key to identify it in the search results
$doc->addField(Zend_Search_Lucene_Field::Keyword('pk', $this->getId()));

// index company fields
$doc->addField(Zend_Search_Lucene_Field::Unstored('zipcode', $this->getZipcode(), 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::Unstored('name', $this->getName(), 'utf-8'));

I can search on the company name but not the zipcode. Is there a problem with Zend Lucene Search indexing integers? If s/o could shed some light who was experience, please help me out. I can only imagine using Lucene to search by zipcode is pretty common.

A: 

I believe your problem is with the Analyzer. I suggest you use Zend_Search_Lucene_Field::Keyword, instead of Zend_Search_Lucene_Field::Unstored for the zip code field. This way, the Lucene analyzer will not modify the zip code while indexing. The Java Lucene has explain() which can be used to debug searches. You may have to print some interim values to simulate explain(), and see whether this is indeed the problem.

Yuval F
A: 

I believe the default text Analyzer for Zend Lucene does not search numbers by default. Zend comes packaged with several different text analyzers. Use the TextNum analyzer to search both numbers and characters. There are also a handful of other analyzers in the zend/search/lucene/analysis/analyzer/common folder that you may find useful.

You can change your default analyzer with the following code:

Zend_Search_Lucene_Analysis_Analyzer::setDefault(
    new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum());
justinl