Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit 7e70e4e

Browse files
Improving search result by using score correction
Modified the code in order to allow Zend Search to return terms with null frequency in search results with their score correction.
1 parent c8de250 commit 7e70e4e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

library/ZendSearch/Lucene/Search/Query/MultiTerm.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ class MultiTerm extends AbstractQuery
8282
private $_weights = array();
8383

8484

85+
/**
86+
* Show terms with null frequency in the output.
87+
* integer
88+
*
89+
* @var int
90+
*/
91+
private $_allowTermsWithNullFreq = 1;
92+
93+
8594
/**
8695
* Class constructor. Create a new multi-term query object.
8796
*
@@ -457,9 +466,19 @@ public function _conjunctionScore($docId, Lucene\SearchIndexInterface $reader)
457466
* We don't need to check that term freq is not 0
458467
* Score calculation is performed only for matched docs
459468
*/
469+
/*
460470
$score += $reader->getSimilarity()->tf($this->_termsFreqs[$termId][$docId]) *
461471
$this->_weights[$termId]->getValue() *
462472
$reader->norm($docId, $term->field);
473+
*/
474+
if ($this->_allowTermsWithNullFreq == 0 || isset($this->_termsFreqs[$termId][$docId])) {
475+
$score += $reader->getSimilarity()->tf($this->_termsFreqs[$termId][$docId]) *
476+
$this->_weights[$termId]->getValue() *
477+
$reader->norm($docId, $term->field);
478+
} else {
479+
$score += $this->_weights[$termId]->getValue() *
480+
$reader->norm($docId, $term->field);
481+
}
463482
}
464483

465484
return $score * $this->_coord * $this->getBoost();

0 commit comments

Comments
 (0)