Zend Lucene 中的通配符查询

发布于 2024-08-18 07:33:01 字数 485 浏览 6 评论 0原文

$index = Zend_Search_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;

}

这段代码执行成功后,需要打印auto。但数组 $hits 是空的。

这背后的原因是什么?

$index = Zend_Search_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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

和我恋爱吧 2024-08-25 07:33:01

晚了两年,但可能的原因是您的更改未提交到索引。添加文档后,需要调用commit方法使其可供搜索。

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.

橘虞初梦 2024-08-25 07:33:01

你可能不得不在这里迁就我,但是你是否尝试过将:替换

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

$query = new Zend_Search_Lucene_Search_Query_Wildcard($term);

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

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

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*');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文