Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
search_simpledb\engine Class Reference

Simple moodle database engine. More...

Inheritance diagram for search_simpledb\engine:
core_search\engine

Public Member Functions

 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 area's documents.
 
 delete_by_id ($id)
 Deletes the specified document.
 
 delete_index_for_context (int $oldcontextid)
 Simpledb supports deleting the index for a context.
 
 delete_index_for_course (int $oldcourseid)
 Simpledb supports deleting the index for a course.
 
 execute_query ($filters, $usercontexts, $limit=0)
 Prepares a SQL query, applies filters and executes it returning its results.
 
 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 results.
 
 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 ()
 It is always installed.
 
 is_server_ready ()
 Checks that the required table was installed.
 
 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.
 
 get_simple_query ($q)
 Returns the default query for db engines.
 
 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.
 

Protected Attributes

array $cachedareas = array()
 Internal cache.
 
array $cachedcourses = array()
 Internal cache.
 
stdClass $config = null
 The search engine configuration.
 
string $pluginname = null
 Frankenstyle plugin name.
 
string $queryerror = null
 Last executed query error, if there was any.
 
bool $skipschemacheck = false
 If true, should skip schema validity check when checking the search engine is ready.
 
null int $totalresults = null
 Total number of available results.
 

Static Protected Attributes

static stdClass[] $cachedusers = array()
 User data required to show their fullnames.
 

Detailed Description

Simple moodle database engine.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ add_document()

search_simpledb\engine::add_document ( $document,
$fileindexing = false )

Adds a document to the search engine.

This does not commit to the search engine.

Parameters
core_search\document$document
bool$fileindexingTrue if file indexing is to be used
Return values
boolFalse if the file was skipped or failed, true on success

Reimplemented from core_search\engine.

◆ add_document_batch()

core_search\engine::add_document_batch ( array $documents,
bool $fileindexing = false )
inherited

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 {

See also
supports_add_document_batch}.

The system will only call this function with up to {

See also
get_batch_max_documents} documents, and each document in the batch will have content no larger than specified by {
get_batch_max_content}.
Parameters
document[]$documentsDocuments to add
bool$fileindexingTrue if file indexing is to be used
Return values
int[]Array of three elements, successfully processed, failed processed, batch count

Reimplemented in search_solr\engine.

◆ add_documents()

core_search\engine::add_documents ( $iterator,
$searcharea,
$options )
inherited

Loop through given iterator of search documents and and have the search engine back end add them to the index.

Parameters
iterator$iteratorthe iterator of documents to index
base$searchareathe area for the documents to index
array$optionsdocument indexing options
Return values
arrayProcessed document counts

◆ area_index_complete()

core_search\engine::area_index_complete ( $searcharea,
$numdocs = 0,
$fullindex = false )
inherited

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.

Parameters
core_search\base$searchareaThe search area that was complete
int$numdocsThe number of documents that were added to the index
bool$fullindexTrue if a full index is being performed
Return values
boolTrue means that data is considered indexed

Reimplemented in search_solr\engine.

◆ area_index_starting()

core_search\engine::area_index_starting ( $searcharea,
$fullindex = false )
inherited

Do anything that may need to be done before an area is indexed.

Parameters
core_search\base$searchareaThe search area that was complete
bool$fullindexTrue if a full index is being performed
Return values
void

◆ check_latest_schema()

core_search\engine::check_latest_schema ( )
inherited

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.

Return values
bool|stringTrue if schema is OK, a string if user needs to take action

◆ clear_query_error()

core_search\engine::clear_query_error ( )
inherited

Clears the current query error value.

Return values
void

◆ clear_users_cache()

static core_search\engine::clear_users_cache ( )
staticinherited

Clears the users cache.

Return values
null

◆ delete()

search_simpledb\engine::delete ( $areaid = null)

Delete all area's documents.

Parameters
string$areaid
Return values
void

Reimplemented from core_search\engine.

◆ delete_by_id()

search_simpledb\engine::delete_by_id ( $id)

Deletes the specified document.

Parameters
string$idThe document id to delete
Return values
void

◆ delete_index_for_context()

search_simpledb\engine::delete_index_for_context ( int $oldcontextid)

Simpledb supports deleting the index for a context.

Parameters
int$oldcontextidContext that has been deleted
Return values
boolTrue to indicate that any data was actually deleted
Exceptions
core_search\engine_exception

Reimplemented from core_search\engine.

◆ delete_index_for_course()

search_simpledb\engine::delete_index_for_course ( int $oldcourseid)

Simpledb supports deleting the index for a course.

Parameters
int$oldcourseid
Return values
boolTrue to indicate that any data was actually deleted
Exceptions
core_search\engine_exception

Reimplemented from core_search\engine.

◆ execute_query()

search_simpledb\engine::execute_query ( $filters,
$usercontexts,
$limit = 0 )

Prepares a SQL query, applies filters and executes it returning its results.

Exceptions
core_search\engine_exception
Parameters
stdClass$filtersContaining query and filters.
array$usercontextsContexts where the user has access. True if the user can access all contexts.
int$limitThe maximum number of results to return.
Return values
core_search\document[]Results or false if no results

Reimplemented from core_search\engine.

◆ file_indexing_enabled()

core_search\engine::file_indexing_enabled ( )
inherited

Return true if file indexing is supported and enabled.

False otherwise.

Return values
bool

Reimplemented in search_solr\engine.

◆ get_batch_max_content()

