Search engines support the sort parameter, it would be nice if we
could pass it to be rendered in the web ui. This avoids implementing
any ui, which can be done at a later time.
Bug: T195071
Change-Id: Id7bd35bd4259bb1f1f856933d279dbd6eddfa2e2
* @ingroup Search
*/
abstract class SearchEngine {
* @ingroup Search
*/
abstract class SearchEngine {
+ const DEFAULT_SORT = 'relevance';
+
/** @var string */
public $prefix = '';
/** @var string */
public $prefix = '';
/** @var bool */
protected $showSuggestion = true;
/** @var bool */
protected $showSuggestion = true;
- private $sort = 'relevance';
+ private $sort = self::DEFAULT_SORT;
/** @var array Feature values */
protected $features = [];
/** @var array Feature values */
protected $features = [];
/**
* Get the valid sort directions. All search engines support 'relevance' but others
/**
* 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() {
*
* @since 1.25
* @return string[] the valid sort directions for setSort
*/
public function getValidSorts() {
- return [ 'relevance' ];
+ return [ self::DEFAULT_SORT ];
+ /**
+ * @var string
+ */
+ protected $sort;
+
$this->setExtraParam( 'prefix', $this->mPrefix );
}
$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
$user = $this->getUser();
# Extract manually requested namespaces
$search->setFeatureData( 'rewrite', $this->runSuggestion );
$search->setLimitOffset( $this->limit, $this->offset );
$search->setNamespaces( $this->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 ] );
$search->prefix = $this->mPrefix;
Hooks::run( 'SpecialSearchSetupEngine', [ $this, $this->profile, $search ] );