public function SearchTextProcessor::analyze in Drupal 10
Same name and namespace in other branches
- 9 core/modules/search/src/SearchTextProcessor.php \Drupal\search\SearchTextProcessor::analyze()
File
- core/modules/search/src/SearchTextProcessor.php, line 64
Class
- SearchTextProcessor
- Processes search text for indexing.
Namespace
Drupal\search
Code
public function analyze(string $text, ?string $langcode = NULL) : string {
$text = Html::decodeEntities($text);
$text = mb_strtolower($text);
$text = $this->transliteration
->removeDiacritics($text);
$this
->invokePreprocess($text, $langcode);
if ($this->configFactory
->get('search.settings')
->get('index.overlap_cjk')) {
$text = preg_replace_callback('/[' . self::PREG_CLASS_CJK . ']+/u', [
$this,
'expandCjk',
], $text);
}
$text = preg_replace('/([' . self::PREG_CLASS_NUMBERS . ']+)[' . self::PREG_CLASS_PUNCTUATION . ']+(?=[' . self::PREG_CLASS_NUMBERS . '])/u', '\\1', $text);
$text = preg_replace('/[.-]{2,}/', ' ', $text);
$text = preg_replace('/[._-]+/', '', $text);
$text = preg_replace('/[' . Unicode::PREG_CLASS_WORD_BOUNDARY . ']+/u', ' ', $text);
$words = explode(' ', $text);
array_walk($words, [
$this,
'truncate',
]);
$text = implode(' ', $words);
return $text;
}