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

Forums / Developing with Sitefinity / Sitefinity 4.4- Searches - How to Programatically Reindex

Sitefinity 4.4- Searches - How to Programatically Reindex

15 posts, 0 answered
  1. steve
    steve avatar
    10 posts
    Registered:
    18 Aug 2011
    17 May 2012
    Link to this post
    We have implemented a custom pipe for indexing custom database content as per blog:

    public class CoursesModule : ModuleBase...

    public class CoursesInboundPipe : PipeBase, IPushPipe, IInboundPipe

     

    The index works fine and search results from the custom index are as expected.
    However, we need to schedule a re-index of database content to run every night.
    I note that manually reindexing through the Admin section seems to call the method below on our custom pipe.

    public void ToPublishingPoint()
    Calling this method removes old index and recreates lucene data files.

    I would appreciate a code snippet that gets a reference to a registered pipe and subsequently calls the "ToPublishingPoint" method (or whatever approach is required to kick off the reindex). 

    We intend to make an authenticated nightly 'Get' request for a page whose code behind programatically re-creates the index.
     
    Thanks Steve


  2. steve
    steve avatar
    10 posts
    Registered:
    18 Aug 2011
    17 May 2012
    Link to this post
    I'm guessing it may be something along these lines:

    var pipeSettings=PublishingSystemFactory.GetPipeSettings("CoursesInboundPipe");
    var pipe = PublishingSystemFactory.GetPipe("CoursesInboundPipe");
    pipe.Initialize(pipeSettings);
    pipe.Initialise should set the PublishingPoint:

     

    public virtual void Initialize(Telerik.Sitefinity.Publishing.Model.PipeSettings pipeSettings)
           {
               this.PipeSettings = pipeSettings;
               this.PublishingPoint = PublishingSystemFactory.GetPublishingPoint(this.PipeSettings.PublishingPoint);
           }

    Once the PublishingPoint is initialised it may be possible(?) to trigger a reindex using invoke method below.
     Problem is, the PublishingPoint within the PipeSettings object is always null using my initialsation code above. When reindexing through Admin the PipeBase Initialise method is passed a fully populated PipeSettings.PublishingPoint.

    if (point != null)
    {
        PublishingManager.InvokeInboundPushPipes(point.Id, null);
    }

  3. Bonny
    Bonny avatar
    58 posts
    Registered:
    11 Nov 2016
    18 May 2012
    Link to this post
    Hello,

    This code gets the search index with name "myCustomSearchIndexName" and invoke reindex on it.
    var searchIndex = manger.GetPublishingPoints().Where(p => p.Name == "as").FirstOrDefault();
    if(searchIndex != null)
    {
       var searchIndexPublishingPointId = searchIndex.Id;
       SearchManager.GetManager().DeleteCatalogue("myCustomSearchIndexName");   
       PublishingManager.InvokeInboundPushPipes(searchIndexPublishingPointId , String.Empty);
    }

    This code uses the default search provider, which i guess you use too. If you have any problems with it or any other questions, contact us again.

    All the best,
    Bonny
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. steve
    steve avatar
    10 posts
    Registered:
    18 Aug 2011
    18 May 2012
    Link to this post
    Thanks for the reply Bonny, 

    I've tried your code as per below:
    var searchIndex = manger.GetPublishingPoints().Where(p => p.Name ==
    "as").FirstOrDefault();

    But this returns null for searchIndex, also below returns null:

    var searchIndex = manager.GetPublishingPoints().Where(p => p.DateCreated>DateTime.Now.AddDays(-90)).FirstOrDefault;

    So not sure what I'm doing wrong?
    Cheers
    Steve
  5. steve
    steve avatar
    10 posts
    Registered:
    18 Aug 2011
    18 May 2012
    Link to this post
    for clarity I'm initialising the manager as follws:
    PublishingManager manager = PublishingManager.GetManager();
  6. steve
    steve avatar
    10 posts
    Registered:
    18 Aug 2011
    18 May 2012
    Link to this post
    also can conform index exists:
    SearchManager.GetDefaultProviderName();
    SearchManager manager = SearchManager.GetManager(SearchManager.GetDefaultProviderName());
    var searchIndexFound = manager.SearchIndexExists("courses");
  7. Bonny
    Bonny avatar
    58 posts
    Registered:
    11 Nov 2016
    18 May 2012
    Link to this post
    Hello,

    Instead of "as" you should use your search index name - "courses". The "search index name" is the name that you see in the UI - same as that you use for your search index. And if you want to get all publishing points, you can just remove your Where clause. Write me back if the problem exists.

    Kind regards,
    Bonny
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. steve
    steve avatar
    10 posts
    Registered:
    18 Aug 2011
    19 May 2012
    Link to this post
    The problem seems to be the fact I appear to have no Publishing Points!
    Using the code below, the specific request for 'courses' returns null.
    The request for a list of Publishing Points returns an empty list.

    PublishingManager pubManager = PublishingManager.GetManager();
    var pubPoint = pubManager.GetPublishingPoints().FirstOrDefault(w => w.Name == "Courses");
    var allpubPoints = pubManager.GetPublishingPoints().ToList();
    Not sure what could be the cause of this? I re-indexed 'courses' manually and ran fine. The Lucene index files updated successfully. Is there anything I can try to further test Publishing Points?
    Cheers

    Steve


    Cheers

    Steve




  9. Bonny
    Bonny avatar
    58 posts
    Registered:
    11 Nov 2016
    23 May 2012
    Link to this post
    Hello,

    Can you send me your whole project with your DB, so I can investigate this issue?

    All the best,
    Bonny
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. steve
    steve avatar
    10 posts
    Registered:
    18 Aug 2011
    07 Jun 2012
    Link to this post
    .Hi Bonny,
    Been away for a few weeks so apologies for late reply...
    I now have it working correctly with valid Publishing Points.
    The problem was in the CourseInboundPipe class: changing the publishing provider from default to SearchProvider resulted in valid publishing points being returned.

    CourseInboundPipe.cs:
    _publishingProviderName = publishingConfig.SearchProviderName;


    Then invoke reindexing based on CourseInboundPipe's provider name:  

    //Get a reference to the pipe.
    var pipe = (CoursesInboundPipe)PublishingSystemFactory.GetPipe(CoursesInboundPipe.PipeName);
    //Set the correct provider name for the publishing point.
    string providerName = pipe.PublishingProviderName;

    //Initialise the appropriate Publishing Manager based on the Pipe's Publishing Provider Name. PublishingManager pubManager = PublishingManager.GetManager(providerName);
    //Initialise the specific Publishing Point associated with required search index.
    var publishingPoint = pubManager.GetPublishingPoints().FirstOrDefault(w => w.Name == indexName);
    //Proceed only if Publishing Point was found.
    if (publishingPoint != null) PublishingManager.InvokeInboundPushPipes(publishingPoint.Id, providerName);

     

     

  11. Bonny
    Bonny avatar
    58 posts
    Registered:
    11 Nov 2016
    07 Jun 2012
    Link to this post
    Hello,

    I am happy to hear that everything is okay now. If you have any other troubles, don't hesitate to contact us again.

    Greetings,
    Bonny
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  12. steve
    steve avatar
    10 posts
    Registered:
    18 Aug 2011
    13 Jun 2012
    Link to this post
    Just hit a PipeSettings problem we think is related to our Sitefinity upgrade from 4.3 to 5.0.
    The Course index still rebuilds OK from Admin but NOT manually using the following:

    PublishingManager .InvokeInboundPushPipes(publishingPoint.Id, providerName);

    I can step through the code and see that the PipeSettings are initialised correcly in the PipeBase.cs using Sitefinity Admin or InvokeInboundPipe.
    Here's the init code that sets the PipeSettings:
    PipeBase.cs:
    public virtual void Initialize(Telerik.Sitefinity.Publishing.Model.PipeSettings pipeSettings) {
     this.PipeSettings = pipeSettings;
     this.PublishingPoint = PublishingSystemFactory.GetPublishingPoint(this.PipeSettings.PublishingPoint);
     }
    However, when using InvokeInboundPipe, the PipeSettings are null when needed in subsequent method calls eg: ToPublishingPoint()

    We now receive error from Telerik.OpenAccess.Exceptions.InvalidOperationException
     'IObjectScope' is already closed' error when attempting to retreive the PipeSettings.
    eg
                WrapperObject obj = new WrapperObject(null);
                obj.MappingSettings = this.PipeSettings.Mappings;
    This is very puzzling. No indexing code has been changed apart from the Sitefinity upgrade dll references.

    Telerik.OpenAccess is now  rtv v2.050727, Version 2011.3.1320.1
    Telerik.Sitefinity is now rtv v4.0.30319, Version 5.0.2860.0

    Thanks

    Steve.

     





  13. Bonny
    Bonny avatar
    58 posts
    Registered:
    11 Nov 2016
    14 Jun 2012
    Link to this post
    Hello,

    This is very strange behaviour. Can you try this code and tell me if the problem continues:

    var pointGuid = new Guid(pointId);
    var providers = PublishingManager.GetManager().Providers;
    SearchIndexPipeSettings pipeSettings = null;
    foreach (var provider in providers)
      {
         pipeSettings = PublishingManager.GetManager(provider.Name).GetPipeSettings<SearchIndexPipeSettings>().Where(ps => ps.PublishingPoint.Id == pointGuid).FirstOrDefault();
         if (pipeSettings != null)
                        break;
      }
     
      if (pipeSettings != null)
      {
          SearchManager.GetManager(pipeSettings.SearchProviderName).DeleteCatalogue(pipeSettings.CatalogName);
      }
     
      PublishingManager.InvokeInboundPushPipes(pointGuid, providerName);

    If the problem still exists with this code, we will need your whole project + DB + configuration to reproduce it and investigate it.

    Kind regards,
    Bonny
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  14. steve
    steve avatar
    10 posts
    Registered:
    18 Aug 2011
    14 Jun 2012
    Link to this post
    Thanks very much Bonnie, your code suggestion did the trick!

    Here's the merged code deleting the existing catalogue:
    private void CreateCourseIndex(string indexName)
     {
         //Get a reference to the Courses pipe.
         var pipe = (CoursesInboundPipe)PublishingSystemFactory.GetPipe(CoursesInboundPipe.PipeName);
     
         //Set the correct provider name for the publishing point.
         // Note: CoursesInboundPipe sets provider name using: PublishingConfig.SearchProviderName;
         string providerName = pipe.PublishingProviderName;
     
         //Initialise the appropriate Publishing Manager based on the Pipe's Publishing Provider Name. 
         PublishingManager pubManager = PublishingManager.GetManager(providerName);
     
         //Initialise the specific Publishing Point associated with required search index [courses].
         var publishingPoint = pubManager.GetPublishingPoints().FirstOrDefault(w => w.Name == indexName);
     
         //Proceed only if Publishing Point was found.
         if (publishingPoint != null)
         {
             var pointGuid = new Guid(publishingPoint.Id.ToString());
             var providers = PublishingManager.GetManager().Providers;
     
             SearchIndexPipeSettings pipeSettings = null;
     
             //Get Pipe Settings for 'Course' Publishing Point.
             foreach (var provider in providers)
             {
                 //pipeSettings = PublishingManager.GetManager(provider.Name).GetPipeSettings<SearchIndexPipeSettings>().Where(ps => ps.PublishingPoint.Id == pointGuid).FirstOrDefault();
                 pipeSettings = PublishingManager.GetManager(provider.Name).GetPipeSettings<SearchIndexPipeSettings>().FirstOrDefault(ps => ps.PublishingPoint.Id == pointGuid);
                 if (pipeSettings != null)break;
             }
     
             if (pipeSettings != null)
             {
                 //Remove old Lucene Catalogue Files for Course Index.
                 SearchManager.GetManager(pipeSettings.SearchProviderName).DeleteCatalogue(pipeSettings.CatalogName);
             }
     
             //Trigger the indexing using the appropriate Publishing Point Id and Publishing Provider Name.
             PublishingManager.InvokeInboundPushPipes(publishingPoint.Id, providerName);
     
         }
     
     
     }
  15. Bonny
    Bonny avatar
    58 posts
    Registered:
    11 Nov 2016
    14 Jun 2012
    Link to this post
    Hi,

    I am glad to hear that. If you have other problems, feel free to contact us again.

    Kind regards,
    Bonny
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
15 posts, 0 answered