The IndexCrawler

Last updated Thursday, October 22, 2015 in Sitecore Experience Platform for Developer
Keywords: Development, Search

The IndexCrawler is a crawler that takes an existing index and executes a group of functions over it.

The IndexCrawler inherits from the FlatDataCrawler<T>. This means that you can pass a list of IIndexables and it iterates over them, then executes a function on each IIndexable and commits it back to the index.

This an example of what you can use it for: Go through every document in the index and add “!!” to the name of every document. The code would look like this:

var crawler = new IndexCrawler(this.sourceIndexName);
crawler.CrawlFunctions += this.CallMe;
public IEnumerable<IIndexable> CallMe(IProviderSearchContext context)
    var list = new List<IIndexable>();
    foreach (var item in context.GetQueryable<InsertDocument>())
        item.Name = item.Name + "!!";
        list.Add(new ObjectIndexable(item, null));
    return list.AsEnumerable();