Clear search index programatically - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Clear search index programatically

  • Clear search index programatically
  • Hi!

    Currently I'm using sitefinity 9.2. 

    How to clear searc index programatically ?

  • Here is the documentation for search index CRUD operations.  These methods will allow for deleting and/or updating search indexes programmaticlly.

    docs.sitefinity.com/for-developers-crud-operations-for-a-search-index

  • You can try something like this:

    var queryBuilder = Telerik.Sitefinity.Abstractions.ObjectFactory.Resolve<IQueryBuilder>();
            var searchQuery = queryBuilder.BuildQuery("test", new string[] "content" );
            searchQuery.IndexName = searchIndexName;
            searchQuery.Skip = 0;
            searchQuery.Take = 10;
            searchQuery.HighlightedFields = new List<string>() "content" ;


            IResultSet searchResult = ServiceBus.ResolveService<ISearchService>().Search(searchQuery);
            foreach (var item in searchResult)
           
                ServiceBus.ResolveService<ISearchService>().RemoveDocument(searchIndexName, item.IdentityField);