MDL-59434 core_search: Alternate result orders including by context

Implements a mechanism by which search engines can provide different
result orderings, and implements a 'by location' ordering within the
Solr search engine (available whenever the user starts their search
from within a course or activity).
This commit is contained in:
sam marshall 2017-11-23 10:55:07 +00:00
parent b63a3b04b1
commit fc440796e9
9 changed files with 211 additions and 0 deletions

View file

@ -543,4 +543,17 @@ abstract class engine {
public function supports_group_filtering() {
return false;
}
/**
* Obtain a list of results orders (and names for them) that are supported by this
* search engine in the given context.
*
* By default, engines sort by relevance only.
*
* @param \context $context Context that the user requested search from
* @return array Array from order name => display text
*/
public function get_supported_orders(\context $context) {
return ['relevance' => get_string('order_relevance', 'search')];
}
}

View file

@ -684,6 +684,8 @@ class manager {
* - q (query text)
* - courseids (optional list of course ids to restrict)
* - contextids (optional list of context ids to restrict)
* - context (Moodle context object for location user searched from)
* - order (optional ordering, one of the types supported by the search engine e.g. 'relevance')
*
* @param \stdClass $formdata Query input data (usually from search form)
* @param int $limit The maximum number of documents to return

View file

@ -55,6 +55,15 @@ class search extends \moodleform {
$mform->setDefault('searchwithin', '');
}
// If the search engine provides multiple ways to order results, show options.
if (!empty($this->_customdata['orderoptions']) &&
count($this->_customdata['orderoptions']) > 1) {
$mform->addElement('select', 'order', get_string('order', 'search'),
$this->_customdata['orderoptions']);
$mform->setDefault('order', 'relevance');
}
$mform->addElement('header', 'filtersection', get_string('filterheader', 'search'));
$mform->setExpanded('filtersection', false);