Developer forum
E-mail notifications
Start Lucene search index update from code
I'm importing a lot of filters and products via some activites, and i'd like to update the index once all these imports are done.
Regards
Martin
Replies
Hi, try please this code:
Imports Dynamicweb.Extensibility.Searching
.
.
.
' *** Dynamicweb Searching ***
' Running all pending index updates
If Not ScheduledUpdate.StartupTaskIsExecuted Then
If Not HttpRuntime.UsingIntegratedPipeline Then
For Each u As ScheduledUpdate In ScheduledUpdate.GetPendingUpdates(ScheduledUpdateType.StartupTask)
' Update will be performed asynchronously
Dynamicweb.Searching.Management.IndexUpdateService.Current.CreateTask(u.Path, u.IsFullUpdate)
' Updating "Last executed" timestamp
u.LastExecuted = DateTime.Now
u.Save()
Next
End If
ScheduledUpdate.StartupTaskIsExecuted = True
End If
Kind Regards
Zhukovskiy Yury
Yury, this approach won't work because the code relies on a "Scheduled updates" settings (Management Center -> eCommerce -> Advanced configuration -> Searching -> Right click on "Products" -> "Scheduled updates") so if you didn't configure that then the update won't execute.
There is a much simpler (and recommended) approach:
1. Non-blocking (asynchronous) update:
var isFullUpdate = false; Dynamicweb.Searching.Management.IndexUpdateService.Current.CreateTask("Products", isFullUpdate);
var isFullUpdate = false; Dynamicweb.Searching.IndexManager.Current.UpdateIndex("Products", isFullUpdate);
-- Pavel
FYI - If your DW solution is Integrated with Navision and you want to update the index after import. Create a PipeLine with Pavel's solution 2. (Synchronous) and place it as the last pipeline in the import. Otherwise the index will, in some cases, fail with an object reference not set to an instance of an object. Don't know why, but it works with
Dynamicweb.Searching.IndexManager.Current.UpdateIndex("Products", isFullUpdate);
Dynamicweb.Searching.Management.IndexUpdateService.Current.CreateTask("Products", isFullUpdate);
Dynamicweb.Searching.IndexManager.Current.UpdateIndex("Products", isFullUpdate);
Regards /Snedker
You must be logged in to post in the forum