Zend 搜索 Lucene 匹配
好吧,假设我有一个搜索查询,它返回一些 Zend_Search_Lucene_Search_QueryHit 对象,其中包含与查询匹配的 Zend_Search_Lucene_Document 对象。 我有一个小问题,关于如何从与查询 str 匹配的文档中检索字段的名称以突出显示它? 我希望一切都清楚,并且解决起来不是那么明显:)... 多谢 亚历克斯
OK so let's say I have a search query giving me back some Zend_Search_Lucene_Search_QueryHit objects containing the Zend_Search_Lucene_Document object matching the query.
I have a small question about how to retrieve simply the name of the field from the document matching the query str in order to highlight it??
I hope everything's clear and not to obvious to resolve :)...
Thanks a lot
Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设“name”、“address”、“phone”是 Zend_Search_Lucene_Field::Text 类型的字段,并且您有一个名为“content”的 Zend_Search_Lucene_Field::Unstored 字段 这可以使用“strpos”轻松解决":
您的电话字段可能是 Zend_Search_Lucene_Field::keyword 或其他内容。如果这些前面的字段都没有突出显示,则意味着您在内容中找到了 $query 字符串,但该字符串未保存,因为它是 Zend_Search_Lucene_Field::Unstored 字段。然后你应该做的是将另一种类型的 Zend_Search_Lucene_Field::Text 字段添加到你的 $doc 中,并将其称为“摘录”,
并将其添加到你之前的“foreach”循环中
Assuming "name", "address", "phone" are your fields of type Zend_Search_Lucene_Field::Text and you have one single field Zend_Search_Lucene_Field::Unstored called "content" This could be easily solved using "strpos":
your phone field might be a Zend_Search_Lucene_Field::keyword or something else. if none of these previous fields was highlighted it means that you $query string was found in your content which is not saved because it's a Zend_Search_Lucene_Field::Unstored field. what you should do then is add another type Zend_Search_Lucene_Field::Text field to your $doc and call it "excerpt"
and add this to you previous "foreach" loop