Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
|
Base search implementation. More...
Public Member Functions | |
__construct () | |
Constructor. | |
attach_files ($document) | |
Files related to the current document are attached, to the document object ready for indexing by Global Search. | |
check_access ($id) | |
Can the current user see the document. | |
get_area_id () | |
Returns the area id. | |
get_category_names () | |
Returns a list of category names associated with the area. | |
get_component_name () | |
Returns the moodle component name. | |
get_component_type () | |
Returns the component type. | |
get_config () | |
Returns all the search area configuration. | |
get_config_var_name () | |
Returns the config var name. | |
get_context_url (\core_search\document $doc) | |
Returns a url to the document context. | |
get_contexts_to_reindex () | |
Gets a list of all contexts to reindex when reindexing this search area. | |
get_doc_icon (document $doc) | |
Returns an icon instance for the document. | |
get_doc_url (\core_search\document $doc) | |
Returns a url to the document, it might match self\get_context_url(). | |
get_document ($record, $options=array()) | |
Returns the document related with the provided record. | |
get_document_display_title (\core_search\document $doc) | |
Returns the document title to display. | |
get_document_recordset ($modifiedfrom=0, context $context=null) | |
Returns a recordset containing all items from this area, optionally within the given context, and including only items modifed from (>=) the specified time. | |
get_last_indexing_duration () | |
Gets the length of time spent indexing this area (the last time it was indexed). | |
get_recordset_by_timestamp ($modifiedfrom=0) | |
Returns a recordset ordered by modification date ASC. | |
get_search_fileareas () | |
Return the context info required to index files for this search area. | |
get_visible_name ($lazyload=false) | |
Returns the area visible name. | |
is_enabled () | |
Is the search component enabled by the system administrator? | |
set_enabled ($isenabled) | |
supports_get_document_recordset () | |
Checks if get_document_recordset is supported for this search area. | |
uses_file_indexing () | |
Returns true if this area uses file indexing. | |
Static Public Member Functions | |
static | get_levels () |
Returns context levels property. | |
static | get_settingnames () |
Return a list of all required setting names. | |
Public Attributes | |
string | $areaid |
An area id from the componentname and the area name. | |
Protected Member Functions | |
get_course_level_context_restriction_sql (?\context $context, $coursetable, $paramtype=SQL_PARAMS_QM) | |
Helper function that gets SQL useful for restricting a search query given a passed-in context, for data stored at course level. | |
Static Protected Attributes | |
static array | $levels = [CONTEXT_SYSTEM] |
The context levels the search implementation is working on. | |
Base search implementation.
Components and plugins interested in filling the search engine with data should extend this class (or any extension of this class).
|
final |
core_search\base::attach_files | ( | $document | ) |
Files related to the current document are attached, to the document object ready for indexing by Global Search.
The default implementation retrieves all files for the file areas returned by get_search_fileareas(). If you need to filter files to specific items per file area, you will need to override this method and explicitly provide the items.
document | $document | The current document |
void |
Reimplemented in block_html\search\content, core_search\base_activity, mod_data\search\entry, and mod_forum\search\post.
|
abstract |
Can the current user see the document.
int | $id | The internal search area entity id. |
int | manager:ACCESS_xx constant |
Reimplemented in core_course\search\course, core_course\search\customfield, core_course\search\section, core_message\search\message_received, core_message\search\message_sent, core_search\base_activity, core_search\base_block, core_user\search\course_teacher, core_user\search\user, mod_book\search\chapter, mod_data\search\entry, mod_forum\search\post, mod_glossary\search\entry, and mod_wiki\search\collaborative_page.
core_search\base::get_area_id | ( | ) |
Returns the area id.
string |
core_search\base::get_category_names | ( | ) |
Returns a list of category names associated with the area.
array |
Reimplemented in core_course\search\course, core_course\search\customfield, core_course\search\section, core_message\search\base_message, core_search\base_block, core_search\base_mod, core_user\search\course_teacher, and core_user\search\user.
core_search\base::get_component_name | ( | ) |
Returns the moodle component name.
It might be the plugin name (whole frankenstyle name) or the core subsystem name.
string |
Reimplemented in core_course\search\course, core_course\search\customfield, core_course\search\section, core_user\search\course_teacher, and core_user\search\user.
core_search\base::get_component_type | ( | ) |
Returns the component type.
It might be a plugintype or 'core' for core subsystems.
string |
core_search\base::get_config | ( | ) |
Returns all the search area configuration.
array |
core_search\base::get_config_var_name | ( | ) |
Returns the config var name.
It depends on whether it is a moodle subsystem or a plugin as plugin-related config should remain in their own scope.
string | Config var path including the plugin (or component) and the varname |
|
abstract |
Returns a url to the document context.
core_search\document | $doc |
moodle_url |
Reimplemented in core_search\base_activity, and core_search\base_block.
core_search\base::get_contexts_to_reindex | ( | ) |
Gets a list of all contexts to reindex when reindexing this search area.
The list should be returned in an order that is likely to be suitable when reindexing, for example with newer contexts first.
The default implementation simply returns the system context, which will result in reindexing everything in normal date order (oldest first).
Iterator | Iterator of contexts to reindex |
Reimplemented in core_search\base_block, and core_search\base_mod.
|
protected |
Helper function that gets SQL useful for restricting a search query given a passed-in context, for data stored at course level.
The SQL returned will be zero or more JOIN statements, surrounded by whitespace, which act as restrictions on the query based on the rows in a module table.
You can pass in a null or system context, which will both return an empty string and no params.
Returns an array with two nulls if there can be no results for a course within this context.
If named parameters are used, these will be named gclcrs0, gclcrs1, etc. The table aliases used in SQL also all begin with gclcrs, to avoid conflicts.
context | null | $context | Context to restrict the query |
string | $coursetable | Name of alias for course table e.g. 'c' |
int | $paramtype | Type of SQL parameters to use (default question mark) |
array | Array with SQL and parameters; both null if no need to query |
coding_exception | If called with invalid params |
core_search\base::get_doc_icon | ( | document | $doc | ) |
Returns an icon instance for the document.
core_search\document | $doc |
core_search\document_icon |
Reimplemented in core_search\base_block, and core_search\base_mod.
|
abstract |
Returns a url to the document, it might match self\get_context_url().
core_search\document | $doc |
moodle_url |
Reimplemented in core_search\base_activity, and core_search\base_block.
|
abstract |
Returns the document related with the provided record.
This method receives a record with the document id and other info returned by get_recordset_by_timestamp or get_recordset_by_contexts that might be useful here. The idea is to restrict database queries to minimum as this function will be called for each document to index. As an alternative, use cached data.
Internally it should use core_search\document to standarise the documents before sending them to the search engine.
Search areas should send plain text to the search engine, use the following function to convert any user input data to plain text: content_to_text
Valid keys for the options array are: indexfiles => File indexing is enabled if true. lastindexedtime => The last time this area was indexed. 0 if never indexed.
The lastindexedtime value is not set if indexing a specific context rather than the whole system.
stdClass | $record | A record containing, at least, the indexed document id and a modified timestamp |
array | $options | Options for document creation |
core_search\document |
Reimplemented in block_html\search\content, core_course\search\course, core_course\search\customfield, core_course\search\section, core_message\search\base_message, core_message\search\message_received, core_message\search\message_sent, core_search\base_activity, core_user\search\course_teacher, core_user\search\user, mod_bigbluebuttonbn\search\tags, mod_book\search\chapter, mod_data\search\entry, mod_forum\search\post, mod_glossary\search\entry, mod_page\search\activity, mod_url\search\activity, and mod_wiki\search\collaborative_page.
core_search\base::get_document_display_title | ( | \core_search\document | $doc | ) |
Returns the document title to display.
Allow to customize the document title string to display.
core_search\document | $doc |
string | Document title to display in the search results page |
core_search\base::get_document_recordset | ( | $modifiedfrom = 0, | |
context | $context = null ) |
Returns a recordset containing all items from this area, optionally within the given context, and including only items modifed from (>=) the specified time.
The recordset must be ordered in ascending order of modified time.
Each record can include any data self\get_document might need. It must include an 'id' field,a unique identifier (in this area's scope) of a document to index in the search engine. If the indexed content field can contain embedded files, the 'id' value should match the filearea itemid.
The return value can be a recordset, null (if this area does not provide any results in the given context and there is no need to do a database query to find out), or false (if this facility is not currently supported by this search area).
If this function returns false, then:
The default implementation returns false, indicating that this facility is not supported and the older get_recordset_by_timestamp function should be used.
This function must accept all possible values for the $context parameter. For example, if you are implementing this function for the forum module, it should still operate correctly if called with the context for a glossary module, or for the HTML block. (In these cases where it will not return any data, it may return null.)
The $context parameter can also be null or the system context; both of these indicate that all data, without context restriction, should be returned.
int | $modifiedfrom | Return only records modified after this date |
context | null | $context | Context (null means no context restriction) |
moodle_recordset|null|false | Recordset / null if no results / false if not supported |
Reimplemented in core_course\search\course, core_course\search\customfield, core_course\search\section, core_message\search\message_received, core_message\search\message_sent, core_search\base_activity, core_search\base_block, core_user\search\course_teacher, core_user\search\user, mod_bigbluebuttonbn\search\tags, mod_book\search\chapter, mod_data\search\entry, mod_forum\search\post, mod_glossary\search\entry, mod_survey\search\activity, and mod_wiki\search\collaborative_page.
core_search\base::get_last_indexing_duration | ( | ) |
Gets the length of time spent indexing this area (the last time it was indexed).
int|bool | Time in seconds spent indexing this area last time, false if never indexed |
|
static |
Returns context levels property.
int |
core_search\base::get_recordset_by_timestamp | ( | $modifiedfrom = 0 | ) |
Returns a recordset ordered by modification date ASC.
Each record can include any data self\get_document might need but it must:
Since Moodle 3.4, subclasses should instead implement get_document_recordset, which has an additional context parameter. This function continues to work for implementations which haven't been updated, or where the context parameter is not required.
int | $modifiedfrom |
moodle_recordset |
core_search\base::get_search_fileareas | ( | ) |
Return the context info required to index files for this search area.
Should be onerridden by each search area.
array |
Reimplemented in core_course\search\course, core_course\search\section, core_search\base_activity, core_user\search\user, mod_assign\search\activity, mod_book\search\chapter, mod_folder\search\activity, mod_forum\search\post, mod_glossary\search\entry, mod_lesson\search\activity, mod_page\search\activity, mod_resource\search\activity, mod_scorm\search\activity, mod_wiki\search\collaborative_page, and mod_workshop\search\activity.
|
static |
Return a list of all required setting names.
array |
core_search\base::get_visible_name | ( | $lazyload = false | ) |
Returns the area visible name.
bool | $lazyload | Usually false, unless when in admin settings. |
string |
core_search\base::is_enabled | ( | ) |
Is the search component enabled by the system administrator?
bool |
core_search\base::supports_get_document_recordset | ( | ) |
Checks if get_document_recordset is supported for this search area.
For many uses you can simply call get_document_recordset and see if it returns false, but this function is useful when you don't want to actually call the function right away.
core_search\base::uses_file_indexing | ( | ) |
Returns true if this area uses file indexing.
bool |
Reimplemented in block_html\search\content, core_course\search\course, core_course\search\section, core_user\search\user, mod_assign\search\activity, mod_bigbluebuttonbn\search\activity, mod_bigbluebuttonbn\search\tags, mod_book\search\activity, mod_book\search\chapter, mod_chat\search\activity, mod_choice\search\activity, mod_data\search\activity, mod_data\search\entry, mod_feedback\search\activity, mod_folder\search\activity, mod_forum\search\activity, mod_forum\search\post, mod_glossary\search\activity, mod_glossary\search\entry, mod_h5pactivity\search\activity, mod_imscp\search\activity, mod_label\search\activity, mod_lesson\search\activity, mod_lti\search\activity, mod_page\search\activity, mod_quiz\search\activity, mod_resource\search\activity, mod_scorm\search\activity, mod_survey\search\activity, mod_url\search\activity, mod_wiki\search\activity, mod_wiki\search\collaborative_page, and mod_workshop\search\activity.