Zend搜索Lucene数值范围搜索

时间:2009-11-19 00:50:11

标签: php zend-framework lucene

我很难确定我对Zend Search Lucene索引和搜索范围内整数的误解。

在下面的例子中,我希望输出为1,但它总是2(两个结果)。任何提示都会非常感激。

<?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]')));

1 个答案:

答案 0 :(得分:0)

我会尝试将addField命令更改为:

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

也就是说,使用字符串而不是整数。如果这不起作用,也许您应该使用Zend_Search_Lucene_Field::Text类型。