Documentation

OnReIndex

bool
handler function( array NS, string oCallback, string callback_method );

"OnReindex" event is called during the re-indexing of the module data by the CSearch::ReindexModule or CSearch::ReIndexAll methods.

Parameters

Parameter Description
NS Array in which the data about the start of the current step is passed.
  • MODULE - module ID;
  • ID - element ID;
  • SITE_ID - array of sites;
oCallback Search module object to call the lement indexing method.
callback_method Method for the search module object to index an element.

See Also

Example of handler function:

<?

// register the "OnReindex" event handler of the "search" module
RegisterModuleDependences("search", "OnReindex", "my_module", "CMyModule", "OnReindex");

// create method-function OnReindex in the my_module, in the CMyModule class
public static function OnReindex($NS, $oCallback, $callback_method)
{
global $DB;

$NS["ID"] = intval($NS["ID"]);
if($NS["MODULE"]=="my_module" && $NS["ID"] > 0)
$strWhere = "WHERE ID > ".$NS["ID"];
else
$strWhere = "";

$strSql =
"SELECT FT.ID, FT.TITLE, FT.MESSAGE, ".
" DATE_FORMAT(FT.POST_DATE, '%d.%m.%Y %H:%i:%s') as POST_DATE, FT.LID ".
"FROM b_my_table FT ".
$strWhere.
" ORDER BY FT.ID";

$db_res = $DB->Query($strSql);
while ($res = $db_res->Fetch())
{
$Result = array(
"ID" => $res["ID"],
"SITE_ID" => array("s1"),
"DATE_CHANGE" => $res["POST_DATE"],
"URL" => "/my_module/index.php?ID=".$res["ID"],
"PERMISSIONS" => array(2),
"TITLE" => $res["TITLE"],
"BODY" => $res["MESSAGE"],
);
$index_res = call_user_func(array($oCallback, $callback_method), $Result);
if(!$index_res)
return $Result["ID"];
}
return false;
}

// call the module re-indexing
CSearch::ReIndexModule("my_module");

?>


© «Bitrix24», 2001-2024
Up