Developer forum

Forum » Development » DynamicwebProductIndexer

DynamicwebProductIndexer


Reply
Hi,

Can I trigger the update mechanism of the DynamicwebProductIndexer via the api.
If yes how to do this?

kind regards,
Remi

Replies

 
Reply
Hi Remi!
You can add refference to the Dynamicweb.Searching.dll library
And then, execute Searching.Management.IndexUpdateService.Current.CreateTask(string path, bool isPartial) function to start  updating.
path - is relative to /Files/System/_search path to the index folder (f.e. "Products")
isPartial - full/partial update

Best regards, Vladimir
 
Reply
Hello Remi,

As Vladimir pointed, the one option is to call the CreateTask method of the IndexupdateService object like the following:

using Dynamicweb.Searching.Management;

public void UpdateProductIndex(bool isFullUpdate)
{
    IndexUpdateService.Current.CreateTask("Products", isFullUpdate);
}


Where "isFullUpdate" means whether any information persisted in the queue should be discarded and the index should be recreated "from scratch".

Although you need to know that calling this method doesn't necessarily means that the index will start updating right away. This is because the method simply registers new task for the background thread which will perform an actual update. So you shouldn't expect the index to become up-to-date when the method is executed. If you want to update the index "synchronously" you can use another approach:

using Dynamicweb.Searching;

public void UpdateProductIndex(bool isFullUpdate)
{
    IndexManager.Current.UpdateIndex("Products", isFullUpdate);
}


This method perform an actual update. But note that it might take several minutes before it completes.

Hope this will help you.

-- Pavel

 
Reply
Thanks for all the replies :)
Today i will check this out.

 

You must be logged in to post in the forum