L
L
lie22020-03-04 11:43:53
1C-Bitrix
lie2, 2020-03-04 11:43:53

How and where is the “BeforeIndex” event (before indexing) of an element called by the CSearch::Index method?

Good day!
I found an article: https://camouf.ru/blog-note/3081/ and everything seems to be clear, but I confused the text:

using the "BeforeIndex" event, which is called before the element is indexed by the CSearch::Index method

How and where can/should it be called BeforeIndex?
I wrote everything to the init file, I have 11 here, not 48 /// $arrIblock = array(48); ///
AddEventHandler("search", "BeforeIndex", "BeforeIndexHandler");
  function BeforeIndexHandler($arFields) {
      $arrIblock = array(48);
      $arDelFields = array("DETAIL_TEXT", "PREVIEW_TEXT") ;
      if (CModule::IncludeModule('iblock') && $arFields["MODULE_ID"] == 'iblock' && in_array($arFields["PARAM2"], $arrIblock) && intval($arFields["ITEM_ID"]) > 0){
      $dbElement = CIblockElement::GetByID($arFields["ITEM_ID"]) ;
      if ($arElement = $dbElement->Fetch()){
          foreach ($arDelFields as $value){
          if (isset ($arElement[$value]) && strlen($arElement[$value]) > 0){
              $arFields["BODY"] = str_replace (CSearch::KillTags($arElement[$value]) , "", CSearch::KillTags($arFields["BODY"]) );
              }
          }
      }
      return $arFields;
      }
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MiXaLiN17, 2020-03-04
@lie2

Run /bitrix/admin/search_reindex.php?lang=ru and it will work for you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question