• Модуль: landing
  • Путь к файлу: ~/bitrix/modules/landing/lib/dataloader/landing.php
  • Класс: BitrixLandingDataLoaderLanding
  • Вызов: Landing::getSearchSnippet
protected function getSearchSnippet(string $query, string $content): string
{
	$isUtf = defined('BX_UTF') && BX_UTF === true;

	if (!$isUtf)
	{
		[$content, $query] = BitrixMainTextEncoding::convertEncoding(
			[$content, $query], SITE_CHARSET, 'UTF-8'
		);
	}

	$phrases = explode(' ', $query);
	trimArr($phrases, true);
	$newContent = '';
	$snippetOffset = 50;

	foreach ($phrases as $phrase)
	{
		$phrasePos = mb_strpos(mb_strtolower($content), mb_strtolower($phrase));
		if ($phrasePos === false)
		{
			continue;
		}
		$newContent .= (($phrasePos > $snippetOffset) ? ' ...' : ' ') .
						mb_substr(
							$content,
							($phrasePos > $snippetOffset) ? $phrasePos - $snippetOffset : 0,
							$phrasePos + mb_strlen($phrase) + $snippetOffset
						) .
						'... ';
	}

	if (!$isUtf)
	{
		$newContent = BitrixMainTextEncoding::convertEncoding(
			$newContent, 'UTF-8', SITE_CHARSET
		);
	}

	return $newContent;
}