Represents a document to index.
More...
|
| __construct ($itemid, $componentname, $areaname) |
| We ensure that the document has a unique id across search areas.
|
|
| add_stored_file ($file) |
| Add a stored file to the document.
|
|
| export_doc (\renderer_base $output) |
| Returns the current docuement information.
|
|
| export_for_engine () |
| Returns the document ready to submit to the search engine.
|
|
| export_for_template (\renderer_base $output) |
| Export the document data to be used as a template context.
|
|
| get ($field) |
| Getter.
|
|
| get_context_url () |
| Gets the url to the context.
|
|
| get_doc_icon () |
| Gets document icon instance.
|
|
| get_doc_url () |
| Gets the url to the doc.
|
|
| get_files () |
| Returns the array of attached files.
|
|
| get_is_new () |
| Returns if the document is new.
|
|
| is_set ($field) |
| Checks if a field is set.
|
|
| set ($fieldname, $value) |
| Setter.
|
|
| set_context_url (\moodle_url $url) |
|
| set_data_from_engine ($docdata) |
| Fills the document with data coming from the search engine.
|
|
| set_doc_icon (document_icon $docicon) |
| Sets document icon instance.
|
|
| set_doc_url (\moodle_url $url) |
| Sets the document url.
|
|
| set_extra ($fieldname, $value) |
| Sets data to this->extradata.
|
|
| set_is_new ($new) |
| Set if this is a new document.
|
|
|
int const | SCHEMA_VERSION = 2017091700 |
| Change list (for engine implementers): 2017091700 - add optional field groupid.
|
|
|
| apply_defaults () |
| Apply any defaults to unset fields before export.
|
|
| format_text ($text) |
| Formats a text string coming from the search engine.
|
|
| get_text_format () |
| Returns how text is returned from the search engine.
|
|
|
int null | $contentfilearea = null |
| The content field filearea.
|
|
int null | $contentitemid = null |
| The content field itemid.
|
|
moodle_url | $contexturl = null |
| Link to the document context.
|
|
array | $data = array() |
| $data The document data.
|
|
core_search document_icon | $docicon = null |
| Document icon instance.
|
|
moodle_url | $docurl = null |
| Link to the document.
|
|
array | $extradata = array() |
| Extra data needed to render the document.
|
|
stored_file[] | $files = array() |
| An array of stored files to attach to the document.
|
|
bool | $isnew = false |
| Should be set to true if document hasn't been indexed before.
|
|
Represents a document to index.
Note that, if you are writting a search engine and you want to change core_search\document behaviour, you can overwrite this class, will be automatically loaded from search_YOURENGINE::document.
- Copyright
- 2015 David Monllao
- License
- http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
◆ __construct()
core_search\document::__construct |
( |
| $itemid, |
|
|
| $componentname, |
|
|
| $areaname ) |
We ensure that the document has a unique id across search areas.
- Parameters
-
int | $itemid | An id unique to the search area |
string | $componentname | The search area component Frankenstyle name |
string | $areaname | The area name (the search area class name) |
- Return values
-
◆ add_stored_file()
core_search\document::add_stored_file |
( |
| $file | ) |
|
Add a stored file to the document.
- Parameters
-
- Return values
-
◆ apply_defaults()
core_search\document::apply_defaults |
( |
| ) |
|
|
protected |
Apply any defaults to unset fields before export.
Called after document building, but before export.
Sub-classes of this should make sure to call parent::apply_defaults().
Reimplemented in search_solr\document.
◆ export_doc()
core_search\document::export_doc |
( |
\renderer_base | $output | ) |
|
Returns the current docuement information.
Adding more info than the required one as themers and ws clients might be interested in showing more stuff.
Although content is a required field when setting up the document, it accepts '' (empty) values as they may be the result of striping out HTML.
SECURITY NOTE: It is the responsibility of the document to properly escape any text to be displayed. The renderer will output the content without any further cleaning.
- Parameters
-
renderer_base | $output | The renderer. |
- Return values
-
◆ export_for_engine()
core_search\document::export_for_engine |
( |
| ) |
|
Returns the document ready to submit to the search engine.
- Exceptions
-
- Return values
-
◆ export_for_template()
core_search\document::export_for_template |
( |
\renderer_base | $output | ) |
|
Export the document data to be used as a template context.
Just delegates all the processing to export_doc_info, also used by external functions. Adding more info than the required one as people might be interested in extending the template.
- Parameters
-
renderer_base | $output | The renderer. |
- Return values
-
◆ format_string_for_engine()
static core_search\document::format_string_for_engine |
( |
| $string | ) |
|
|
static |
Formats a string value for the search engine.
Search engines may overwrite this method to apply restrictions, like limiting the size. The default behaviour is just returning the string.
- Parameters
-
- Return values
-
Reimplemented in search_solr\document.
◆ format_text()
core_search\document::format_text |
( |
| $text | ) |
|
|
protected |
Formats a text string coming from the search engine.
By default just return the text as it is:
- Search areas are responsible of sending just plain data, the search engine may append HTML or markdown to it (highlighing for example).
- The view is responsible of shortening the text if it is too big
- Parameters
-
string | $text | Text to format |
- Return values
-
string | HTML text to be renderer |
Reimplemented in search_solr\document.
◆ format_text_for_engine()
static core_search\document::format_text_for_engine |
( |
| $text | ) |
|
|
static |
Formats a text value for the search engine.
Search engines may overwrite this method to apply restrictions, like limiting the size. The default behaviour is just returning the string.
- Parameters
-
- Return values
-
◆ format_time_for_engine()
static core_search\document::format_time_for_engine |
( |
| $timestamp | ) |
|
|
static |
Formats the timestamp preparing the time fields to be inserted into the search engine.
By default it just returns a timestamp so any search engine could just store integers and use integers comparison to get documents between x and y timestamps, but search engines might be interested in using their own field formats. They can do it extending this class in search_xxx::document.
- Parameters
-
- Return values
-
Reimplemented in search_solr\document.
◆ get()
core_search\document::get |
( |
| $field | ) |
|
Getter.
Use self::is_set if you are not sure if this field is set or not as otherwise it will trigger a coding_exception
- Exceptions
-
- Parameters
-
- Return values
-
◆ get_context_url()
core_search\document::get_context_url |
( |
| ) |
|
Gets the url to the context.
- Return values
-
◆ get_default_fields_definition()
static core_search\document::get_default_fields_definition |
( |
| ) |
|
|
static |
Returns all default fields definitions.
- Return values
-
◆ get_doc_icon()
core_search\document::get_doc_icon |
( |
| ) |
|
Gets document icon instance.
- Return values
-
◆ get_doc_url()
core_search\document::get_doc_url |
( |
| ) |
|
Gets the url to the doc.
- Return values
-
◆ get_files()
core_search\document::get_files |
( |
| ) |
|
Returns the array of attached files.
- Return values
-
◆ get_is_new()
core_search\document::get_is_new |
( |
| ) |
|
Returns if the document is new.
False if unknown.
- Return values
-
◆ get_text_format()
core_search\document::get_text_format |
( |
| ) |
|
|
protected |
Returns how text is returned from the search engine.
- Return values
-
Reimplemented in search_solr\document.
◆ import_time_from_engine()
static core_search\document::import_time_from_engine |
( |
| $time | ) |
|
|
static |
Returns a timestamp from the value stored in the search engine.
By default it just returns a timestamp so any search engine could just store integers and use integers comparison to get documents between x and y timestamps, but search engines might be interested in using their own field formats. They should do it extending this class in search_xxx::document.
- Parameters
-
- Return values
-
Reimplemented in search_solr\document.
◆ is_set()
core_search\document::is_set |
( |
| $field | ) |
|
Checks if a field is set.
- Parameters
-
- Return values
-
◆ set()
core_search\document::set |
( |
| $fieldname, |
|
|
| $value ) |
Setter.
Basic checkings to prevent common issues.
If the field is a string tags will be stripped, if it is an integer or a date it will be casted to a PHP integer. tdate fields values are expected to be timestamps.
- Exceptions
-
- Parameters
-
string | $fieldname | The field name |
string | int | $value | The value to store |
- Return values
-
string|int | The stored value |
◆ set_data_from_engine()
core_search\document::set_data_from_engine |
( |
| $docdata | ) |
|
Fills the document with data coming from the search engine.
- Exceptions
-
- Parameters
-
- Return values
-
◆ set_doc_icon()
Sets document icon instance.
- Parameters
-
◆ set_doc_url()
core_search\document::set_doc_url |
( |
\moodle_url | $url | ) |
|
Sets the document url.
- Parameters
-
- Return values
-
◆ set_extra()
core_search\document::set_extra |
( |
| $fieldname, |
|
|
| $value ) |
Sets data to this->extradata.
This data can be retrieved using core_search\document->get($fieldname).
- Parameters
-
string | $fieldname | |
string | $value | |
- Return values
-
◆ set_is_new()
core_search\document::set_is_new |
( |
| $new | ) |
|
Set if this is a new document.
False if unknown.
- Parameters
-
◆ $enginefields
array core_search\document::$enginefields = array() |
|
staticprotected |
Any fields that are engine specifc.
These are fields that are solely used by a search engine plugin for internal purposes.
Field names should be prefixed with engine name to avoid potential conflict with core fields.
Uses same format as fields above.
◆ $isnew
bool core_search\document::$isnew = false |
|
protected |
Should be set to true if document hasn't been indexed before.
False if unknown.
◆ $optionalfields
array core_search\document::$optionalfields |
|
staticprotected |
Initial value:= array(
'userid' => array(
'type' => 'int',
'stored' => true,
'indexed' => true
),
'groupid' => array(
'type' => 'int',
'stored' => true,
'indexed' => true
),
'description1' => array(
'type' => 'text',
'stored' => true,
'indexed' => true,
'mainquery' => true
),
'description2' => array(
'type' => 'text',
'stored' => true,
'indexed' => true,
'mainquery' => true
)
)
All optional fields docs can contain.
Although it matches solr fields format, this is just to define the field types. Search engine plugins are responsible of setting their appropriate field types and map these naming to whatever format they need.
◆ $requiredfields
array core_search\document::$requiredfields |
|
staticprotected |
All required fields any doc should contain.
We have to choose a format to specify field types, using solr format as we have to choose one and solr is the default search engine.
Search engine plugins are responsible of setting their appropriate field types and map these naming to whatever format they need.
◆ SCHEMA_VERSION
int const core_search\document::SCHEMA_VERSION = 2017091700 |
Change list (for engine implementers): 2017091700 - add optional field groupid.
Schema version number (update if any change)
The documentation for this class was generated from the following file:
- search/classes/document.php