使用 Zend Lucene 对范围查询进行排序
根据 文档,Zend Lucene 应该按字典顺序排序。我发现情况并非如此。如果我有一个查询“avg:[050 TO 300]”,是的,它将返回该范围内的所有值,但它会根据文档 ID 对它们进行排序,而不是值。
我发现 find() 函数可以接受其他参数,允许我按特定列进行排序(例如 $hits = $index->find($query, 'avg', SORT_NUMERIC, SORT_ASC);< /代码>)。但是,我正在动态创建 $query 并且不想按“avg”对每个搜索进行排序。
当我进行范围搜索时,如何强制 Lucene 按字典顺序自动对结果进行排序?如果这是不可能的,如何动态地将排序字段添加到查找函数中?
According to the documentation, Zend Lucene is supposed to sort lexicographically. I am finding this is not the case. If I have a query 'avg:[050 TO 300]', yes it will return all values in that range, but it will sort them according to the document id, not the value.
I have found that the find() function can accept additional parameters, allowing me to sort by a specific column (eg $hits = $index->find($query, 'avg', SORT_NUMERIC, SORT_ASC);
). However, I am creating $query dynamically and do not want to sort every search by 'avg'.
How do I force Lucene to sort the results automatically, lexicographically, when I do a range search? And if that's not possible, how do I dynamically add a sort field to the find function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从
$index->find(...)
得到结果后为什么不自己对$hits
进行排序呢?好吧,这看起来像是一种解决方法,对于非常大的结果集来说会很耗时,但我想这是大多数情况下最简单的方法。Why don't you sort
$hits
by yourself after getting the result from$index->find(...)
? Ok this looks like a workaround and will be time-consuming for very large resultsets, but I guess that this is the easiest way in most cases.