views:

212

answers:

2

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());
+1  A: 

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):

foreach ($this->_terms as $termId => $term) {
     if (array_key_exists($termId,$this->_weights)) {
         $score += $reader->getSimilarity()->tf($this->_termsFreqs[$termId][$docId]) *
                   $this->_weights[$termId]->getValue() *
                   $reader->norm($docId, $term->field);
     }
}

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.

Cahlroisse
I have done that and I still get errors.
Richard Knop
It seems like the $docId is not defined.
Richard Knop
Cahlroisse
+1  A: 

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.

Sebastian Knuell