Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
|
Solr engine. More...
Public Member Functions | |
__construct (bool $alternateconfiguration=false) | |
Initialises the search engine configuration. | |
add_document ($document, $fileindexing=false) | |
Adds a document to the search engine. | |
add_document_batch (array $documents, bool $fileindexing=false) | |
Adds a batch of documents to the engine at once. | |
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. | |
add_fields ($query) | |
Sets fields to be returned in the result. | |
add_highlight_content ($response) | |
Finds the key common to both highlighing and docs array returned from response. | |
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) | |
Solr supports deleting the index for a context. | |
delete_index_for_course (int $oldcourseid) | |
Solr supports deleting the index for a course. | |
execute_query ($filters, $accessinfo, $limit=0) | |
Prepares a Solr 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_connection_url ($path) | |
Return a Moodle url object for the server connection. | |
get_curl_object () | |
Returns a curl object for conntecting to solr. | |
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 number of documents available for the most recently call to execute_query. | |
get_solr_major_version () | |
Returns the solr server major version. | |
get_supported_orders (\context $context) | |
Solr supports sort by location within course contexts or below. | |
get_user ($userid) | |
Returns user data checking the internal static cache. | |
has_alternate_configuration () | |
Checks if an alternate configuration has been defined. | |
index_complete ($numdocs=0, $fullindex=false) | |
Run any post indexing operations. | |
index_starting ($fullindex=false) | |
Run any pre-indexing operations. | |
is_installed () | |
Checks if the PHP Solr extension is available. | |
is_server_configured () | |
Is the solr server properly configured?. | |
is_server_ready () | |
Pings the Solr server using search_solr config. | |
merge_highlight_field_values ($doc, $highlighteddoc) | |
Adds the highlighting array values to docs array values. | |
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. | |
standarize_solr_obj (\SolrObject $obj) | |
Returns a standard php array from a SolrObject instance. | |
supports_add_document_batch () | |
Solr supports adding documents in a batch. | |
supports_group_filtering () | |
Solr includes group support in the execute_query function. | |
supports_users () | |
Solr supports search by user id. | |
Static Public Member Functions | |
static | clear_users_cache () |
Clears the users cache. | |
Public Attributes | |
int const | AUTOCOMMIT_WITHIN = 15000 |
Commit documents interval (number of miliseconds). | |
float const | CONTEXT_BOOST = 0.5 |
Boost value for matching context (in addition to course boost) | |
float const | COURSE_BOOST = 1 |
Boost value for matching course in location-ordered searches. | |
string const | DATE_FORMAT = 'Y-m-d\TH:i:s\Z' |
The date format used by solr. | |
const | FRAG_SIZE = 510 |
Highlighting fragsize. | |
const | HIGHLIGHT_END = '@@HI_E@@' |
Marker for the end of a highlight. | |
const | HIGHLIGHT_START = '@@HI_S@@' |
Marker for the start of a highlight. | |
const | QUERY_SIZE = 120 |
The maximum number of results to fetch at a time. | |
Protected Member Functions | |
add_solr_document ($doc) | |
Adds a text document to the search engine. | |
add_solr_documents (array $docs) | |
Adds multiple text documents to the search engine. | |
add_stored_file ($document, $storedfile) | |
Adds a file to the search engine. | |
commit () | |
Commits all pending changes. | |
convert_file_results ($responsedoc) | |
A very lightweight handler for getting information about already indexed files from a Solr response. | |
create_solr_document (array $doc) | |
Creates a Solr document object. | |
create_user_query ($filters, $accessinfo) | |
Prepares a new query object with needed limits, filters, etc. | |
file_is_indexable ($file) | |
Checks to see if a passed file is indexable. | |
get_course ($courseid) | |
Returns a course instance checking internal caching. | |
get_indexed_files ($document, $start=0, $rows=500) | |
Get the currently indexed files for a particular document, returns the total count, and a subset of files. | |
get_missing_docs ($missingdocs) | |
Retreive any missing main documents and attach provided files. | |
get_query_response ($query) | |
Takes a query and returns the response in SolrObject format. | |
get_response_counts ($response) | |
Returns count information for a provided response. | |
get_search_area ($areaid) | |
Returns a search instance of the specified area checking internal caching. | |
get_search_client ($triggerexception=true) | |
Returns the solr client instance. | |
grouped_files_process_response ($response, $limit=0) | |
Processes grouped file results into documents, with attached matching files. | |
process_document_files ($document) | |
Index files attached to the docuemnt, ensuring the index matches the current document files. | |
process_response ($response, $limit=0, $skipaccesscheck=false) | |
Filters the response on Moodle side. | |
set_query ($query, $q) | |
Prepares a new query by setting the query, start offset and rows to return. | |
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. | |
Static Protected Member Functions | |
static | replace_underlines (string $str) |
Replaces underlines at edges of words in the content with spaces. | |
Protected Attributes | |
bool | $cacheclient = true |
True if we should reuse SolrClients, false if not. | |
array | $cachedareas = array() |
Internal cache. | |
array | $cachedcourses = array() |
Internal cache. | |
SolrClient | $client = null |
stdClass | $config = null |
The search engine configuration. | |
curl | $curl = null |
Direct curl object. | |
array | $highlightfields = array('title', 'content', 'description1', 'description2') |
Fields that can be highlighted. | |
string | $pluginname = null |
Frankenstyle plugin name. | |
int | $processeddocs = 0 |
Number of docs we have processed for the last query. | |
string | $queryerror = null |
Last executed query error, if there was any. | |
int | $skippeddocs = 0 |
Number of docs that have been skipped while processing the last query. | |
bool | $skipschemacheck = false |
If true, should skip schema validity check when checking the search engine is ready. | |
int | $solrmajorversion = null |
Solr server major version. | |
int | $totalenginedocs = 0 |
Number of total docs reported by Sorl for the last query. | |
Static Protected Attributes | |
static stdClass[] | $cachedusers = array() |
User data required to show their fullnames. | |
Solr engine.
search_solr\engine::__construct | ( | bool | $alternateconfiguration = false | ) |
Initialises the search engine configuration.
bool | $alternateconfiguration | If true, use alternate configuration settings |
void |
Reimplemented from core_search\engine.
search_solr\engine::add_document | ( | $document, | |
$fileindexing = false ) |
Adds a document to the search engine.
This does not commit to the search engine.
document | $document | |
bool | $fileindexing | True if file indexing is to be used |
bool |
Reimplemented from core_search\engine.
search_solr\engine::add_document_batch | ( | array | $documents, |
bool | $fileindexing = false ) |
Adds a batch of documents to the engine at once.
core_search\document[] | $documents | Documents to add |
bool | $fileindexing | If true, indexes files (these are done one at a time) |
int[] | Array of three elements: successfully processed, failed processed, batch count |
Reimplemented from core_search\engine.
|
inherited |
Loop through given iterator of search documents and and have the search engine back end add them to the index.
iterator | $iterator | the iterator of documents to index |
base | $searcharea | the area for the documents to index |
array | $options | document indexing options |
array | Processed document counts |
search_solr\engine::add_fields | ( | $query | ) |
Sets fields to be returned in the result.
SolrDisMaxQuery | SolrQuery | $query | object. |
search_solr\engine::add_highlight_content | ( | $response | ) |
Finds the key common to both highlighing and docs array returned from response.
object | $response | containing results. |
|
protected |
Adds a text document to the search engine.
array | $doc |
bool |
|
protected |
Adds multiple text documents to the search engine.
array | $docs | Array of documents (each an array of fields) to add |
int[] | Array of success, failure, batch count |
core_search\engine_exception |
|
protected |
Adds a file to the search engine.
Notes about Solr and Tika indexing. We do not send the mime type, only the filename. Tika has much better content type detection than Moodle, and we will have many more doc failures if we try to send mime types.
document | $document | |
stored_file | $storedfile |
void |
search_solr\engine::area_index_complete | ( | $searcharea, | |
$numdocs = 0, | |||
$fullindex = false ) |
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.
core_search\base | $searcharea | The search area that was complete |
int | $numdocs | The number of documents that were added to the index |
bool | $fullindex | True if a full index is being performed |
bool | True means that data is considered indexed |
Reimplemented from core_search\engine.
|
inherited |
Do anything that may need to be done before an area is indexed.
core_search\base | $searcharea | The search area that was complete |
bool | $fullindex | True if a full index is being performed |
void |
|
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.
bool|string | True if schema is OK, a string if user needs to take action |
|
inherited |
Clears the current query error value.
void |
|
staticinherited |
Clears the users cache.
null |
|
protected |
Commits all pending changes.
void |
|
protected |
A very lightweight handler for getting information about already indexed files from a Solr response.
SolrObject | $responsedoc | A Solr response document |
stdClass[] | An array of objects that contain the basic information for file processing. |
|
protected |
Creates a Solr document object.
array | $doc | Array of document fields |
SolrInputDocument | Created document |
|
protected |
Prepares a new query object with needed limits, filters, etc.
stdClass | $filters | Containing query and filters. |
stdClass | $accessinfo | Information about contexts the user can access |
SolrDisMaxQuery|null | Query object or null if they can't get any results |
search_solr\engine::delete | ( | $areaid = null | ) |
Delete all area's documents.
string | $areaid |
void |
Reimplemented from core_search\engine.
search_solr\engine::delete_by_id | ( | $id | ) |
Deletes the specified document.
string | $id | The document id to delete |
void |
search_solr\engine::delete_index_for_context | ( | int | $oldcontextid | ) |
Solr supports deleting the index for a context.
int | $oldcontextid | Context that has been deleted |
bool | True to indicate that any data was actually deleted |
core_search\engine_exception |
Reimplemented from core_search\engine.
search_solr\engine::delete_index_for_course | ( | int | $oldcourseid | ) |
Solr supports deleting the index for a course.
int | $oldcourseid |
bool | True to indicate that any data was actually deleted |
core_search\engine_exception |
Reimplemented from core_search\engine.
search_solr\engine::execute_query | ( | $filters, | |
$accessinfo, | |||
$limit = 0 ) |
Prepares a Solr query, applies filters and executes it returning its results.
core_search\engine_exception |
stdClass | $filters | Containing query and filters. |
stdClass | $accessinfo | Information about areas user can access. |
int | $limit | The maximum number of results to return. |
core_search\document[] | Results or false if no results |
Reimplemented from core_search\engine.
search_solr\engine::file_indexing_enabled | ( | ) |
Return true if file indexing is supported and enabled.
False otherwise.
bool |
Reimplemented from core_search\engine.
|
protected |
Checks to see if a passed file is indexable.
stored_file | $file | The file to check |
bool | True if the file can be indexed |
|
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 {
Can be overridden by search engine if required.
int | Max size in bytes, default 1MB |
|
inherited |
Gets the maximum number of documents to send together in batch mode.
Only relevant if the engine returns true to {
Can be overridden by search engine if required.
Number of documents to send together in batch mode, default 100.
search_solr\engine::get_connection_url | ( | $path | ) |
Return a Moodle url object for the server connection.
string | $path | The solr path to append. |
moodle_url |
|
protectedinherited |
Returns a course instance checking internal caching.
int | $courseid |
stdClass |
search_solr\engine::get_curl_object | ( | ) |
Returns a curl object for conntecting to solr.
curl |
|
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.
string |
|
protected |
Get the currently indexed files for a particular document, returns the total count, and a subset of files.
document | $document | |
int | $start | The row to start the results on. Zero indexed. |
int | $rows | The number of rows to fetch |
array | A two element array, the first is the total number of availble results, the second is an array of documents for the current request. |
|
protected |
Retreive any missing main documents and attach provided files.
The missingdocs array should be an array, indexed by document id, of main documents we need to retrieve. The value associated to the key should be an array of stored_files or stored file ids to attach to the result document.
Return array also indexed by document id.
array() | $missingdocs An array, indexed by document id, with arrays of files/ids to attach. |
document[] |
|
inherited |
Returns the plugin name.
string | Frankenstyle plugin name. |
|
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.
string |
|
protected |
Takes a query and returns the response in SolrObject format.
SolrQuery | $query | Solr query object. |
SolrObject|false | Response document or false on error. |
search_solr\engine::get_query_total_count | ( | ) |
Returns the total number of documents available for the most recently call to execute_query.
int |
Reimplemented from core_search\engine.
|
protected |
Returns count information for a provided response.
Will return 0, 0 for invalid or empty responses.
SolrDocument | $response | The response document from Solr. |
array | A two part array. First how many response docs are in the response. Second, how many results are vailable in the engine. |
|
protectedinherited |
Returns a search instance of the specified area checking internal caching.
string | $areaid | Area id |
core_search\base |
|
protected |
Returns the solr client instance.
We don't reuse SolrClient if we are on libcurl 7.35.0, due to a bug in that version of curl.
core_search\engine_exception |
bool | $triggerexception |
SolrClient |
search_solr\engine::get_solr_major_version | ( | ) |
Returns the solr server major version.
int |
search_solr\engine::get_supported_orders | ( | \context | $context | ) |
Solr supports sort by location within course contexts or below.
context | $context | Context that the user requested search from |
array | Array from order name => display text |
Reimplemented from core_search\engine.
|
inherited |
Returns user data checking the internal static cache.
Including here the minimum required user information as this may grow big.
int | $userid |
stdClass |
|
protected |
Processes grouped file results into documents, with attached matching files.
SolrObject | $response | The response returned from solr server |
int | $limit | The maximum number of results to return. 0 for all. |
array | Final results to be displayed. |
search_solr\engine::has_alternate_configuration | ( | ) |
Checks if an alternate configuration has been defined.
bool | True if alternate configuration is available |
Reimplemented from core_search\engine.
|
inherited |
Run any post indexing operations.
Should be overwritten if the search engine needs to do any post index cleanup.
int | $numdocs | The number of documents that were added to the index |
bool | $fullindex | True if a full index was performed |
void |
|
inherited |
Run any pre-indexing operations.
Should be overwritten if the search engine needs to do any pre index preparation.
bool | $fullindex | True if a full index will be performed |
void |
search_solr\engine::is_installed | ( | ) |
Checks if the PHP Solr extension is available.
bool |
Reimplemented from core_search\engine.
search_solr\engine::is_server_configured | ( | ) |
Is the solr server properly configured?.
true|string | Returns true if all good or an error string. |
search_solr\engine::is_server_ready | ( | ) |
Pings the Solr server using search_solr config.
true|string | Returns true if all good or an error string. |
Reimplemented from core_search\engine.
search_solr\engine::merge_highlight_field_values | ( | $doc, | |
$highlighteddoc ) |
Adds the highlighting array values to docs array values.
core_search\engine_exception |
object | $doc | containing the results. |
object | $highlighteddoc | containing the highlighted results values. |
|
inherited |
Optimizes the search engine.
Should be overwritten if the search engine can optimize its contents.
void |
|
protected |
Index files attached to the docuemnt, ensuring the index matches the current document files.
For documents that aren't known to be new, we check the index for existing files.
document | $document |
|
protected |
Filters the response on Moodle side.
SolrObject | $response | Solr object containing the response return from solr server. |
int | $limit | The maximum number of results to return. 0 for all. |
bool | $skipaccesscheck | Don't use check_access() on results. Only to be used when results have known access. |
array\$results | containing final results to be displayed. |
|
inherited |
Usually called by the engine; marks that the schema has been updated.
int | $version | Records the schema version now applied |
|
staticprotected |
Replaces underlines at edges of words in the content with spaces.
For example 'frogs' will become 'frogs', 'frogs and toads' will become 'frogs and toads', and 'frogs_and_toads' will be left as 'frogs_and_toads'.
The reason for this is that for italic content_to_text puts italic underlines at the start and end of the italicised phrase (not between words). Solr treats underlines as part of the word, which means that if you search for a word in italic then you can't find it.
string | $str | String to replace |
string | Replaced string |
|
protected |
Prepares a new query by setting the query, start offset and rows to return.
SolrQuery | $query | |
object | $q | Containing query and filters. |
|
protectedinherited |
For use by subclasses.
The engine can call this inside is_server_ready to check whether it should skip time-consuming schema checks.
bool | True if schema checks should be skipped |
|
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.
bool | $skip | True to skip the checks, false to start checking again |
search_solr\engine::standarize_solr_obj | ( | \SolrObject | $obj | ) |
Returns a standard php array from a SolrObject instance.
SolrObject | $obj |
array | The returned document as an array. |
search_solr\engine::supports_add_document_batch | ( | ) |
Solr supports adding documents in a batch.
bool | True |
Reimplemented from core_search\engine.
search_solr\engine::supports_group_filtering | ( | ) |
Solr includes group support in the execute_query function.
bool | True |
Reimplemented from core_search\engine.
search_solr\engine::supports_users | ( | ) |
|
protectedinherited |
Returns a document instance prepared to be rendered.
core_search\base | $searcharea | |
array | $docdata |
core_search\document |
|
protected |
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.
int | $oldversion | Old schema version |
int | $newversion | New schema version |
bool|string | True if schema is updated successfully, a string if it needs updating manually |
Reimplemented from core_search\engine.
|
staticprotectedinherited |
User data required to show their fullnames.
Indexed by userid.
const search_solr\engine::FRAG_SIZE = 510 |
Highlighting fragsize.
Slightly larger than output size (500) to allow for ... appending.