<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/prolog_before.php");
?>
<?
if ((CModule::IncludeModule('search')) && (CModule::IncludeModule('iblock'))) {
$q = $_REQUEST['q'];
$obSearch = new CSearch;
$obSearch->Search(array(
"QUERY" => $q,
"SITE_ID" => LANG,
"MODULE_ID" => 'iblock',
"CHECK_DATES" => 'Y',
"PARAM2" => "6"
)
);
$result = array();
$aa=0;
while ($res = $obSearch->GetNext()) {
$id = $res['ITEM_ID'];
$grab = GetIBlockElement($id);
$image1 = CFile::GetPath($grab["PREVIEW_PICTURE"]);
$aa = $image1;
//если нашли раздел:
if (strripos($id, 'S') !== false) {
$result_item['TITLE'] = $res['TITLE'];
$result_item['URL'] = $res['URL'];
$result_item['BODY_FORMATED'] = $res['TITLE_FORMATED'];
$result[] = $result_item;
} //если S-ки нету, то
else {
$result_item['TITLE'] = $res['TITLE'];
$result_item['URL'] = $res['URL'];
$result_item['BODY_FORMATED'] = $res['BODY_FORMATED'];
$result[] = $result_item;
}
}
echo json_encode($aa);
}
?>