* @ingroup Search
*/
abstract class SearchEngine {
+ const DEFAULT_SORT = 'relevance';
+
/** @var string */
public $prefix = '';
/** @var bool */
protected $showSuggestion = true;
- private $sort = 'relevance';
+ private $sort = self::DEFAULT_SORT;
/** @var array Feature values */
protected $features = [];
/**
* Get the valid sort directions. All search engines support 'relevance' but others
- * might support more. The default in all implementations should be 'relevance.'
+ * might support more. The default in all implementations must be 'relevance.'
*
* @since 1.25
* @return string[] the valid sort directions for setSort
*/
public function getValidSorts() {
- return [ 'relevance' ];
+ return [ self::DEFAULT_SORT ];
}
/**
*/
protected $fulltext;
+ /**
+ * @var string
+ */
+ protected $sort;
+
/**
* @var bool
*/
$this->setExtraParam( 'prefix', $this->mPrefix );
}
+ $this->sort = $request->getVal( 'sort', SearchEngine::DEFAULT_SORT );
+ if ( $this->sort !== SearchEngine::DEFAULT_SORT ) {
+ $this->setExtraParam( 'sort', $this->sort );
+ }
+
$user = $this->getUser();
# Extract manually requested namespaces
$search->setFeatureData( 'rewrite', $this->runSuggestion );
$search->setLimitOffset( $this->limit, $this->offset );
$search->setNamespaces( $this->namespaces );
+ $search->setSort( $this->sort );
$search->prefix = $this->mPrefix;
Hooks::run( 'SpecialSearchSetupEngine', [ $this, $this->profile, $search ] );