Restrict Search not to show deleted managed property value
-
09-12-2019 - |
Question
The default SharePoint behavior is to also search documents which have been deleted unless the content has been re-crawled or index is reset. I am using a KeywordQuery to search items with a particular managed property and I don't want the deleted items to show up in the result even if content has not been re-crawled or reset.
query.QueryText = string.Format("Barcode:\"{0}\"", "ABC123");
query.ResultTypes |= ResultType.RelevantResults;
query.SelectProperties.Add("Barcode");
The only way I am able to achieve it so far is to add the "Path" property and then checking if the resulting SPListItem is not null.
query.SelectProperties.Add("Path");
Is there any better way of doing this?
Solution
If you have a high ratio of queries compared to deletes, then you might want to add an event receiver which calls CrawlRuleCollection.RemoveFromResults upon deletion of an item
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange