Bitrix Site Manager

CSearch::CSearch

CDBResult
CSearch(
 string strQuery [, 
 string LID [, 
 string MODULE_ID [, 
 string ITEM_ID [, 
 string PARAM1 [, 
 string PARAM2]]]]]
);

The CSearch constructor returns index records satisfying the passed query string and parameters. The record returned if only if the current user has permissions to access this information.

Parameters

ParameterDescription
strQuery Query string. Must comply the query language.
LID Site where the search is to be performed. If set to false (default), the method affects elements in all sites.
MODULE_ID The ID of the module index of which is to be search. If set to false (default), the method searches all index.
ITEM_ID Code of the indexed element. Used to restrict searches to elements with this code. If set to false (default), the method searches all index.
PARAM1 Parameter of elements which are to be searched. If set to false (default), the method searches all index.
PARAM2 Same as PARAM1.

Return Values

Set of records; each record has the following structure:

Array(
   [ID] => Index ID
   [DATE_CHANGE] => indexed element modification date
   [MODULE_ID] => module to which the element pertains
   [ITEM_ID] => Element ID
   [LID] => Site ID
   [URL] => Path of the element, relative to the site root (HTML-safe)
   [TITLE] => Element title (HTML-safe)
   [BODY] => Element text (HTML-safe)
   [SEARCHABLE_CONTENT] => Element index (HTML-safe)
   [PARAM1] => Element parameter
   [PARAM2] => Element parameter
   [~URL] => Path of the element, relative to the site root 
   [~TITLE] => element title
   [~BODY] => element text
   [~SEARCHABLE_CONTENT] => element index
   [TITLE_FORMATED] => Element title with words selected
   [BODY_FORMATED] => Element text with words selected
)

Example

Search a string in the forum of the current site.

<?
$q = "oyster or cod fillet";
$module_id = "forum"
$obSearch = new CSearch($q, LANG, $module_id);
if ($obSearch->errorno!=0):
  ?>
  <font class="text">Error in search string:</font>
  <?echo ShowError($obSearch->error);?>
  <font class="text">Fix the query and try again.</font>
  <?
else:
  while($arResult = $obSearch->GetNext())
  {
    <a href="<?echo $arResult["URL"]?>"><?echo $arResult["TITLE_FORMATED"]?></a><br>
    <?echo $arResult["BODY_FORMATED"]?><br>
    <hr size="1" color="#DFDFDF">
  }
endif;
?>