I'm trying to add some items to a custom Sitecore Solr index Programmatically via the Sitecore Content Search APIs. The items I will add won't reside in Sitecore so the code below is just a test for now.
I've simplified the code a bit to share an example below, however I don't know if this approach will work or not as I'm not sure how best to pass in the IProviderUpdateContext and IProviderIndexConfiguration:
using (var context = ContentSearchManager.GetIndex(indexName).CreateSearchContext())
{
//get the home item from Sitecore
var item = _databaseManager.GetItem(new ID("{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"));
//convert to an indexable item
var searchItem = new SitecoreIndexableItem(item);
//add the item to the index - this doesn't work
context.Index.Operations.Add(searchItem, null, null);
}
I know that there are other ways of doing this such as creating my own search crawler using FlatDataCrawler and the GetItemsToIndex() method. However I want to run the code from SiteCron in order to have more control over when and how it happens.
I'm using Sitecore 8.2 Update 6 and Solr 6.6.3.
One way I could do this is using the Rest Apis to add data but I’d rather use the internal Apis given this runs in the Sitecore context. I’m open to other suggestions on how to do this in other ways though.