views:

80

answers:

3

Using Zend Lucene I cannot search numbers in description fields

Added it like this:

$doc->addField(Zend_Search_Lucene_Field::Text('description', $current_item['item_short_description'], 'utf-8'));

Googling for this showed that applying following code should solve the problem, but it did not..:

Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());

any thougts?

A: 

I'm not sure about 'zend', but for deal with number in lucene, you need use following technique:

  • To place int to document use following:

    document.Add(new Field(FIELD_SPEC, NumberTools.LongToString(YOUR_INT), Field.Store.YES, Field.Index.UN_TOKENIZED));

  • To locate value use Term: Term(FIELD_SPEC, NumberTools.LongToString(YOUR_INT))

Dewfy
How do I use it for description? I want so that numbers inside description are searchable. I don't just have a "seprate integer".
Pavel Dubinin
@Pavel Dubinin - look at my note: "To locate value use Term:..." So when you need search you create this as part of BooleanQuery where Term is constructed using NumberTools. Little bit complicated if you use standard qury parser - in this case make preprocess by replacing all numbers in queries by value rendered NumberTools
Dewfy
A: 

Did you use that command before or after calling Zend_Search_Lucene::open()?

Calling it beforehand definitely works.

Robert Elwell
A: 

Could anyone please paste here working part of code searching for numbers as well as strings? I tried I believe everything and finally failed.

Lormitto