2

I would like to add a lucene layer on my database model. Everything works fine and I use several keywords beside the main content which is filled by some HTML data.

e.g.

$doc = Zend_Search_Lucene_Document_Html::loadHTML($html);
$doc->addField(Zend_Search_Lucene_Field::keyword('author_id', 1));

I have an 1:N-table with some data I would like to use aswell for filtering the search result. Let's assume that the document is an article which can be published in different categories. I now have an array of category IDs which I somehow want to add to this document. My first approach was to just implode the array and save it as a string:

$doc->addField(Zend_Search_Lucene_Field::keyword('categories', '12, 15, 22'));

But it turned out to be a little complicated for search (searching for category 1 also returned 12 and 15). Then I created some "magical" strings such as CAT_12_A instead of 12 to make them unique:

$doc->addField(Zend_Search_Lucene_Field::keyword('categories', 'CAT_12_A, CAT_15_A, CAT_22_A'));

This works pretty fine but I am not totally happy with this solution because it is obviously a hack. Is there any chance to add a multi-value "keyword" to a Zend Lucene document without such a strange hack?

Thanks for helping.

Marc
  • 377
  • 7
  • 19
  • I got to this page having the same problem, having in mind exactly CAT_12_ solution, like yours ;) Have you found a better one? – takeshin Apr 05 '13 at 16:41

1 Answers1

1

I did a lot of googling after finding your question: looks like there is no way to directly add multi-valued fields without modifying zend framework core code.

Did you try

$doc->addField(Zend_Search_Lucene_Field::keyword('category_1', '12' ));
$doc->addField(Zend_Search_Lucene_Field::keyword('category_2', '15' ));
$doc->addField(Zend_Search_Lucene_Field::keyword('category_3', '22' ));

? Looks like query() will search across all fields, so if you don't care which field matches you should be fine?

Steve
  • 3,601
  • 4
  • 34
  • 41