php 带索引的bitrix搜索
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 带索引的bitrix搜索相关的知识,希望对你有一定的参考价值。
<?
AddEventHandler("search", "BeforeIndex", "BeforeIndexHandler");
function BeforeIndexHandler($arFields) {
//BODY
$arrIblock = array(11);
if ($arFields["MODULE_ID"] == 'iblock' && in_array($arFields["PARAM2"], $arrIblock) && intval($arFields["ITEM_ID"]) > 0){
$dbElement = CIblockElement::GetByID($arFields["ITEM_ID"]) ;
if ($arElement = $dbElement->Fetch()) {
$arFields["BODY"] = $arElement['DETAIL_TEXT'];
// echo $arFields["BODY"]; exit;
}
}
//TITLE
$words = [];
$arFields['TITLE'] = trim($arFields['TITLE']);
if (preg_grep('/-/', explode("\n", $arFields['TITLE']))) {
$words[] = preg_replace('/-/', '', $arFields['TITLE']);
}
$masks = [
'/.*?([0-9]+).*?/i',
'/.*?([0-9a-zA-Z.,]+).*?/i',
];
//preg_match('/([x*х])/i', $input_line, $output_array);
foreach ($masks as $mask) {
preg_match_all($mask, $arFields['TITLE'], $tags);
if (isset($tags[1])) {
foreach ($tags[1] as $tag) {
if (!in_array($tag, $words) && strlen($tag) > 1) {
$words[] = trim($tag);
}
}
}
}
preg_match_all('/(?<sizes>[0-9,.]+[x|*|х][0-9,.]+[x|*|х][0-9,.]+)/iu', $arFields['TITLE'], $matches);
$synonyms = ['', 'x', '*', 'х'];
$searchSizes = [];
if ($matches['sizes']) {
$searchSizes = [];
foreach ($matches['sizes'] as $size) {
preg_match_all('/(?<num1>[0-9,.]+)(?<op1>[x|*|х])(?<num2>[0-9,.]+)(?<op2>[x|*|х])(?<num3>[0-9,.]+)/iu', $size, $elements);
$arrNum[] = $elements['num1'][0];
$arrNum[] = $elements['num2'][0];
$arrNum[] = $elements['num3'][0];
$isHasSeparator = preg_grep('/[.,]/iu', explode("\n", $size));
foreach ($synonyms as $operator) {
$newSize = implode($operator, $arrNum);
if (!in_array($newSize, $searchSizes)) {
$searchSizes[] = $newSize;
}
if ($isHasSeparator) {
$temp = preg_replace('/[.,]/iu', '', $newSize);
if (!in_array($temp, $searchSizes)) {
$searchSizes[] = $temp;
}
$temp = preg_replace('/[.]/iu', ',', $newSize);
if (!in_array($temp, $searchSizes)) {
$searchSizes[] = $temp;
}
$temp = preg_replace('/[,]/iu', '.', $newSize);
if (!in_array($temp, $searchSizes)) {
$searchSizes[] = $temp;
}
}
}
}
}
if ($searchSizes) {
$arFields['TITLE'] = $arFields['TITLE'].' '.implode(' ', $searchSizes);
}
if ($words) {
$arFields['TITLE'] = $arFields['TITLE'].' '.implode(' ', $words);
}
return $arFields;
}
以上是关于php 带索引的bitrix搜索的主要内容,如果未能解决你的问题,请参考以下文章