max_score = $max_score; } /** * @since 3.0 * * @param string|integer $min_score */ public function min_score( $min_score ) { $this->min_score = $min_score; } /** * @note The hash is expected to match DIWikiPage::getHash to easily match * result subjects available in an QueryResult instance. * * @since 3.0 * * @param DIWikiPage|string $hash * @param string|integer $score */ public function addScore( $hash, $score, $pos = null ) { if ( $hash instanceof DIWikiPage ) { $hash = $hash->getHash(); } if ( $pos === null ) { $this->scores[] = [ $hash, $score ]; } else { $this->scores[$pos] = [ $hash, $score ]; } } /** * @since 3.0 * * @param DIWikiPage|string $hash * * @return string|integer|false */ public function getScore( $hash ) { if ( $hash instanceof DIWikiPage ) { $hash = $hash->getHash(); } foreach ( $this->scores as $map ) { if ( $map[0] === $hash ) { return $map[1]; } } return false; } /** * @since 3.0 * * @return [] */ public function getScores() { return $this->scores; } /** * @since 3.0 * * @param boolean $usort */ public function usort( $usort ) { if ( !$usort|| $this->scores === [] ) { return; } usort( $this->scores, function( $a, $b ) { if ( $a[1] == $b[1] ) { return 0; } return ( $a[1] > $b[1] ) ? -1 : 1; } ); } /** * @since 3.0 * * @param string $class * * @return string */ public function asTable( $class = '' ) { if ( $this->scores === [] ) { return ''; } $table = ""; $table .= ""; $table .= ""; ksort( $this->scores ); foreach ( $this->scores as $pos => $set ) { $table .= ''; } $table .= '
ScoreSubjectPos
' . $set[1] . '' . $set[0] . '' . $pos . '
'; return $table; } }