|
| __construct () |
| Initialises the search engine configuration. More...
|
|
| add_document ($document, $fileindexing=false) |
| Adds a document to the search engine. More...
|
|
| add_documents ($iterator, $searcharea, $options) |
| Loop through given iterator of search documents and and have the search engine back end add them to the index. More...
|
|
| area_index_complete ($searcharea, $numdocs=0, $fullindex=false) |
| Do any area cleanup needed, and do anything to confirm contents. More...
|
|
| area_index_starting ($searcharea, $fullindex=false) |
| Do anything that may need to be done before an area is indexed. More...
|
|
| check_latest_schema () |
| Checks that the schema is the latest version. More...
|
|
| clear_query_error () |
| Clears the current query error value. More...
|
|
| delete ($areaid=null) |
| Delete all documents. More...
|
|
| delete_index_for_context (int $oldcontextid) |
| Deletes information related to a specific context id. More...
|
|
| delete_index_for_course (int $oldcourseid) |
| Deletes information related to a specific course id. More...
|
|
| execute_query ($filters, $accessinfo, $limit=0) |
| Executes the query on the engine. More...
|
|
| file_indexing_enabled () |
| Return true if file indexing is supported and enabled. More...
|
|
| get_document_classname () |
| Gets the document class used by this search engine. More...
|
|
| get_plugin_name () |
| Returns the plugin name. More...
|
|
| get_query_error () |
| Returns any error reported by the search engine when executing the provided query. More...
|
|
| get_query_total_count () |
| Returns the total number of documents available for the most recent call to execute_query. More...
|
|
| get_supported_orders (\context $context) |
| Obtain a list of results orders (and names for them) that are supported by this search engine in the given context. More...
|
|
| get_user ($userid) |
| Returns user data checking the internal static cache. More...
|
|
| index_complete ($numdocs=0, $fullindex=false) |
| Run any post indexing operations. More...
|
|
| index_starting ($fullindex=false) |
| Run any pre-indexing operations. More...
|
|
| is_installed () |
| Does the system satisfy all the requirements. More...
|
|
| is_server_ready () |
| Is the server ready to use? More...
|
|
| optimize () |
| Optimizes the search engine. More...
|
|
| record_applied_schema_version ($version) |
| Usually called by the engine; marks that the schema has been updated. More...
|
|
| skip_schema_check ($skip=true) |
| Tells the search engine to skip any time-consuming checks that it might do as part of the is_server_ready function, and only carry out a basic check that it can contact the server. More...
|
|
| supports_group_filtering () |
| Checks if this search engine supports groups. More...
|
|
| supports_users () |
| Checks if the search engine supports searching by user. More...
|
|
Base class for search engines.
All search engines must extend this class.
- Copyright
- 2015 Daniel Neis
- License
- http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
core_search\engine::delete_index_for_context |
( |
int |
$oldcontextid | ) |
|
Deletes information related to a specific context id.
This should be used when the context itself is deleted from Moodle.
This only deletes information for the specified context - not for any child contexts.
This function is optional; if not supported it will return false and the information will not be deleted from the search index.
If an engine implements this function it should also implement delete_index_for_course; otherwise, nothing will be deleted when users delete an entire course at once.
- Parameters
-
int | $oldcontextid | ID of context that has been deleted |
- Return values
-
- Exceptions
-
Reimplemented in search_solr\engine, and search_simpledb\engine.
core_search\engine::delete_index_for_course |
( |
int |
$oldcourseid | ) |
|
Deletes information related to a specific course id.
This should be used when the course itself is deleted from Moodle.
This deletes all information relating to that course from the index, including all child contexts.
This function is optional; if not supported it will return false and the information will not be deleted from the search index.
If an engine implements this function then, ideally, it should also implement delete_index_for_context so that deletion of single activities/blocks also works.
- Parameters
-
int | $oldcourseid | ID of course that has been deleted |
- Return values
-
- Exceptions
-
Reimplemented in search_solr\engine, and search_simpledb\engine.
core_search\engine::execute_query |
( |
|
$filters, |
|
|
|
$accessinfo, |
|
|
|
$limit = 0 |
|
) |
| |
|
abstract |
Executes the query on the engine.
Implementations of this function should check user context array to limit the results to contexts where the user have access. They should also limit the owneruserid field to manger::NO_OWNER_ID or the current user's id. Engines must use area->check_access() to confirm user access.
Engines should reasonably attempt to fill up to limit with valid results if they are available.
The $filters object may include the following fields (optional except q):
- q: value of main search field; results should include this text
- title: if included, title must match this search
- areaids: array of search area id strings (only these areas will be searched)
- courseids: array of course ids (only these courses will be searched)
- groupids: array of group ids (only results specifically from these groupids will be searched) - this option will be ignored if the search engine doesn't support groups
The $accessinfo parameter has two different values (for historical compatibility). If the engine returns false to supports_group_filtering then it is an array of user contexts, or true if the user can access all contexts. (This parameter used to be called $usercontexts.) If the engine returns true to supports_group_filtering then it will be an object containing these fields:
- everything (true if admin is searching with no restrictions)
- usercontexts (same as above)
- separategroupscontexts (array of context ids where separate groups are used)
- visiblegroupscontextsareas (array of subset of those where some areas use visible groups)
- usergroups (array of relevant group ids that user belongs to)
The engine should apply group restrictions to those contexts listed in the 'separategroupscontexts' array. In these contexts, it shouled only include results if the groupid is not set, or if the groupid matches one of the values in USER_GROUPS array, or if the search area is one of those listed in 'visiblegroupscontextsareas' for that context.
- Parameters
-
stdClass | $filters | Query and filters to apply. |
stdClass | $accessinfo | Information about the contexts the user can access |
int | $limit | The maximum number of results to return. If empty, limit to manager::MAX_RESULTS. |
- Return values
-
Reimplemented in search_simpledb\engine, and search_solr\engine.
core_search\engine::get_document_classname |
( |
| ) |
|
Gets the document class used by this search engine.
Search engines can overwrite core_search\document with search_ENGINENAME\document class.
Looks for a document class in the current search engine namespace, falling back to core_search\document.
Publicly available because search areas do not have access to the engine details, core_search\document_factory accesses this function.
- Return values
-
core_search\engine::get_query_total_count |
( |
| ) |
|
|
abstract |
Returns the total number of documents available for the most recent call to execute_query.
This can be an estimate, but should get more accurate the higher the limited passed to execute_query is. To do that, the engine can use (actual result returned count + count of unchecked documents), or (total possible docs - docs that have been checked and rejected).
Engine can limit to manager::MAX_RESULTS if there is cost to determining more. If this cannot be computed in a reasonable way, manager::MAX_RESULTS may be returned.
- Return values
-
Reimplemented in search_solr\engine, and search_simpledb\engine.
core_search\engine::is_server_ready |
( |
| ) |
|
|
abstract |
Is the server ready to use?
This should also check that the search engine configuration is ok.
If the function $this->should_skip_schema_check() returns true, then this function may leave out time-consuming checks that the schema is valid. (This allows for improved performance on critical pages such as the main search form.)
- Return values
-
true|string | Returns true if all good or an error string. |
Reimplemented in search_solr\engine, and search_simpledb\engine.
core_search\engine::supports_group_filtering |
( |
| ) |
|
Checks if this search engine supports groups.
Note that returning true to this function causes the parameters to execute_query to be passed differently!
In order to implement groups and return true to this function, the search engine should:
- Handle the fields ->separategroupscontexts and ->usergroups in the $accessinfo parameter to execute_query (ideally, using these to automatically restrict search results).
- Support the optional groupids parameter in the $filter parameter for execute_query to restrict results to only those where the stored groupid matches the given value.
- Return values
-
bool | True if this engine supports searching by group id field |
Reimplemented in search_solr\engine.
core_search\engine::update_schema |
( |
|
$oldversion, |
|
|
|
$newversion |
|
) |
| |
|
protected |
Requests the search engine to upgrade the schema.
The engine should update the schema if possible/necessary, and should ensure that record_applied_schema_version is called as a result.
If it is not possible to upgrade the schema at the moment, it can do nothing and return; the function will be called again next time search is initialised.
The default implementation just returns, with a DEBUG_DEVELOPER warning.
- Parameters
-
int | $oldversion | Old schema version |
int | $newversion | New schema version |
- Return values
-
bool|string | True if schema is updated successfully, a string if it needs updating manually |
Reimplemented in search_solr\engine.