Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
|
Search subsystem manager. More...
Public Member Functions | |
__construct ($engine) | |
Constructor, use core_search::manager::instance instead to get a class instance. More... | |
delete_index ($areaid=false) | |
Deletes an area's documents or all areas documents. More... | |
delete_index_by_id ($id) | |
Deletes index by id. More... | |
get_areas_config ($searchareas) | |
Returns search areas configuration. More... | |
get_engine () | |
Returns the search engine. More... | |
get_index_requests_info () | |
Gets information about the request queue, in the form of a plain object suitable for passing to a template for rendering. More... | |
index ($fullindex=false, $timelimit=0, progress_trace $progress=null) | |
Index all documents. More... | |
index_context ($context, $singleareaid='', $timelimit=0, progress_trace $progress=null, $startfromarea='', $startfromtime=0) | |
Indexes or reindexes a specific context of the system, e.g. More... | |
optimize_index () | |
Merge separate index segments into one. | |
paged_search (\stdClass $formdata, $pagenum) | |
Returns requested page of documents plus additional information for paging. More... | |
process_index_requests ($timelimit=0.0, progress_trace $progress=null) | |
Processes outstanding index requests. More... | |
reset_config ($areaid=false) | |
Resets areas config. More... | |
search (\stdClass $formdata, $limit=0) | |
Returns documents from the engine based on the data provided. More... | |
Static Public Member Functions | |
static | clean_up_non_existing_area ($areaid) |
Cleans up non existing search area. More... | |
static | clear_static () |
Clears all static caches. More... | |
static | context_deleted (\context $context) |
Informs the search system that a context has been deleted. More... | |
static | course_deleting_finish (int $courseid) |
Informs the search engine that a course has now been deleted. More... | |
static | course_deleting_start (int $courseid) |
Informs the search system that a course is about to be deleted. More... | |
static | extract_areaid_parts ($areaid) |
Returns all areaid string components (component name and area name). More... | |
static | generate_areaid ($componentname, $areaname) |
Generates an area id from the componentname and the area name. More... | |
static | get_course_search_url () |
Returns the search URL for course search. More... | |
static | get_current_time () |
Gets current time for use in search system. More... | |
static | get_default_area_category_name () |
Returns default search area category name. More... | |
static | get_search_area ($areaid) |
Returns a new area search indexer instance. More... | |
static | get_search_area_categories () |
Return a list of existing search area categories. More... | |
static | get_search_area_category_by_name ($name) |
Return search area category instance by category name. More... | |
static | get_search_areas_list ($enabled=false) |
Return the list of available search areas. More... | |
static | include_all_courses () |
Check if search all courses setting is enabled. More... | |
static | instance ($fast=false) |
Returns an initialised core_search instance. More... | |
static | is_global_search_enabled () |
Returns whether global search is enabled or not. More... | |
static | is_indexing_enabled () |
Returns whether indexing is enabled or not (you can enable indexing even when search is not enabled at the moment, so as to have it ready for students). More... | |
static | is_search_area_categories_enabled () |
Check if search area categories functionality is enabled. More... | |
static | parse_areaid ($areaid) |
Parse a search area id and get plugin name and config name prefix from it. More... | |
static | request_index (\context $context, $areaid='', $priority=self::INDEX_PRIORITY_NORMAL) |
Requests that a specific context is indexed by the scheduled task. More... | |
static | search_engine_instance () |
Returns an instance of the search engine. More... | |
static | should_hide_all_results_category () |
Check if all results category should be hidden. More... | |
static | trigger_search_results_viewed ($other) |
Triggers search_results_viewed event. More... | |
Protected Member Functions | |
build_limitcourseids (\stdClass $formdata) | |
Build a list of course ids to limit the search based on submitted form data. More... | |
get_all_courses ($limitcourseids) | |
Get a list of all courses limited by ids if required. More... | |
get_areas_user_accesses ($limitcourseids=false, $limitcontextids=false) | |
Returns information about the areas which the user can access. More... | |
get_my_courses ($allaccessible) | |
Get a list of courses as user can access. More... | |
Static Protected Member Functions | |
static | get_additional_search_area_categories () |
Gets a list of additional search area categories. More... | |
static | get_area_classname ($areaid) |
Returns a search area class name. More... | |
static | get_core_search_area_categories () |
Get list of core search area categories. More... | |
static | is_search_area ($classname) |
Checks whether a classname is of an actual search area. More... | |
static | is_valid_area_category ($areacategory) |
Check if provided instance of area category is valid. More... | |
Protected Attributes | |
int | $behatresultcount = 0 |
Result count when used with mock results for Behat tests. | |
core_search engine | $engine = null |
Static Protected Attributes | |
static core_search base[] | $allsearchareas = null |
All system search areas. | |
static array | $coursedeleting = [] |
IDs (as keys) of course deletions in progress in this requuest, if any. | |
static core_search base[] | $enabledsearchareas = null |
Enabled search areas. | |
static core_search manager | $instance = null |
static float | $phpunitfaketime = 0 |
Note: This should be removed once possible (see MDL-60644). More... | |
static core_search area_category[] | $searchareacategories = null |
A list of search area categories. | |
Search subsystem manager.
core_search\manager::__construct | ( | $engine | ) |
Constructor, use core_search::manager::instance instead to get a class instance.
core_search::base | The search engine to use |
|
protected |
Build a list of course ids to limit the search based on submitted form data.
stdClass | $formdata | Submitted search form data. |
array|bool |
|
static |
Cleans up non existing search area.
string | $areaid | Search area id. |
|
static |
Clears all static caches.
void |
|
static |
Informs the search system that a context has been deleted.
This will clear the data from the search index, where the search engine supports that.
This function does not usually throw an exception (so as not to get in the way of the context deletion finishing).
This is called for all types of context deletion.
context | $context | Context object that has just been deleted |
|
static |
Informs the search engine that a course has now been deleted.
This causes the search engine to actually delete the index for the whole course.
int | $courseid | Course id that no longer exists |
|
static |
Informs the search system that a course is about to be deleted.
This prevents it from sending hundreds of 'delete context' updates for all the individual contexts that are deleted.
If you call this, you must call course_deleting_finish().
int | $courseid | Course id that is being deleted |
core_search\manager::delete_index | ( | $areaid = false | ) |
Deletes an area's documents or all areas documents.
string | $areaid | The area id or false for all |
void |
core_search\manager::delete_index_by_id | ( | $id | ) |
Deletes index by id.
int | Solr Document string $id |
|
static |
Returns all areaid string components (component name and area name).
string | $areaid |
array | Component name (Frankenstyle) and area name (search area class name) |
|
static |
Generates an area id from the componentname and the area name.
There should not be any naming conflict as the area name is the class name in component/classes/search/.
string | $componentname | |
string | $areaname |
void |
|
staticprotected |
Gets a list of additional search area categories.
core_search::area_category[] |
|
protected |
Get a list of all courses limited by ids if required.
array | false | $limitcourseids | An array of course ids to limit the search to. False for no limiting. |
array |
|
staticprotected |
Returns a search area class name.
string | $areaid |
string |
core_search\manager::get_areas_config | ( | $searchareas | ) |
Returns search areas configuration.
core_search::base[] | $searchareas |
stdClass[]::$configsettings |
|
protected |
Returns information about the areas which the user can access.
The returned value is a stdClass object with the following fields:
The areas can be limited by course id and context id. If specifying context ids, results are limited to the exact context ids specified and not their children (for example, giving the course context id would result in including search items with the course context id, and not anything from a context inside the course). For performance, you should also specify course id(s) when using context ids.
array | false | $limitcourseids | An array of course ids to limit the search to. False for no limiting. |
array | false | $limitcontextids | An array of context ids to limit the search to. False for no limiting. |
stdClass | Object as described above |
|
staticprotected |
Get list of core search area categories.
core_search::area_category[] |
|
static |
Returns the search URL for course search.
moodle_url |
|
static |
Gets current time for use in search system.
Note: This should be replaced with generic core functionality once possible (see MDL-60644).
float | Current time in seconds (with decimals) |
|
static |
Returns default search area category name.
string |
core_search\manager::get_engine | ( | ) |
Returns the search engine.
core_search::engine |
core_search\manager::get_index_requests_info | ( | ) |
Gets information about the request queue, in the form of a plain object suitable for passing to a template for rendering.
stdClass | Information about queued index requests |
|
protected |
Get a list of courses as user can access.
bool | $allaccessible | Include courses user is not enrolled in, but can access. |
array |
|
static |
Returns a new area search indexer instance.
string | $areaid |
core_search::base|bool | False if the area is not available. |
|
static |
Return a list of existing search area categories.
core_search::area_category[] |
|
static |
Return search area category instance by category name.
string | $name | Category name. If name is not valid will return default category. |
core_search::area_category |
|
static |
Return the list of available search areas.
bool | $enabled | Return only the enabled ones. |
core_search::base[] |
|
static |
Check if search all courses setting is enabled.
bool |
core_search\manager::index | ( | $fullindex = false , |
|
$timelimit = 0 , |
|||
progress_trace | $progress = null |
||
) |
Index all documents.
bool | $fullindex | Whether we should reindex everything or not. |
float | $timelimit | Time limit in seconds (0 = no time limit) |
progress_trace | null | $progress | Optional class for tracking progress |
moodle_exception |
bool | Whether there was any updated document or not. |
core_search\manager::index_context | ( | $context, | |
$singleareaid = '' , |
|||
$timelimit = 0 , |
|||
progress_trace | $progress = null , |
||
$startfromarea = '' , |
|||
$startfromtime = 0 |
|||
) |
Indexes or reindexes a specific context of the system, e.g.
one course.
The function returns an object with field 'complete' (true or false).
This function supports partial indexing via the time limit parameter. If the time limit expires, it will return values for $startfromarea and $startfromtime which can be passed next time to continue indexing.
context | $context | Context to restrict index. |
string | $singleareaid | If specified, indexes only the given area. |
float | $timelimit | Time limit in seconds (0 = no time limit) |
progress_trace | null | $progress | Optional class for tracking progress |
string | $startfromarea | Area to start from |
int | $startfromtime | Timestamp to start from |
stdClass | Object indicating success |
|
static |
Returns an initialised core_search instance.
While constructing the instance, checks on the search schema may be carried out. The $fast parameter provides a way to skip those checks on pages which are used frequently. It has no effect if an instance has already been constructed in this request.
bool | $fast | Set to true when calling on a page that requires high performance |
core_search::engine_exception |
core_search::manager |
|
static |
Returns whether global search is enabled or not.
bool |
|
static |
Returns whether indexing is enabled or not (you can enable indexing even when search is not enabled at the moment, so as to have it ready for students).
bool | True if indexing is enabled. |
|
staticprotected |
Checks whether a classname is of an actual search area.
string | $classname |
bool |
|
static |
Check if search area categories functionality is enabled.
bool |
|
staticprotected |
Check if provided instance of area category is valid.
mixed | $areacategory | Area category instance. Potentially could be anything. |
bool |
core_search\manager::paged_search | ( | \stdClass | $formdata, |
$pagenum | |||
) |
Returns requested page of documents plus additional information for paging.
This function does not perform any kind of security checking for access, the caller code should check that the current user have moodle/search:query capability.
If a page is requested that is beyond the last result, the last valid page is returned in results, and actualpage indicates which page was returned.
stdClass | $formdata | |
int | $pagenum | The 0 based page number. |
object | An object with 3 properties: results => An array of core_search::documents for the actual page. totalcount => Number of records that are possibly available, to base paging on. actualpage => The actual page returned. |
|
static |
Parse a search area id and get plugin name and config name prefix from it.
string | $areaid | Search area id. |
array | Where the first element is a plugin name and the second is config names prefix. |
core_search\manager::process_index_requests | ( | $timelimit = 0.0 , |
|
progress_trace | $progress = null |
||
) |
Processes outstanding index requests.
This will take the first item from the queue (taking account the indexing priority) and process it, continuing until an optional time limit is reached.
If there are no index requests, the function will do nothing.
float | $timelimit | Time limit (0 = none) |
progress_trace | null | $progress | Optional progress indicator |
|
static |
Requests that a specific context is indexed by the scheduled task.
The context will be added to a queue which is processed by the task.
This is used after a restore to ensure that restored items are indexed, even though their modified time will be older than the latest indexed. It is also used by the 'Gradual reindex' admin feature from the search areas screen.
context | $context | Context to index within |
string | $areaid | Area to index, '' = all areas |
int | $priority | Priority (INDEX_PRIORITY_xx constant) |
core_search\manager::reset_config | ( | $areaid = false | ) |
core_search\manager::search | ( | \stdClass | $formdata, |
$limit = 0 |
|||
) |
Returns documents from the engine based on the data provided.
This function does not perform any kind of security checking, the caller code should check that the current user have moodle/search:query capability.
It might return the results from the cache instead.
Valid formdata options include:
stdClass | $formdata | Query input data (usually from search form) |
int | $limit | The maximum number of documents to return |
core_search::document[] |
|
static |
Returns an instance of the search engine.
core_search::engine |
|
static |
Check if all results category should be hidden.
bool |
|
static |
Triggers search_results_viewed event.
Other data required:
array | $other | Other info for the event. |
core::event::search_results_viewed |
|
staticprotected |
Note: This should be removed once possible (see MDL-60644).
Fake current time for use in PHPunit tests