• Модуль: search
  • Путь к файлу: ~/bitrix/modules/search/classes/general/search.php
  • Класс: CAllSearch
  • Вызов: CAllSearch::Repl
function Repl($strCond, $strType, $strWh)
{
	$l = mb_strlen($strCond);

	if ($this->Query->bStemming)
	{
		$arStemInfo = stemming_init($this->Query->m_lang);
		$pcreLettersClass = "[".$arStemInfo["pcre_letters"]."]";
		$strWhUpp = stemming_upper($strWh, $this->Query->m_lang);
	}
	else
	{
		$strWhUpp = ToUpper($strWh);
	}

	$strCondUpp = ToUpper($strCond);

	$pos = 0;
	do
	{
		$pos = mb_strpos($strWhUpp, $strCondUpp, $pos);

		//Check if we are in the middle of the numeric entity
		while (
			$pos !== false &&
			preg_match("/^[0-9]+;/", mb_substr($strWh, $pos)) &&
			preg_match("/^[0-9]+#&/", strrev(mb_substr($strWh, 0, $pos + mb_strlen($strCond))))
		)
		{
			$pos = mb_strpos($strWhUpp, $strCondUpp, $pos + 1);
		}

		if ($pos === false) break;

		if ($strType == "STEM")
		{
			$lw = mb_strlen($strWhUpp);
			for ($s = $pos; $s >= 0; $s--)
			{
				if (!preg_match("/$pcreLettersClass/".BX_UTF_PCRE_MODIFIER, mb_substr($strWhUpp, $s, 1)))
					break;
			}
			$s++;
			for ($e = $pos; $e < $lw; $e++)
			{
				if (!preg_match("/$pcreLettersClass/".BX_UTF_PCRE_MODIFIER, mb_substr($strWhUpp, $e, 1)))
					break;
			}
			$e--;
			$a = stemming(mb_substr($strWhUpp, $s, $e - $s + 1), $this->Query->m_lang, true);
			foreach ($a as $stem => $cnt)
			{
				if ($stem == $strCondUpp)
				{
					$strWh = mb_substr($strWh, 0, $pos)."%^%".mb_substr($strWh, $pos, $e - $pos + 1)."%/^%".mb_substr($strWh, $e + 1);
					$strWhUpp = mb_substr($strWhUpp, 0, $pos)."%^%".str_repeat(" ", $e - $pos + 1)."%/^%".mb_substr($strWhUpp, $e + 1);
					$pos += 7 + $e - $pos + 1;
				}
			}
		}
		else
		{
			$strWh = mb_substr($strWh, 0, $pos)."%^%".mb_substr($strWh, $pos, $l)."%/^%".mb_substr($strWh, $pos + $l);
			$strWhUpp = mb_substr($strWhUpp, 0, $pos)."%^%".str_repeat(" ", $l)."%/^%".mb_substr($strWhUpp, $pos + $l);
			$pos += 7 + $l;
		}
		$pos += 1;
	} while ($pos < mb_strlen($strWhUpp));

	return $strWh;
}