Zend_Search_Lucene 大量 - 类似于 ZF-5545 问题
编辑:
暂时通过黑客解决。 在第 473 行添加:
if (isset($this->_termsFreqs[$termId][$docId])) {
}
仅当我搜索多个单词时才会发生这种情况,例如:
+word1 +word2 + word3
我收到这个巨大的错误:
Notice: Undefined offset: 2 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Notice: Undefined offset: 2 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Notice: Undefined offset: 4 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Notice: Undefined offset: 4 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Notice: Undefined offset: 6 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Notice: Undefined offset: 6 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Notice: Undefined offset: 1 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Notice: Undefined offset: 1 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Notice: Undefined offset: 9 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Notice: Undefined offset: 9 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
有趣的是返回的结果集是正确的,因此在生产中我可以关闭错误报告并它会像魅力一样发挥作用,但我不想这样做。
此处记录了类似的问题: http://framework.zend.com/issues/browse/ ZF-5545
显然没有解决方案。
我还尝试过使用 UTF-8 兼容的文本分析器(尽管索引中只有 Latin 1 个字符):
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
EDIT:
Solved with a hack for now. Added at line 473:
if (isset($this->_termsFreqs[$termId][$docId])) {
}
This happens only when I'm searching for multiple words, e.g.:
+word1 +word2 + word3
I get this massive error:
Notice: Undefined offset: 2 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Notice: Undefined offset: 2 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Notice: Undefined offset: 4 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Notice: Undefined offset: 4 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Notice: Undefined offset: 6 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Notice: Undefined offset: 6 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Notice: Undefined offset: 1 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Notice: Undefined offset: 1 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Notice: Undefined offset: 9 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Notice: Undefined offset: 9 in C:\wamp\www\project\library\Zend\Search\Lucene\Search\Query\MultiTerm.php on line 473
Funny thing is that the result set that is returned is correct, so in production I could just turn off the error reporting and it would work like a charm but I don't want to do that.
Similar issue is documented here: http://framework.zend.com/issues/browse/ZF-5545
And apparently there is no solution.
I have also tried using UTF-8 compatible text analyzer (even though I have only Latin 1 characters in the index):
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须设置此条件来抑制警告:
if (array_key_exists($termId, $this->_termsFreqs) && array_key_exists($docId, $this->_termsFreqs[$termId])) { ...但
问题仍然存在,这是否有帮助。 可能存在逻辑错误导致此未定义的偏移量。
You have to put this condition to surpress the warning:
if (array_key_exists($termId, $this->_termsFreqs) && array_key_exists($docId, $this->_termsFreqs[$termId])) { ... }
But the question remains, if this is helpful. There might be a logical error causing this undefined offset.
未定义的偏移量仅意味着它正在尝试获取不存在的数组值。 解决方案只是首先检查 array_key_exists 以确保已设置密钥。 从错误中提到的文件源中,您需要在第 473 行附近添加此 if 条件(第二行和第六行是添加):
目前,因为 $this->_weights[$termId]-> getValue() 与其他值相乘,然后与 $score 相加,相乘的结果为 0,没有添加任何内容,因此结果正确。 添加 if 不会改变这一点,因为无论如何都不会添加任何内容。
Undefined offset just means that it is trying to get an array value that doesn't exist. The solution is just to check array_key_exists first to make sure the key is set. From the source for the file mentioned in the error, you'd need to add this if condition near line 473 (the second and sixth lines are the addition):
Presently, because $this->_weights[$termId]->getValue() is being multiplied by other values and then added to $score, the result of the multiplication is 0 and nothing gets added, thus the result comes out correctly. Adding the if will not change this as nothing will be added either way.