ZF-10968: When using setResultLimit you get not top rated results

Description

Search with $index->setResultSetLimit(4); and without gives different results. Most top (and that right) result in full search does not list at all in limited resultset. Didn't actually test, but as i can see there is still that problem in repo. Problem located in Zend/Search/Lucene.php, sorting is later than fetching limit, so it gets not top hits, but random one.

{{ foreach ($query->matchedDocs() as $id => $num) { $docScore = $query->score($id, $this); if( $docScore != 0 ) { $hit = new Zend_Search_Lucene_Search_QueryHit($this); $hit->id = $id; $hit->score = $docScore;

    $hits[]   = $hit;
    $ids[]    = $id;
    $scores[] = $docScore;

    if ($docScore > $topScore) {
        $topScore = $docScore;
    }
}

// LIMIT IS HERE if (self::$_resultSetLimit != 0 && count($hits) >= self::$_resultSetLimit) { break; } }

if (count($hits) == 0) { // skip sorting, which may cause a error on empty index return array(); }

if ($topScore > 1) { foreach ($hits as $hit) { $hit->score /= $topScore; } } //SORTING IS HERE if (func_num_args() == 1) { // sort by scores array_multisort($scores, SORT_DESC, SORT_NUMERIC, $ids, SORT_ASC, SORT_NUMERIC, $hits); }}

Comments

No comments to display