php lucene索引,php – Lucene问题 – 搜索没有索引数值?

我在

PHP中使用Lucene(使用Zend Framework实现).我遇到一个问题,我无法搜索包含数字的字段.

这是索引中的数据:

ts | contents

--------------+-----------------

1236917100 | dog cat gerbil

1236630752 | cow pig goat

1235680249 | lion tiger bear

nonnumeric | bass goby trout

我的问题:查询“ts:1236630752”不会返回任何匹配.但是,对“ts:nonnumeric”的查询会返回命中.

我将“ts”存储为关键字字段,其中according to documentation“未标记,但已编入索引并存储.非常适用于非文本字段,例如日期或网址.”我曾尝试将其视为“文本”字段,但行为是相同的,只是当ts是文本时,对“ts:*”的查询不返回任何内容.

我正在使用Zend Framework 1.7(刚刚在3天前下载)和PHP 5.2.9.这是我的代码:

//=========================================================

// Initializes Zend Framework (Zend_Loader).

//=========================================================

set_include_path(realpath('../library') . PATH_SEPARATOR . get_include_path());

require_once('Zend/Loader.php');

Zend_Loader::registerAutoload();

//=========================================================

// Delete existing index and create a new one

//=========================================================

define('SEARCH_INDEX', 'test_search_index');

if(file_exists(SEARCH_INDEX))

foreach(scandir(SEARCH_INDEX) as $file)

if(!is_dir($file))

unlink(SEARCH_INDEX . "/$file");

$index = Zend_Search_Lucene::create(SEARCH_INDEX);

//=========================================================

// Create this data in index:

// ts | contents

// --------------+-----------------

// 1236917100 | dog cat gerbil

// 1236630752 | cow pig goat

// 1235680249 | lion tiger bear

// nonnumeric | bass goby trout

//=========================================================

function add_to_index($index, $ts, $contents) {

$doc = new Zend_Search_Lucene_Document();

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

$doc->addField(Zend_Search_Lucene_Field::Text('contents', $contents));

$index->addDocument($doc);

}

add_to_index($index, '1236917100', 'dog cat gerbil');

add_to_index($index, '1236630752', 'cow pig goat');

add_to_index($index, '1235680249', 'lion tiger bear');

add_to_index($index, 'nonnumeric', 'bass goby trout');

//=========================================================

// Run some test queries and output results

//=========================================================

echo '

';

function run_query($index, $query) {

echo "Running query: $query\n";

$hits = $index->find($query);

echo 'Got ' . count($hits) . " hits.\n";

foreach($hits as $hit)

echo " ts='$hit->ts', contents='$hit->contents'\n";

echo "\n";

}

run_query($index, 'pig'); //1 hit

run_query($index, 'ts:1236630752'); //0 hits

run_query($index, '1236630752'); //0 hits

run_query($index, 'ts:pig'); //0 hits

run_query($index, 'contents:pig'); //1 hits

run_query($index, 'ts:[1236630700 TO 1236630800]'); //0 hits (range query)

run_query($index, 'ts:*'); //4 hits if ts is keyword, 1 hit otherwise

run_query($index, 'nonnumeric'); //1 hits

run_query($index, 'ts:nonnumeric'); //1 hits

run_query($index, 'trout'); //1 hits

产量

Running query: pig

Got 1 hits.

ts='1236630752', contents='cow pig goat'

Running query: ts:1236630752

Got 0 hits.

Running query: 1236630752

Got 0 hits.

Running query: ts:pig

Got 0 hits.

Running query: contents:pig

Got 1 hits.

ts='1236630752', contents='cow pig goat'

Running query: ts:[1236630700 TO 1236630800]

Got 0 hits.

Running query: ts:*

Got 4 hits.

ts='1236917100', contents='dog cat gerbil'

ts='1236630752', contents='cow pig goat'

ts='1235680249', contents='lion tiger bear'

ts='nonnumeric', contents='bass goby trout'

Running query: nonnumeric

Got 1 hits.

ts='nonnumeric', contents='bass goby trout'

Running query: ts:nonnumeric

Got 1 hits.

ts='nonnumeric', contents='bass goby trout'

Running query: trout

Got 1 hits.

ts='nonnumeric', contents='bass goby trout'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值