Developer forum

Forum » Development » Delete from index

Delete from index

Tobias Belling
Reply

Hi.

I am trying to change the index by code and it's possible to add/update the index. I am a having a bit more trouble by deleting from the index.

It looks like Lucene has a function to delete using an index document... Is there a way to delete from an index?

var indexService = ServiceLocator.Current.GetInstance<IIndexService>();

var index = indexService.LoadIndex(Dynamicweb.Indexing.Repositories.RepositoryService.BaseFolder + "IndexPath");
                        
var write = index.GetInstance().CreateWriter();
write.Open(true);
//Delete the document
write.Close();

Replies

 
Vladimir Shushunov Dynamicweb Employee
Vladimir Shushunov
Reply
This post has been marked as an answer

Hi Tobias,

hmm.. there is no direct delete method, but updating index with empty document will do that:

var document = new IndexDocument();
writer.AddOrUpdateDocument(document, "keyField", key);

Best regards,

Vladimir

Votes for this answer: 1

 

You must be logged in to post in the forum