views:

325

answers:

1

Hi all,

I am having difficulty determining my misunderstanding of how Zend Search Lucene indexes and searches integers in ranges.

In the following example, I would expect the output to be 1, however it is always 2 (both results). Any hints would be much appreciated.

<?php

require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();

$search = Zend_Search_Lucene::create('test.index');

$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::Text('foo', 'Hello'));
$doc->addField(Zend_Search_Lucene_Field::Keyword('bar', 100));
$search->addDocument($doc);

$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::Text('foo', 'Hello'));
$doc->addField(Zend_Search_Lucene_Field::Keyword('bar', 200));
$search->addDocument($doc);
$search->commit();

var_dump(count($search->find('foo:Hello AND bar:[050 TO 150]')));
A: 

I would try changing the addField commands to:

$doc->addField(Zend_Search_Lucene_Field::Keyword('bar', '100'));

That is, use a string instead of an integer. If that does not work, maybe you should use the Zend_Search_Lucene_Field::Text type.

Yuval F