core_search\engine::get_batch_max_content ( )
inherited

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 {

See also
supports_add_document_batch}.

Can be overridden by search engine if required.

Return values
intMax size in bytes, default 1MB

◆ get_batch_max_documents()

int core_search\engine::get_batch_max_documents ( )
inherited

Gets the maximum number of documents to send together in batch mode.

Only relevant if the engine returns true to {

See also
supports_add_document_batch}.

Can be overridden by search engine if required.

Number of documents to send together in batch mode, default 100.

◆ get_course()

core_search\engine::get_course ( $courseid)
protectedinherited

Returns a course instance checking internal caching.

Parameters
int$courseid
Return values
stdClass

◆ get_document_classname()

core_search\engine::get_document_classname ( )
inherited

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
string

◆ get_plugin_name()

core_search\engine::get_plugin_name ( )
inherited

Returns the plugin name.

Return values
stringFrankenstyle plugin name.

◆ get_query_error()

core_search\engine::get_query_error ( )
inherited

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.

Return values
string

◆ get_query_total_count()

search_simpledb\engine::get_query_total_count ( )

Returns the total results.

Including skipped results.

Return values
int

Reimplemented from core_search\engine.

◆ get_search_area()

core_search\engine::get_search_area ( $areaid)
protectedinherited

Returns a search instance of the specified area checking internal caching.

Parameters
string$areaidArea id
Return values
core_search\base

◆ get_simple_query()

search_simpledb\engine::get_simple_query ( $q)
protected

Returns the default query for db engines.

Parameters
string$qThe query string
Return values
arraySQL string and params list

◆ get_supported_orders()

core_search\engine::get_supported_orders ( \context $context)
inherited

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.

Parameters
context$contextContext that the user requested search from
Return values
arrayArray from order name => display text

Reimplemented in search_solr\engine.

◆ get_user()

core_search\engine::get_user ( $userid)
inherited

Returns user data checking the internal static cache.

Including here the minimum required user information as this may grow big.

Parameters
int$userid
Return values
stdClass

◆ has_alternate_configuration()

core_search\engine::has_alternate_configuration ( )
inherited

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.)

Return values
boolTrue if an alternate configuration is defined

Reimplemented in search_solr\engine.

◆ index_complete()

core_search\engine::index_complete ( $numdocs = 0,
$fullindex = false )
inherited

Run any post indexing operations.

Should be overwritten if the search engine needs to do any post index cleanup.

Parameters
int$numdocsThe number of documents that were added to the index
bool$fullindexTrue if a full index was performed
Return values
void

◆ index_starting()

core_search\engine::index_starting ( $fullindex = false)
inherited

Run any pre-indexing operations.

Should be overwritten if the search engine needs to do any pre index preparation.

Parameters
bool$fullindexTrue if a full index will be performed
Return values
void

◆ is_installed()

search_simpledb\engine::is_installed ( )

It is always installed.

Return values
true

Reimplemented from core_search\engine.

◆ is_server_ready()

search_simpledb\engine::is_server_ready ( )

Checks that the required table was installed.

Return values
true|stringReturns true if all good or an error string.

Reimplemented from core_search\engine.

◆ optimize()

core_search\engine::optimize ( )
inherited

Optimizes the search engine.

Should be overwritten if the search engine can optimize its contents.

Return values
void

◆ record_applied_schema_version()

core_search\engine::record_applied_schema_version ( $version)
inherited

Usually called by the engine; marks that the schema has been updated.

Parameters
int$versionRecords the schema version now applied

◆ should_skip_schema_check()

core_search\engine::should_skip_schema_check ( )
protectedinherited

For use by subclasses.

The engine can call this inside is_server_ready to check whether it should skip time-consuming schema checks.

Since
Moodle 3.5
Return values
boolTrue if schema checks should be skipped

◆ skip_schema_check()

core_search\engine::skip_schema_check ( $skip = true)
inherited

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.

Since
Moodle 3.5
Parameters
bool$skipTrue to skip the checks, false to start checking again

◆ supports_add_document_batch()

core_search\engine::supports_add_document_batch ( )
inherited

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.

Return values
boolTrue if the search engine supports adding documents in a batch

Reimplemented in search_solr\engine.

◆ supports_group_filtering()

core_search\engine::supports_group_filtering ( )
inherited

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:

  1. Handle the fields ->separategroupscontexts and ->usergroups in the $accessinfo parameter to execute_query (ideally, using these to automatically restrict search results).
  2. 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
boolTrue if this engine supports searching by group id field

Reimplemented in search_solr\engine.

◆ supports_users()

core_search\engine::supports_users ( )
inherited

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.

Return values
boolTrue if the search engine supports searching by user

Reimplemented in search_solr\engine.

◆ to_document()

core_search\engine::to_document ( \core_search\base $searcharea,
$docdata )
protectedinherited

Returns a document instance prepared to be rendered.

Parameters
core_search\base$searcharea
array$docdata
Return values
core_search\document

◆ update_schema()

core_search\engine::update_schema ( $oldversion,
$newversion )
protectedinherited

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$oldversionOld schema version
int$newversionNew schema version
Return values
bool|stringTrue if schema is updated successfully, a string if it needs updating manually

Reimplemented in search_solr\engine.

Member Data Documentation

◆ $cachedusers

stdClass [] core_search\engine::$cachedusers = array()
staticprotectedinherited

User data required to show their fullnames.

Indexed by userid.


The documentation for this class was generated from the following file: