E
E
Evgeny Osipov2020-01-14 15:59:59
1C-Bitrix
Evgeny Osipov, 2020-01-14 15:59:59

How can Bitrix search by the property of an infoblock of the File/Multiple type?

Good afternoon.
There are two properties of one infoblock: HTML/text and File (Multiple)
Both property values ​​are involved in the search, reindexing was done.
The text from the HTML/text field in the search is found, but if you enter the name of the file that is loaded in File (Multiple) it does not find it.
What needs to be done to find a product in which a file with a specific name is loaded?
Search code:

spoiler
<?$APPLICATION->IncludeComponent(
   "bitrix:search.page", 
   "search", 
   array(
      "RESTART" => "Y",
      "NO_WORD_LOGIC" => "Y",
      "CHECK_DATES" => "Y",
      "USE_TITLE_RANK" => "Y",
      "DEFAULT_SORT" => "rank",
      "FILTER_NAME" => "",
      "arrFILTER" => array(
         0 => "iblock_aspro_priority_catalog",
         1 => "iblock_aspro_priority_content",
      ),
      "arrFILTER_iblock_aspro_priority_catalog" => array(
         0 => "34",
      ),
      "arrFILTER_iblock_aspro_priority_content" => array(
         0 => "all",
      ),
      "SHOW_WHERE" => "N",
      "SHOW_WHEN" => "N",
      "PAGE_RESULT_COUNT" => "50",
      "AJAX_MODE" => "N",
      "AJAX_OPTION_JUMP" => "Y",
      "AJAX_OPTION_STYLE" => "Y",
      "AJAX_OPTION_HISTORY" => "N",
      "CACHE_TYPE" => "N",
      "CACHE_TIME" => "3600",
      "DISPLAY_TOP_PAGER" => "N",
      "DISPLAY_BOTTOM_PAGER" => "Y",
      "PAGER_TITLE" => "Результаты поиска",
      "PAGER_SHOW_ALWAYS" => "N",
      "PAGER_TEMPLATE" => "",
      "USE_LANGUAGE_GUESS" => "Y",
      "USE_SUGGEST" => "Y",
      "SHOW_RATING" => "",
      "RATING_TYPE" => "",
      "PATH_TO_USER_PROFILE" => "",
      "AJAX_OPTION_ADDITIONAL" => "",
      "COMPONENT_TEMPLATE" => "search",
      "COMPOSITE_FRAME_MODE" => "A",
      "COMPOSITE_FRAME_TYPE" => "AUTO"
   ),
   false
);?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2020-01-14
@Medik18

It is necessary to write the handler in init.php
So I threw it offhand, maybe there is a better way, otherwise in my example I have to make a request for each IB element (this at least increases the reindexing time)

$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->addEventHandler('search', 'BeforeIndex', array('MySearch', 'BeforeIndex'));

class MySearch {
  public static function BeforeIndex($arFields) {
    if(intval($arFields['PARAM2']) > 0 && intval($arFields['ITEM_ID']) > 0 && isset($arFields['BODY'])) {
      \Bitrix\Main\Loader::includeModule('iblock');
      
      $dbRes = CIBlockElement::GetList(array(), array('IBLOCK_ID' => $arFields['PARAM2'], 'ID' => $arFields['ITEM_ID']), false, false, array('PROPERTY_FILE'));
      while($arRes = $dbRes->Fetch()) {
        $arFile = CFile::GetFileArray($arRes['PROPERTY_FILE_VALUE']);
        $arFields['BODY'] .= PHP_EOL.$arFile['ORIGINAL_NAME'];
      }
      
      return $arFields;
    }
  }
}

In the check , instead of > 0, you can specify == ID of the infoblock, if it is necessary for a particular IB Instead , respectivelyintval($arFields['PARAM2']) > 0
array('PROPERTY_FILE')array('PROPERTY_свое ID свойства')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question