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?

Charles
  • 50,943
  • 13
  • 104
  • 142
Pavel Dubinin
  • 2,410
  • 1
  • 24
  • 28

3 Answers3

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());
derphil
  • 385
  • 6
  • 25
1

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

Calling it beforehand definitely works.

Robert Elwell
  • 6,598
  • 1
  • 28
  • 32
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))

Dewfy
  • 23,277
  • 13
  • 73
  • 121
  • 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 May 17 '10 at 06:45
  • @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 Jun 25 '10 at 13:31