Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 4 down vote accepted
+25

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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