diff --git a/lang/en/search.php b/lang/en/search.php index 096722d5a91d8..ebd0f5a32e7b4 100644 --- a/lang/en/search.php +++ b/lang/en/search.php @@ -51,6 +51,7 @@ $string['enginenotselected'] = 'You have not selected any search engine.'; $string['engineserverstatus'] = 'The search engine is not available. Please contact your administrator.'; $string['enteryoursearchquery'] = 'Enter your search query'; +$string['error_indexing'] = 'An error occurred while indexing'; $string['errors'] = 'Errors'; $string['errorareanotavailable'] = '{$a} search area is not available.'; $string['filesinindexdirectory'] = 'Files in index directory'; diff --git a/search/classes/document.php b/search/classes/document.php index 97cdc7b93969c..64831b189c9b3 100644 --- a/search/classes/document.php +++ b/search/classes/document.php @@ -280,6 +280,16 @@ public function set($fieldname, $value) { } else { // Replace all groups of line breaks and spaces by single spaces. $this->data[$fieldname] = preg_replace("/\s+/u", " ", $value); + if ($this->data[$fieldname] === null) { + if (isset($this->data['id'])) { + $docid = $this->data['id']; + } else { + $docid = '(unknown)'; + } + throw new \moodle_exception('error_indexing', 'search', '', null, '"' . $fieldname . + '" value causes preg_replace error (may be caused by unusual characters) ' . + 'in document with id "' . $docid . '"'); + } } return $this->data[$fieldname];