开发者

Wildcard Query in Zend Lucene

$index = Zend_Se开发者_StackOverflow中文版arch_Lucene::open("/data/my_index1");

$doc = new Zend_Search_Lucene_Document();

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

$index->addDocument($doc);

$term = new Zend_Search_Lucene_Index_Term('auto*');

$query = new Zend_Search_Lucene_Search_Query_Wildcard($term);

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

foreach ($hits as $hit){

    echo $hit->type;

}

After successful execution of this code, it needs to print auto. But array $hits is empty.

What is the reason behind this?


Two years late, but the likely reason is that your changes are not committed to the index. After the document has been added, you need to call commit method to make it available for searching.


You might have to humour me here, but have you tried replacing:

$term = new Zend_Search_Lucene_Index_Term('auto*');

$query = new Zend_Search_Lucene_Search_Query_Wildcard($term);

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

with

$hits  = $index->find('auto*');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