1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / AutoIndex CustomIndex

AutoIndex CustomIndex

2 posts, 0 answered
  1. KMac
    KMac avatar
    133 posts
    Registered:
    15 Dec 2008
    20 Jan 2010
    Link to this post
    Hello,

    Quick question. How do I set a customIndex provider to autoindex? I currently have an customIndex that indexes documents in a library and I want it to either reindex after a new item is added or at least at specific time intervals.

    Thanks in advance,

    Kalvin
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    20 Jan 2010
    Link to this post
    Hello KMac,

    In the provider class override Initialize. Subscribe for Executed event of ContentManager and run the index if an item is created, updated, deleted

    sample code

    protected virtual void ContentProvider_Executed(object sender, ExecutedEventArgs e)
    {
        switch (e.CommandName)
        {
            case "UpdateContent":
            case "CreateContent":
      
                IContent content = (IContent)e.Data;
                if (content.Status != ContentStatus.Published)
                    return;
      
                    IIndexerInfo[] info;
                    if (this.manager.Provider.AllowLocalization)
                    {
                        CultureInfo cult = CultureInfo.GetCultureInfo(content.Language);
                        string path = this.GetItemUrl(content, this.baseUrl, cult);
                        info = new IIndexerInfo[] { this.GetIndexerInfo(path, content, cult) };
                    }
                    else
                    {
                        string path = this.GetItemUrl(content, this.baseUrl, null);
                        info = new IIndexerInfo[] { this.GetIndexerInfo(path, content) };
                    }
                    this.OnIndex(new IndexEventArgs(info));
      
                break;
      
            case "DeleteContent":
                Guid itemId = e.ItemID;
      
                if (itemId != Guid.Empty)
                    this.OnIndex(new IndexEventArgs("DeleteIndex", new Guid[] { itemId }));
      
                break;
      
            default:
                break;
        }
      
    }
            

        protected
    virtual void OnIndex(IndexEventArgs args)
     {
     if (this.Index != null)
       this.Index(this, args);
        }
     
     public event EventHandler<IndexEventArgs> Index;


    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
2 posts, 0 answered