Indexing properly everything but.. tags ?

Topics: Troubleshooting, Writing modules
Mar 20, 2014 at 4:14 PM
I'm writing a LOB system using Orchard and have some problems with indexing. I use Orchard.Indexing for searching up the database of customers, but the problem is, the content is indexed once per certain amount of time and I want it to be indexed immediately after creating new customer, so the user can be able to search the database without any delay. So, after a quick research i decided to call method RebuildIndex (from IIndexService) from my controller. But... strange things happen, because the index is updated, and i can see new content item, but the tags part was not updated (of course, i checked "include in index"). The funniest thing is, that when i manually click "Rebuild Index" in the dashboard, everything's okay (and this controller is calling exactly the same method!)

Anybody has an idea, how can I solve this problem?
Thanks in advance!
Feb 4, 2015 at 6:29 PM
I don't know the answer to your concrete question about why the tags are not being indexed. But I know the pain of not being able to rely on index updates. Also, from what you emphasized, your use case is about immediately indexing new (or updated) content.

After some digging around in Orchard we've come up with the following code block:
public void UpdateIndexFor(IContent content) {

    var documentIndex = _indexProvider.New(content.Id);

    // call all handlers to add content to index
    _contentManager.Index(content.ContentItem, documentIndex);

    // save updated documents to the index, as seen in IndexingTaskExecutor line 241
    _indexProvider.Store("Search", documentIndex);
This code block needs an IIndexProvider, _indexProvider, and an IContentManager instance, _contentManager.

Side note: While this code will properly index a new content item or update a new one, it will also slow down whatever you're doing in the calling code. For example, we dropped this approach in favor of indexing content items in a background worker when importing new content because it was just too slow.