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

Forums / Developing with Sitefinity / Seach/Index API

Seach/Index API

7 posts, 0 answered
  1. Audreyn Justus
    Audreyn Justus avatar
    8 posts
    Registered:
    12 Oct 2005
    04 Jan 2010
    Link to this post
    I have a user control that reads a xml file e generates a output. Weekly this xml is uploaded to the site automatically by a database server.

    When the new xml is available the user control must detect this change (yet done) and trigger the reindex of the content page.

    I have tried some variations of the code bellow, but the result its not perfect. Looking the index structure with Lucene Luke its possible to see the differences between the records generated by the admin console (start indexing button) and the records produced by the user control - mainly in the fields indexed (for example GUID) and the url (~/contracts.aspx when done by admin console and http://domain/contracts.aspx when done by the user control - using the full url was the only way I get a index record to be created).

                string[] urls1 = new string[] { "~" + Request.Url.AbsolutePath };
                string[] urls2 = new string[] { Request.Url.AbsoluteUri };
                Telerik.Search.Engine.IndexingManager.DeleteDocumentsFromIndex(IndexProvider, urls1);
                Telerik.Search.Engine.IndexingManager.DeleteDocumentsFromIndex(IndexProvider, urls2);
                Telerik.Search.Engine.IndexingManager.StartIndexing(IndexProvider, urls2, true);

    What would be the correct code to reindex this page (or even the entire site) from inside a user control?

    Regards
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    05 Jan 2010
    Link to this post
    Hello Audreyn Justus,

    Here is how you can index the site from a user control:

    indexButton.CommandName = "Index";
    indexButton.CommandArgument = id;
    indexButton.Command += new CommandEventHandler(Service_Command);
    ...
     
    void Service_Command(object sender, CommandEventArgs e)
            {
                this.serviceId = new Guid((string)e.CommandArgument);
                switch (e.CommandName)
                {
                    case "Index":
                        IIndexingService service = new IndexingService(this.dataManager.GetService(serviceId));
                        int timeout = this.Context.Server.ScriptTimeout;
    this.Context.Server.ScriptTimeout = 4800;
    service.Index(false);
    this.Context.Server.ScriptTimeout = timeout;
    service.DisposeService();
        break;
    ...

    Your approach is correct though.

    Regards,
    Georgi
    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.
  3. Audreyn Justus
    Audreyn Justus avatar
    8 posts
    Registered:
    12 Oct 2005
    05 Jan 2010
    Link to this post
    Thank you Georgi

    It´s not clear to me in your code:

    The value of variable id used in CommandArgument;

    How the this.datamanager was initialized ;

    Can you clarify it?

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    05 Jan 2010
    Link to this post
    Hi Audreyn Justus,

    You can initialize the dataManager as private field in your control

    private IndexDataManager dataManager = new IndexDataManager();

    Regards,
    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.
  5. Audreyn Justus
    Audreyn Justus avatar
    8 posts
    Registered:
    12 Oct 2005
    05 Jan 2010
    Link to this post
    Thanks Ivan

    I get it!

    I believe the full working code  will be

        public string IndexName { getset; }  
     
        private Telerik.Search.Data.IndexingServiceInfo ServiceInfo()  
        {  
            Telerik.Search.Data.IndexingServiceInfo Result = new Telerik.Search.Data.IndexingServiceInfo();  
            Telerik.Search.IndexDataManager idm = new Telerik.Search.IndexDataManager();  
            IList svs = idm.GetServices();  
            for (int i = 0; i < svs.Count; i++)  
            {  
                if (((Telerik.Search.Data.IndexingServiceInfo)svs[i]).Name == IndexName)  
                {  
                    Result = (Telerik.Search.Data.IndexingServiceInfo)svs[i];  
                }  
            }  
            return Result;  
        }  
     
     
        private void ReIndexSite()  
        {  
            Telerik.Search.Data.IndexingServiceInfo isi = ServiceInfo();  
            Telerik.Search.Engine.IIndexingService iis = new Telerik.Search.Engine.IndexingService(isi);  
            int timeout = this.Context.Server.ScriptTimeout;  
            this.Context.Server.ScriptTimeout = 4800;  
            iis.Index(false);  
            this.Context.Server.ScriptTimeout = timeout;  
            iis.DisposeService();  
        }  

     

    THis code will reindex the entire site. What it´s perfect for my project. But, for a really big site this will be a problem.  How to reindex only a page? It´s possible?

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    05 Jan 2010
    Link to this post
    Hello Audreyn Justus,

    It is not possible to re index only a page. Internally Lucene creates its segments in App_Data folder each time you publish a page. If you have a really large site you may just experience some CPU and RAM peaks, but in this case you should consider powerful VPS or Dedicated server.

    Best wishes,
    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.
  7. Audreyn Justus
    Audreyn Justus avatar
    8 posts
    Registered:
    12 Oct 2005
    05 Jan 2010
    Link to this post
    Thank you anyway

    I was able to reindex only a page, but with some differences in records created (as mentioned in my first post) through the code:
                string[] urls1 = new string[] { "~" + Request.Url.AbsolutePath };  
                string[] urls2 = new string[] { Request.Url.AbsoluteUri };  
                Telerik.Search.Engine.IndexingManager.DeleteDocumentsFromIndex(IndexProvider, urls1);  
                Telerik.Search.Engine.IndexingManager.DeleteDocumentsFromIndex(IndexProvider, urls2);  
                Telerik.Search.Engine.IndexingManager.StartIndexing(IndexProvider, urls2, true);  
     
Register for webinar
7 posts, 0 answered