MDL-61102 core_search: Improve performance by reducing schema checks
[moodle.git] / search / upgrade.txt
CommitLineData
5f654ea2
DM
1This files describes API changes in /search/*,
2information provided here is intended especially for developers.
3
25564a78 4=== 3.5 ===
5
6* Search areas may now optionally implement the get_contexts_to_reindex function (for modules and
7 blocks, see also get_contexts_to_reindex_extra_sql). This allows a search area to customise the
8 order in which it is reindexed when doing a gradual reindex, so as to reindex the most important
65da6840 9 contexts first. If not implemented, the default behaviour for modules and blocks is to reindex
10 the newest items first; for other types of search area it will just index the whole system
11 context, oldest data first.
fc440796 12* Search engines may now implement get_supported_orders function to provide multiple ordering
13 options (other than 'relevance' which is default). If there is more than one order then a choice
14 will be shown to users. (This is an optional feature, existing search engine plugins do not need
15 to be modified in order to continue working.)
4359ef18 16* Module search areas that wish to support group filtering should set the new optional search
17 document field groupid (note: to remain compatible with earlier versions, do this inside an if
18 statement so that it only happens on 3.4+) and return true to the supports_group_restriction
19 function. See documentation in \core_search\base_mod class and example in \mod_forum\search\post.
4359ef18 20* When a search engine supports group filtering, the \core_search\manager::search function now
21 accepts the optional 'groupids' parameter in its $data input. This parameter is an array of one
22 or more group IDs. If supplied, only results from those groups will be returned.
4359ef18 23* Search engine plugins will need to be be modified if they wish to support group filtering.
24 (Search engines should continue to work unmodified, but will not then support group filtering.)
25 The modification steps are:
26 - Implement the new update_schema function to make the schema change (add groupid field).
27 - Ensure that the groupid field is stored correctly when provided in a document while indexing.
28 - Return true to new supports_group_filtering() function.
29 - execute_query should support the new $data->groupids parameter (to allow users to restrict
30 search results to specific groups) and the modified meaning of the second parameter,
31 $accessinfo (to automatically restrict search results users cannot access due to groups).
32 See implementation in Solr search engine.
73fd5666 33* Search engine plugins can optionally use a new $this->should_skip_schema_check() function to
34 decide when to skip slow schema checking inside the is_server_ready function, improving user
35 performance on the search page. The Solr plugin implements this.
36* API function \core_search\manager::instance() now includes a $fast parameter to skip schema
37 checks (as above).
4359ef18 38
67d64795 39=== 3.4 ===
40
41* Search indexing now supports time limits to make the scheduled task run more neatly. In order for
42 this to work, search engine plugins will need to implement the 'stopat' parameter if they
43 override the add_documents() function, and return an extra parameter from this function (see base
44 class in engine.php). Unmodified plugins will still work, but without supporting time limits.
427b7563 45* Search areas should now implement the get_document_recordset function instead of the old
46 get_recordset_by_timestamp API (implement both if the area should work in older Moodle versions
47 as well). The new function is the same as the old one, but has an additional context parameter.
48 There is a helper function get_context_restriction_sql to make this easy to implement; see code
49 in base_activity.php for an example of how to implement this in your search area. (The
50 change was required to make search work after restoring sites. It also allows more flexible
51 reindexing in other cases.)
67d64795 52
5f654ea2
DM
53=== 3.2 ===
54
55* Base search area classes have been renamed, please update your search areas to use the classes below:
56 - \core_search\area\base has been renamed to \core_search\base
57 - \core_search\area\base_mod has been renamed to \core_search\base_mod
58 - \core_search\area\base_activity has been renamed to \core_search\base_activity