Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
|
Base class for search engines. More...
Public Member Functions | |
__construct (bool $alternateconfiguration=false) | |
Initialises the search engine configuration. | |
add_document ($document, $fileindexing=false) | |
Adds a document to the search engine. | |
add_document_batch (array $documents, bool $fileindexing=false) | |
Adds multiple documents to the search engine. | |
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. | |
area_index_complete ($searcharea, $numdocs=0, $fullindex=false) | |
Do any area cleanup needed, and do anything to confirm contents. | |
area_index_starting ($searcharea, $fullindex=false) | |
Do anything that may need to be done before an area is indexed. | |
check_latest_schema () | |
Checks that the schema is the latest version. | |
clear_query_error () | |
Clears the current query error value. | |
delete ($areaid=null) | |
Delete all documents. | |
delete_index_for_context (int $oldcontextid) | |
Deletes information related to a specific context id. | |
delete_index_for_course (int $oldcourseid) | |
Deletes information related to a specific course id. | |
execute_query ($filters, $accessinfo, $limit=0) | |
Executes the query on the engine. | |
file_indexing_enabled () | |
Return true if file indexing is supported and enabled. | |
get_batch_max_content () | |
Gets the maximum size of document content to be included in a shared batch (if the document is bigger then it will be sent on its own; batching does not provide a performance improvement for big documents anyway). | |
int | get_batch_max_documents () |
Gets the maximum number of documents to send together in batch mode. | |
get_document_classname () | |
Gets the document class used by this search engine. | |
get_plugin_name () | |
Returns the plugin name. | |
get_query_error () | |
Returns any error reported by the search engine when executing the provided query. | |
get_query_total_count () | |
Returns the total number of documents available for the most recent call to execute_query. | |
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. | |
get_user ($userid) | |
Returns user data checking the internal static cache. | |
has_alternate_configuration () | |
Checks if the search engine has an alternate configuration. | |
index_complete ($numdocs=0, $fullindex=false) | |
Run any post indexing operations. | |
index_starting ($fullindex=false) | |
Run any pre-indexing operations. | |
is_installed () | |
Does the system satisfy all the requirements. | |
is_server_ready () | |
Is the server ready to use? | |
optimize () | |
Optimizes the search engine. | |
record_applied_schema_version ($version) | |
Usually called by the engine; marks that the schema has been updated. | |
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. | |
supports_add_document_batch () | |
Checks if the search engine supports adding documents in a batch. | |
supports_group_filtering () | |
Checks if this search engine supports groups. | |
supports_users () | |
Checks if the search engine supports searching by user. | |
Static Public Member Functions | |
static | clear_users_cache () |
Clears the users cache. | |
Protected Member Functions | |
get_course ($courseid) | |
Returns a course instance checking internal caching. | |
get_search_area ($areaid) | |
Returns a search instance of the specified area checking internal caching. | |
should_skip_schema_check () | |
For use by subclasses. | |
to_document (\core_search\base $searcharea, $docdata) | |
Returns a document instance prepared to be rendered. | |
update_schema ($oldversion, $newversion) | |
Requests the search engine to upgrade the schema. | |
Static Protected Attributes | |
static stdClass[] | $cachedusers = array() |
User data required to show their fullnames. | |
Base class for search engines.
All search engines must extend this class.
core_search\engine::__construct | ( | bool | $alternateconfiguration = false | ) |
Initialises the search engine configuration.
Search engine availability should be checked separately.
The alternate configuration option is only used to construct a special second copy of the search engine object, as described in {
bool | $alternateconfiguration | If true, use alternate configuration settings |
void |
Reimplemented in search_solr\engine.
|
abstract |
Adds a document to the search engine.
document | $document | |
bool | $fileindexing | True if file indexing is to be used |
bool | False if the file was skipped or failed, true on success |
Reimplemented in search_simpledb\engine, and search_solr\engine.
core_search\engine::add_document_batch | ( | array | $documents, |
bool | $fileindexing = false ) |
Adds multiple documents to the search engine.
It should return the number successfully processed, and the number of batches they were processed in (for example if you add 100 documents and there is an error processing one of those documents, and it took 4 batches, it would return [99, 1, 4]).
If the engine implements this, it should return true to {
The system will only call this function with up to {
document[] | $documents | Documents to add |
bool | $fileindexing | True if file indexing is to be used |
int[] | Array of three elements, successfully processed, failed processed, batch count |
Reimplemented in search_solr\engine.
core_search\engine::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.
iterator | $iterator | the iterator of documents to index |
base | $searcharea | the area for the documents to index |
array | $options | document indexing options |
array | Processed document counts |
core_search\engine::area_index_complete | ( | $searcharea, | |
$numdocs = 0, | |||
$fullindex = false ) |
Do any area cleanup needed, and do anything to confirm contents.
Return false to prevent the search area completed time and stats from being updated.
core_search\base | $searcharea | The search area that was complete |
int | $numdocs | The number of documents that were added to the index |
bool | $fullindex | True if a full index is being performed |
bool | True means that data is considered indexed |
Reimplemented in search_solr\engine.
core_search\engine::area_index_starting | ( | $searcharea, | |
$fullindex = false ) |
Do anything that may need to be done before an area is indexed.
core_search\base | $searcharea | The search area that was complete |
bool | $fullindex | True if a full index is being performed |
void |
core_search\engine::check_latest_schema | ( | ) |
Checks that the schema is the latest version.
If the version stored in config does not match the current, this function will attempt to upgrade the schema.
bool|string | True if schema is OK, a string if user needs to take action |
core_search\engine::clear_query_error | ( | ) |
Clears the current query error value.
void |
|
static |
Clears the users cache.
null |
|
abstract |
Delete all documents.
string | $areaid | To filter by area |
void |
Reimplemented in search_simpledb\engine, and search_solr\engine.
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.
int | $oldcontextid | ID of context that has been deleted |
bool | True if implemented |
core_search\engine_exception | Engines may throw this exception for any problem |
Reimplemented in search_simpledb\engine, and search_solr\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.
int | $oldcourseid | ID of course that has been deleted |
bool | True if implemented |
core_search\engine_exception | Engines may throw this exception for any problem |
Reimplemented in search_simpledb\engine, and search_solr\engine.
|
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):
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:
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.
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. |
core_search\document[] | Results or false if no results |
Reimplemented in search_simpledb\engine, and search_solr\engine.
core_search\engine::file_indexing_enabled | ( | ) |
Return true if file indexing is supported and enabled.
False otherwise.
bool |
Reimplemented in search_solr\engine.
core_search\engine::get_batch_max_content | ( | ) |
Gets the maximum size of document content to be included in a shared batch (if the document is bigger then it will be sent on its own; batching does not provide a performance improvement for big documents anyway).
Only relevant if the engine returns true to {
Can be overridden by search engine if required.
int | Max size in bytes, default 1MB |
int core_search\engine::get_batch_max_documents | ( | ) |
Gets the maximum number of documents to send together in batch mode.
Only relevant if the engine returns true to {
Can be overridden by search engine if required.
Number of documents to send together in batch mode, default 100.
|
protected |
Returns a course instance checking internal caching.
int | $courseid |
stdClass |
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.
string |
core_search\engine::get_plugin_name | ( | ) |
Returns the plugin name.
string | Frankenstyle plugin name. |
core_search\engine::get_query_error | ( | ) |
Returns any error reported by the search engine when executing the provided query.
It should be called from static\execute_query when an exception is triggered.
string |
|
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.
int |
Reimplemented in search_simpledb\engine, and search_solr\engine.
|
protected |
Returns a search instance of the specified area checking internal caching.
string | $areaid | Area id |
core_search\base |
core_search\engine::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.
By default, engines sort by relevance only.
context | $context | Context that the user requested search from |
array | Array from order name => display text |
Reimplemented in search_solr\engine.
core_search\engine::get_user | ( | $userid | ) |
Returns user data checking the internal static cache.
Including here the minimum required user information as this may grow big.
int | $userid |
stdClass |
core_search\engine::has_alternate_configuration | ( | ) |
Checks if the search engine has an alternate configuration.
This is used where the same search engine class supports two different configurations, which are both shown on the settings screen. The alternate configuration is selected by passing 'true' parameter to the constructor.
The feature is used when a different connection is in use for indexing vs. querying the search engine.
This function should only return true if the engine supports an alternate configuration and the user has filled in the settings. (We do not need to test they are valid, that will happen as normal.)
bool | True if an alternate configuration is defined |
Reimplemented in search_solr\engine.
core_search\engine::index_complete | ( | $numdocs = 0, | |
$fullindex = false ) |
Run any post indexing operations.
Should be overwritten if the search engine needs to do any post index cleanup.
int | $numdocs | The number of documents that were added to the index |
bool | $fullindex | True if a full index was performed |
void |
core_search\engine::index_starting | ( | $fullindex = false | ) |
Run any pre-indexing operations.
Should be overwritten if the search engine needs to do any pre index preparation.
bool | $fullindex | True if a full index will be performed |
void |
core_search\engine::is_installed | ( | ) |
Does the system satisfy all the requirements.
Should be overwritten if the search engine has any system dependencies that needs to be checked.
bool |
Reimplemented in search_simpledb\engine, and search_solr\engine.
|
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.)
true|string | Returns true if all good or an error string. |
Reimplemented in search_simpledb\engine, and search_solr\engine.
core_search\engine::optimize | ( | ) |
Optimizes the search engine.
Should be overwritten if the search engine can optimize its contents.
void |
core_search\engine::record_applied_schema_version | ( | $version | ) |
Usually called by the engine; marks that the schema has been updated.
int | $version | Records the schema version now applied |
|
protected |
For use by subclasses.
The engine can call this inside is_server_ready to check whether it should skip time-consuming schema checks.
bool | True if schema checks should be skipped |
core_search\engine::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.
This setting is not remembered and applies only to the current request.
bool | $skip | True to skip the checks, false to start checking again |
core_search\engine::supports_add_document_batch | ( | ) |
Checks if the search engine supports adding documents in a batch.
If it returns true to this function, the search engine must implement the add_document_batch function.
bool | True if the search engine supports adding documents in a batch |
Reimplemented in search_solr\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:
bool | True if this engine supports searching by group id field |
Reimplemented in search_solr\engine.
core_search\engine::supports_users | ( | ) |
Checks if the search engine supports searching by user.
If it returns true to this function, the search engine should support the 'userids' option in the $filters value passed to execute_query(), returning only items where the userid in the search document matches one of those user ids.
bool | True if the search engine supports searching by user |
Reimplemented in search_solr\engine.
|
protected |
Returns a document instance prepared to be rendered.
core_search\base | $searcharea | |
array | $docdata |
core_search\document |
|
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.
int | $oldversion | Old schema version |
int | $newversion | New schema version |
bool|string | True if schema is updated successfully, a string if it needs updating manually |
Reimplemented in search_solr\engine.
|
staticprotected |
User data required to show their fullnames.
Indexed by userid.