Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

Search base class to be extended by search areas.

Copyright: 2015 David Monllao {@link http://www.davidmonllao.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 553 lines (20 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes


Class: base  - X-Ref

Base search implementation.

Components and plugins interested in filling the search engine with data should extend this class (or any extension of this
class).

__construct()   X-Ref
Constructor.

return: void

Class: namespace  - X-Ref

get_levels()   X-Ref
Returns context levels property.

return: int

get_area_id()   X-Ref
Returns the area id.

return: string

get_component_name()   X-Ref
Returns the moodle component name.

It might be the plugin name (whole frankenstyle name) or the core subsystem name.

return: string

get_component_type()   X-Ref
Returns the component type.

It might be a plugintype or 'core' for core subsystems.

return: string

get_visible_name($lazyload = false)   X-Ref
Returns the area visible name.

param: bool $lazyload Usually false, unless when in admin settings.
return: string

get_config_var_name()   X-Ref
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.

return: string Config var path including the plugin (or component) and the varname

get_config()   X-Ref
Returns all the search area configuration.

return: array

get_settingnames()   X-Ref
Return a list of all required setting names.

return: array

is_enabled()   X-Ref
Is the search component enabled by the system administrator?

return: bool

set_enabled($isenabled)   X-Ref
No description

get_last_indexing_duration()   X-Ref
Gets the length of time spent indexing this area (the last time it was indexed).

return: int|bool Time in seconds spent indexing this area last time, false if never indexed

uses_file_indexing()   X-Ref
Returns true if this area uses file indexing.

return: bool

get_recordset_by_timestamp($modifiedfrom = 0)   X-Ref
Returns a recordset ordered by modification date ASC.

Each record can include any data self::get_document might need but it must:
- Include an 'id' field: 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.
- Only return data modified since $modifiedfrom, including $modifiedform to prevent
some records from not being indexed (e.g. your-timemodified-fieldname >= $modifiedfrom)
- Order the returned data by time modified in ascending order, as \core_search::manager will need to store the modified time
of the last indexed document.

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.

param: int $modifiedfrom
return: \moodle_recordset

get_document_recordset($modifiedfrom = 0, \context $context = null)   X-Ref
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:
- If indexing the entire system (no context restriction) the search indexer will try
get_recordset_by_timestamp instead
- If trying to index a context (e.g. when restoring a course), the search indexer will not
index this area, so that restored content may not be indexed.

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.

param: int $modifiedfrom Return only records modified after this date
param: \context|null $context Context (null means no context restriction)
return: \moodle_recordset|null|false Recordset / null if no results / false if not supported

supports_get_document_recordset()   X-Ref
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.

get_document_display_title(\core_search\document $doc)   X-Ref
Returns the document title to display.

Allow to customize the document title string to display.

param: \core_search\document $doc
return: string Document title to display in the search results page

get_search_fileareas()   X-Ref
Return the context info required to index files for
this search area.

Should be onerridden by each search area.

return: array

attach_files($document)   X-Ref
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.

param: document $document The current document
return: void

get_course_level_context_restriction_sql(\context $context = null,$coursetable, $paramtype = SQL_PARAMS_QM)   X-Ref
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.

param: \context|null $context Context to restrict the query
param: string $coursetable Name of alias for course table e.g. 'c'
param: int $paramtype Type of SQL parameters to use (default question mark)
return: array Array with SQL and parameters; both null if no need to query

get_contexts_to_reindex()   X-Ref
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).

return: \Iterator Iterator of contexts to reindex

get_doc_icon(document $doc)   X-Ref
Returns an icon instance for the document.

param: \core_search\document $doc
return: \core_search\document_icon

get_category_names()   X-Ref
Returns a list of category names associated with the area.

return: array