Zend Lucene - cannot search numbers
Asked Answered
B

3

6

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?

Ballistics answered 16/5, 2010 at 8:13 Comment(0)
D
8

You have to set the default analyzer twice: On the indexing process as well as on the searching process.

Use the code line from above:

Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
Donnydonnybrook answered 16/2, 2011 at 7:46 Comment(0)
E
1

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

Calling it beforehand definitely works.

Enamour answered 23/6, 2010 at 21:57 Comment(0)
K
0

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))

Kochi answered 16/5, 2010 at 8:23 Comment(2)
How do I use it for description? I want so that numbers inside description are searchable. I don't just have a "seprate integer".Ballistics
@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 NumberToolsKochi

© 2022 - 2024 — McMap. All rights reserved.