Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David Prothero 23 posts 106 karma points
    Mar 10, 2014 @ 17:53
    David Prothero
    0

    How to Automate Examine Index Rebuild?

    We have a custom Examine index on some data in SQL Server. It works great. We have a process that bulk loads this data into SQL Server on a periodic basis. We need to rebuild the Examine index after each run.

    Is there some way to automate the rebuild of the Examine index?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 10, 2014 @ 18:01
    Jeroen Breuer
    0

    Maybe have a lookt at the source code of the Examine Dashboard package. It has a rebuild button. The code tricked behind that button can probably be used for automation as well.

    Jeroen

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Mar 10, 2014 @ 18:13
    Ismail Mayat
    0

    David,

    I had similar issue on a site and I created a webservice then created a console app to call that webservice and then setup windows task scheduler to run that at 2am. In theory you could as Jeroen suggests call the webservice called by examine dashboard using console app and windows scheduler.

    Regards

    Ismail

  • William Parr 9 posts 31 karma points
    Dec 04, 2014 @ 15:17
    William Parr
    2

    Maybe have a lookt at the source code of the Examine Dashboard package. It has a rebuild button. The code tricked behind that button can probably be used for automation as well.

    Jeroen

    Adding to Jeroen's post, I had a look at the Examine Dashboard package and the button they use executes an AJAX call to a file within that package. When you piece it all together you can re-create this call for wherever you'd like. I've placed it in an .aspx file within the Umbraco directory and have set a scheduled task to load this page once a day.

    This is the JavaScript for when you'd like to manually trigger a rebuild of a custom index (using jQuery):

    $.ajax({
      type: 'POST',
      url: '/umbraco/plugins/ExamineDash/Actions.asmx/RebuildIndex',
      data: "{'indexProvider': 'YourCustomIndexer' }",
      contentType: 'application/json; charset=utf-8',
      dataType: 'json'
    });
    

    If all goes well, this call should return a response with the contents: {"d":null}. I've tested it by altering data in my non-Umbraco database, searching for the added data (finding no results), running the .aspx file and executing another search (which subsequently returned the record I had just altered).

  • Chester Campbell 98 posts 209 karma points
    Sep 27, 2021 @ 21:46
    Chester Campbell
    0

    For an Umbraco CMS 8.14.0 website with a custom Examine Index called MyEventsIndex I created a recurring task that runs every hour to rebuild the index.

    I used this as a guide: https://our.umbraco.com/documentation/Reference/Scheduling/

    using Umbraco.Core.Composing;
    using Umbraco.Core.Logging;
    using Umbraco.Examine;
    using Umbraco.Web.Scheduling;
    
    namespace MySite.Examine
    {
        public class MyEventsRecurringTaskComposer : ComponentComposer<MyEventsRecurringTaskComponent>
        {
        }
    
        public class MyEventsRecurringTaskComponent : IComponent
        {
            private readonly IProfilingLogger _logger;
            private BackgroundTaskRunner<IBackgroundTask> _taskRunner;
            private readonly IndexRebuilder _indexRebuilder;
    
            public MyEventsRecurringTaskComponent(IProfilingLogger logger, IndexRebuilder indexRebuilder)
            {
                _logger = logger;
                _indexRebuilder = indexRebuilder;
                _taskRunner = new BackgroundTaskRunner<IBackgroundTask>("MyEventsTaskRunner", _logger);
            }
    
            public void Initialize()
            {
                int delayBeforeStarting = 1 * 60 * 1000; // 1 minute as (minutes X seconds X milliseconds)
                int howOftenToRepeat = 1 * 60 * 60 * 1000; // 1 hour as (hour X minutes X seconds X milliseconds)
    
                var task = new MyEventsRecurringTask(_taskRunner, delayBeforeStarting, howOftenToRepeat, _indexRebuilder);
    
                _taskRunner.TaskCompleted += _taskRunner_TaskCompleted;
    
                _taskRunner.TaskCancelled += _taskRunner_TaskCancelled;
    
                _taskRunner.TaskStarting += _taskRunner_TaskStarting;
    
                _taskRunner.TaskError += _taskRunner_TaskError;
    
                _taskRunner.TryAdd(task);
            }
    
            private void _taskRunner_TaskError(BackgroundTaskRunner<IBackgroundTask> sender, TaskEventArgs<IBackgroundTask> e)
            {
                _logger.Info<MyEventsRecurringTaskComponent>("MyEvents Search Index rebuild error");
            }
    
            private void _taskRunner_TaskStarting(BackgroundTaskRunner<IBackgroundTask> sender, TaskEventArgs<IBackgroundTask> e)
            {
                _logger.Info<MyEventsRecurringTaskComponent>("MyEvents Search Index rebuild starting");
            }
    
            private void _taskRunner_TaskCancelled(BackgroundTaskRunner<IBackgroundTask> sender, TaskEventArgs<IBackgroundTask> e)
            {
                _logger.Info<MyEventsRecurringTaskComponent>("MyEvents Search Index rebuild cancelled");
            }
    
            private void _taskRunner_TaskCompleted(BackgroundTaskRunner<IBackgroundTask> sender, TaskEventArgs<IBackgroundTask> e)
            {
                _logger.Info<MyEventsRecurringTaskComponent>("MyEvents Search Index rebuild completed");
            }
    
            public void Terminate()
            {
                _taskRunner.TaskCompleted -= _taskRunner_TaskCompleted;
    
                _taskRunner.TaskStarting -= _taskRunner_TaskStarting;
    
                _taskRunner.TaskCancelled -= _taskRunner_TaskCancelled;
    
                _taskRunner.TaskError -= _taskRunner_TaskError;
            }
        }
    
        public class MyEventsRecurringTask : RecurringTaskBase
        {
            private readonly IndexRebuilder _indexRebuilder;
    
            public MyEventsRecurringTask(IBackgroundTaskRunner<RecurringTaskBase> runner, int delayBeforeWeStart, int howOftenWeRepeat, IndexRebuilder indexRebuilder)
                : base(runner, delayBeforeWeStart, howOftenWeRepeat)
            {
                _indexRebuilder = indexRebuilder;
            }
    
            public override bool PerformRun()
            {
                _indexRebuilder.RebuildIndex("MyEventsIndex");
    
                return true;
            }
    
            public override bool IsAsync => false;
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft