1

Is there any way to add document to recrawl on the next iteration of continuous crawl?

It seems that CrawlLog API adds document to the next iteration of incremental crawl.

SPSecurity.RunWithElevatedPrivileges(() => {
    var searchServiceApplication = //Assume that there are only one SSA on the farm
        SearchService.Service.SearchServiceApplications.FirstOrDefault();

    // Path should be for default Zone (because SSA crawl from Default Zone)
    path = ConvertToDefaultZoneUrl(path.TrimEnd('/'));

    var crawlLog = new CrawlLog(searchServiceApplication);
    var result = crawlLog.RecrawlDocument(path);

    if (result)
         Log.Trace("Document successfully added to recrawl queue '{0}'", path);
    else Log.Error("Document does not found '{0}'", path);
});

Is possible to update some field like vti_searchversion or another and does not change Modified / Modified By properties to force re-crawl of the document asap?

1

You can set vti_searchversion on a web, library or folder, not per item. Not ideal, but not too bad.

There's some code over at https://sebastian.expert/force-web-whole-list-library-re-crawled-search-sharepoint-2013-using-api/ you can use. Or my re-crawl scripts at https://github.com/wobba/SPO-Trigger-Reindex.

0

If you remove the document from the index, it should be picked up again on the next continuous crawl. Instructions to do it through the UI are available at: https://technet.microsoft.com/en-us/library/jj219587.aspx.

I think you should might be able to achieve the same thing with the RemoveDocumentFromSearchResults() method on the crawl log object, but I'm not sure if that's creating a persistent block of the item from the search results, or just removing the item from the current index so that it can be added again.

0

As I understand item.Update() is enough to add document to the next iteration of continuous crawl. In order to leave modified date unchanged we can use this trick (SharePoint allows to set arbitrary values in "Modified" & "Editor" fields)

It seems that following code is also works:

public static void ReCrawlDocument(string path)
{
    using (var site = new SPSite(path))
    using (var web = site.OpenWeb())
    {
        var pos = path.IndexOf("/", 8, StringComparison.InvariantCultureIgnoreCase);
        var serverRelativeUrl = path.Substring(pos);
        var item = web.GetListItem(serverRelativeUrl);

        // Changing "vti_searchversion" may not be necessary
        var searchVersionPropertyName = "vti_searchversion";
        if (!item.Properties.ContainsKey(searchVersionPropertyName))
        {
            item.Properties.Add(searchVersionPropertyName, 1);
        }
        else
        {
            var versionObj = item.Properties[searchVersionPropertyName];
            var version = versionObj as int? ?? 0;
            item.Properties[searchVersionPropertyName] = (version + 1);
        }

        // These lines will help to not update modified date and editor fields
        item["Modified"] = item["Modified"];
        item["Editor"] = item["Editor"];

        var allowUnsafeUpdates = web.AllowUnsafeUpdates;
        web.AllowUnsafeUpdates = true;
        item.Update();
        web.AllowUnsafeUpdates = allowUnsafeUpdates;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.