Sitecore -Как программно добавить элемент в пользовательский индекс - PullRequest
0 голосов
/ 26 мая 2019

Я создал свой собственный индекс в Sitecore с помощью FlatDataCrawler.Теперь я собираюсь добавить новый элемент (унаследованный от AbstractIndexable) в мой индекс.

private void Test() {
    var newItem = new ContactIndexable {
        Number = new System.Random().Next(500, 10000),
        MyField = "Item from IMPORTER"
    };
    var index = ContentSearchManager.GetIndex("my_index");
    using (var ctx = index.CreateUpdateContext()) {
        //This line doesn't work:
        ctx.Index.Operations.Add(newItem, index.CreateUpdateContext(), index.Configuration);
        index.Refresh(newItem);
    }

}

Вызов этого кода приводит к тому, что в моем пользовательском искателе вызывается только метод GetItemsToIndex, но элемент не добавляется вИндекс.

Итак, как я могу добавить новый элемент в свой пользовательский индекс из кода?

Этот метод работает правильно, и в индекс добавляется новый элемент:

protected override IEnumerable<ContactIndexable> GetItemsToIndex() {
    List<ContactIndexable> items = new List<ContactIndexable>() {
        new ContactIndexable()
        {
             MyField = "Created in crawler"
        }
    };
    return items;
}
...