MDL-60981 core_search: Add get_contexts_to_reindex API

This new API returns a list of contexts for each search area. This
allows the areas to be reindexed in a sensible order (roughly
speaking, newest first) and also allows this to be controlled by
each area.

An implementation in the forum module means that forums are ordered
by the date of the most recent discussion, so that active forums
will be reindexed early even if they were created a long time ago.
This commit is contained in:
sam marshall 2017-12-07 12:26:55 +00:00
parent 9993c1d02c
commit 25564a784b
9 changed files with 302 additions and 0 deletions

View file

@ -292,4 +292,17 @@ class post extends \core_search\base_mod {
}
return $this->discussionsdata[$discussionid];
}
/**
* Changes the context ordering so that the forums with most recent discussions are indexed
* first.
*
* @return string[] SQL join and ORDER BY
*/
protected function get_contexts_to_reindex_extra_sql() {
return [
'JOIN {forum_discussions} fd ON fd.course = cm.course AND fd.forum = cm.instance',
'MAX(fd.timemodified) DESC'
];
}
}