В продолжении темы индексации контента из сторонней БД.
Я создал класс [B]MyClass[/B], пометил его аттрибутом [B][BXMessageReceiver][/B]. Для перехвата события [B]Bitrix.Search.IndexAll[/B] я использую статический метод [B]void ReIndex(BXCommand command)[/B].
При полной переиндексации я проверял - метод отрабатывает. Но поиск не работает.
Мои наблюдения.
В БД битрикса в таблице b_Search_Content(в которой как я понял содержится индексированный контент) появляются строки с моим индексированным контентом. Но в таблице b_Search_ContentStemIndex, b_Search_ContentSites новые строки не появляются.
Помогите, пожалуйста, разобраться в чем причина.
[CODE][BXMessageReceiver]
public class MyClass
{
public MyClass()
{ }
public static DataTable GetData()
{
DataTable dt = new DataTable();
SqlDataAdapter sa = new SqlDataAdapter(@"
SELECT [ID]
,[Title]
,[H1Title]
,[Keys]
,[Html]
,[HtmlBottom]
FROM [MyTable]
", ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString);
sa.Fill(dt);
return dt;
return dt;
}
internal static BXCommandResult IndexContent(Int32 Id, String Title, String H1Title, String Keys, String Html1, String Html2)
{
BXCommandResult result = new BXCommandResult(BXCommandResultType.Ok);
try
{
Html1 = HttpUtility.HtmlDecode(BXStringUtility.StripOffSimpleTags(
BXStringUtility.StripOffStyleTag(BXStringUtility.StripOffScriptTag(Html1)))).Trim();
Html2 = HttpUtility.HtmlDecode(BXStringUtility.StripOffSimpleTags(
BXStringUtility.StripOffStyleTag(BXStringUtility.StripOffScriptTag(Html2)))).Trim();
BXCommand command = new BXCommand("Bitrix.Search.IndexContent");
command.Parameters.Add("title", Title);
if (!string.IsNullOrEmpty(Html1) && !string.IsNullOrEmpty(Html2))
{
Html1 = Html1 + " ... ";
}
command.Parameters.Add("body", Html1 + Html2);
command.Parameters.Add("contentDate", DateTime.Now);
command.Parameters.Add("moduleId", "mymodule");
command.Parameters.Add("itemGroup", "");
command.Parameters.Add("itemId", Id);
command.Parameters.Add("param1", "");
command.Parameters.Add("sites", BXSite.GetDefaultSite());
Keys = HttpUtility.HtmlDecode(BXStringUtility.StripOffSimpleTags(
BXStringUtility.StripOffStyleTag(BXStringUtility.StripOffScriptTag(Keys)))).Trim();
command.Parameters.Add("tags", !BXStringUtility.IsNullOrTrimEmpty(Keys) ? Keys.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) : new string[0]);
command.Send();
}
catch (Exception exception)
{
result.CommandResult = BXCommandResultType.Error;
result.Exception = exception;
result.Result = exception.Message;
BXLogService.LogAll(exception, BXLogMessageType.Error, "Reindex error " + Id.ToString());
}
return result;
}
[BXEventListener("Bitrix.Search.IndexAll")]
public static void ReIndex(BXCommand command)
{
BXCommandResult result;
if (string.Equals(command.Action, "Bitrix.Search.IndexAll", StringComparison.InvariantCultureIgnoreCase))
{
try
{
DataTable dt = MyClass.GetData();
if (dt.Rows.Count != 0)
{
foreach (DataRow r in dt.Rows)
{
result = MyClass.IndexContent(Convert.ToInt32(r["ID"]), "" + r["Title"], "" + r["H1Title"],
"" + r["Keys"], "" + r["Html"], "" + r["HtmlBottom"]);
command.CommandResultDictionary.Add(command.CommandResultDictionary.Count.ToString(), result);
}
}
command.Callback(new object[] { "DelfinTourModule", string.Empty, true });
}
catch (Exception exception)
{
command.Callback(new object[] { "DelfinTourModule", string.Empty, false });
BXLogService.LogAll(exception, BXLogMessageType.Error, "Search Reindex (MyModule)");
}
}
}
}[/CODE]