A
A
Anastasia2018-04-18 16:03:39
1C-Bitrix
Anastasia, 2018-04-18 16:03:39

How to search by strict comparison in Bitrix?

Hello!
How to implement a search in Bitrix without taking into account morphology, by strict comparison, without searching for a part of a word.
That is, if you enter "12" in the search, only "12" was found, and not "1213" or "2112".

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anastasia, 2018-04-19
@haanastasia

It turned out that the search is carried out not only through the titles, but also through the description. Turning off the search by description and announcement - everything worked.
To do this, I added the code to the Init.php file

AddEventHandler("search", "BeforeIndex", "BeforeIndexHandler");
  function BeforeIndexHandler($arFields) {
      $arrIblock = array(айди инфоблока);
      $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;
      }
  }

And then launched a full re-indexing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question