Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
|
Search subsystem manager. More...
Public Member Functions | |
__construct ($engine) | |
Constructor, use core_search\manager\instance instead to get a class instance. | |
delete_index ($areaid=false) | |
Deletes an area's documents or all areas documents. | |
delete_index_by_id ($id) | |
Deletes index by id. | |
get_areas_config ($searchareas) | |
Returns search areas configuration. | |
get_engine () | |
Returns the search engine. | |
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. | |
index ($fullindex=false, $timelimit=0, progress_trace $progress=null) | |
Index all documents. | |
index_context ($context, $singleareaid='', $timelimit=0, progress_trace $progress=null, $startfromarea='', $startfromtime=0) | |
Indexes or reindexes a specific context of the system, e.g. | |
optimize_index () | |
Merge separate index segments into one. | |
paged_search (\stdClass $formdata, $pagenum) | |
Returns requested page of documents plus additional information for paging. | |
process_index_requests ($timelimit=0.0, progress_trace $progress=null) | |
Processes outstanding index requests. | |
reset_config ($areaid=false) | |
Resets areas config. | |
search (\stdClass $formdata, $limit=0) | |
Returns documents from the engine based on the data provided. | |
search_top (\stdClass $formdata) | |
Search for top ranked result. | |
Static Public Member Functions | |
static | can_replace_course_search () |
Tests if global search is configured to be equivalent to the front page course search. | |
static | clean_up_non_existing_area ($areaid) |
Cleans up non existing search area. | |
static | clear_static () |
Clears all static caches. | |
static | context_deleted (\context $context) |
Informs the search system that a context has been deleted. | |
static | course_deleting_finish (int $courseid) |
Informs the search engine that a course has now been deleted. | |
static | course_deleting_start (int $courseid) |
Informs the search system that a course is about to be deleted. | |
static | extract_areaid_parts ($areaid) |
Returns all areaid string components (component name and area name). | |
static | generate_areaid ($componentname, $areaname) |
Generates an area id from the componentname and the area name. | |
static | get_course_search_url () |
Returns the search URL for course search. | |
static | get_current_time () |
Gets current time for use in search system. | |
static | get_default_area_category_name () |
Returns default search area category name. | |
static | get_search_area ($areaid) |
Returns a new area search indexer instance. | |
static | get_search_area_categories () |
Return a list of existing search area categories. | |
static | get_search_area_category_by_name ($name) |
Return search area category instance by category name. | |
static | get_search_areas_list ($enabled=false) |
Return the list of available search areas. | |
static | include_all_courses () |
Check if search all courses setting is enabled. | |
static | instance (bool $fast=false, bool $query=false) |
Returns an initialised core_search instance. | |
static | is_global_search_enabled () |
Returns whether global search is enabled or not. | |
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). | |
static | is_search_area_categories_enabled () |
Check if search area categories functionality is enabled. | |
static | parse_areaid ($areaid) |
Parse a search area id and get plugin name and config name prefix from it. | |
static | request_index (\context $context, $areaid='', $priority=self::INDEX_PRIORITY_NORMAL) |
Requests that a specific context is indexed by the scheduled task. | |
static | search_engine_instance (bool $query=false) |
Returns an instance of the search engine. | |
static | should_hide_all_results_category () |
Check if all results category should be hidden. | |
static | trigger_search_results_viewed ($other) |
Triggers search_results_viewed event. | |
Public Attributes | |
int const | ACCESS_DELETED = 2 |
The document was deleted. | |
int const | ACCESS_DENIED = 0 |
User can not access the document. | |
int const | ACCESS_GRANTED = 1 |
User can access the document. | |
float const | DISPLAY_INDEXING_PROGRESS_EVERY = 30.0 |
Adds indexing progress within one search area to cron log every N seconds. | |
float const | DISPLAY_LONG_QUERY_TIME = 5.0 |
If initial query takes longer than N seconds, this will be shown in cron log. | |
int const | DISPLAY_RESULTS_PER_PAGE = 10 |
Number of results per page. | |
int const | INDEX_PRIORITY_NORMAL = 100 |
Context indexing: normal priority. | |
int const | INDEX_PRIORITY_REINDEXING = 50 |
Context indexing: low priority for reindexing. | |
int const | MAX_RESULTS = 100 |
Maximum number of results that will be retrieved from the search engine. | |
int const | NO_OWNER_ID = 0 |
The id to be placed in owneruserid when there is no owner. | |
int const | SCHEMA_CHECK_REQUIRED_EVERY = 4 * 3600 |
Require a new schema check at least every 4 hours. | |
int const | SCHEMA_CHECK_TRACKING_DELAY = 10 * 60 |
Record time of each successful schema check, but not more than once per 10 minutes. | |
string const | SEARCH_AREA_CATEGORY_ALL = 'core-all' |
Core search area category for all results. | |
string const | SEARCH_AREA_CATEGORY_COURSE_CONTENT = 'core-course-content' |
Core search area category for course content. | |
string const | SEARCH_AREA_CATEGORY_COURSES = 'core-courses' |
Core search area category for courses. | |
string const | SEARCH_AREA_CATEGORY_OTHER = 'core-other' |
Core search area category for results that do not fit into any of existing categories. | |
string const | SEARCH_AREA_CATEGORY_USERS = 'core-users' |
Core search area category for users. | |
int const | TYPE_FILE = 2 |
File contents. | |
int const | TYPE_TEXT = 1 |
Text contents. | |
Protected Member Functions | |
build_limitcourseids (\stdClass $formdata) | |
Build a list of course ids to limit the search based on submitted form data. | |
get_all_courses ($limitcourseids) | |
Get a list of all courses limited by ids if required. | |
get_areas_user_accesses ($limitcourseids=false, $limitcontextids=false) | |
Returns information about the areas which the user can access. | |
get_my_courses ($allaccessible) | |
Get a list of courses as user can access. | |
Static Protected Member Functions | |
static | get_additional_search_area_categories () |
Gets a list of additional search area categories. | |
static | get_area_classname ($areaid) |
Returns a search area class name. | |
static | get_core_search_area_categories () |
Get list of core search area categories. | |
static | is_search_area ($classname) |
Checks whether a classname is of an actual search area. | |
static | is_valid_area_category ($areacategory) |
Check if provided instance of area category is valid. | |
static | search_engine_instance_from_setting (string $setting) |
Loads a search engine based on the name given in settings, which can optionally include '-alternate' to indicate that an alternate version should be used. | |
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). | |
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 |
Tests if global search is configured to be equivalent to the front page course search.
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.
The $query parameter indicates that the page is used for queries rather than indexing. If configured, this will cause the query-only search engine to be used instead of the 'normal' one.
bool | $fast | Set to true when calling on a page that requires high performance |
bool | $query | Set true on a page that is used for querying |
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.
bool | $query | If true, gets the query-only search engine (where configured) |
core_search\engine |
|
staticprotected |
Loads a search engine based on the name given in settings, which can optionally include '-alternate' to indicate that an alternate version should be used.
string | $setting |
engine|null |
core_search\manager::search_top | ( | \stdClass | $formdata | ) |
Search for top ranked result.
stdClass | $formdata | search query data |
array|document[] |
|
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