wikimedia/mediawiki-extensions-CirrusSearch

View on GitHub
includes/Search/CrossProjectBlockScorer.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace CirrusSearch\Search;

/**
 * Score an interwiki block
 */
abstract class CrossProjectBlockScorer {
    public function __construct( array $settings ) {
    }

    /**
     * Compute a score for a given bloack of crossproject searchresults
     * @param string $prefix
     * @param CirrusSearchResultSet $results
     * @return float the score for this block
     */
    abstract public function score( $prefix, CirrusSearchResultSet $results );

    /**
     * Reorder crossproject blocks using the $scorer
     * @param array $resultsets array of ResultSet or empty array if the search was disabled
     * @return array ResultSet reordered
     */
    public function reorder( array $resultsets ) {
        $sortKeys = [];
        foreach ( $resultsets as $pref => $results ) {
            if ( $results instanceof CirrusSearchResultSet ) {
                $sortKeys[] = $this->score( $pref, $results );
            } else {
                $sortKeys[] = -1.0;
            }
        }
        array_multisort( $sortKeys, SORT_DESC, $resultsets );
        return $resultsets;
    }
}