I’m using Sitecore 7 and the Solr Search provider. I currently have the site setup to update the search index when publishing an item.
I’ve noticed that when the CMS author creates different versions of an item and then submits these into the index the previous version of the item is not removed from the index, so the index contains multiple versions of the same Sitecore item.
Does anyone know of any settings, that I can change, to make sure that the previous version is removed from the index before adding the new version?
I’ve tried running some code like below to remove the items from the index just before publishing, but the Delete method on the index doesn’t seem to delete anything.
var indexableItem = (SitecoreIndexableItem)item;
ContentSearchManager.GetIndex(index).Delete(indexableItem.UniqueId
Any help much appreciated.
Do you really need to remove the old versions? There is a virtual field defined for you to use to filter for the latest version. Just add a property like this to your POCO (or base class) and use it to filter in your Linq query:
[IndexField("_lastestversion")]
public bool IsLatestVersion { get; set; }
Note that the name of the field is different in the default Solr config (_lastestversion) than it is in the Lucene config (_latestversion).
I contacted Sitecore on this one and they have said that this is likely to be a bug and they are investigating.
As a workaround, Sitecore recommend using the Inbound and Outbound filters to filter items in the index.
Here's some more information on that:
http://www.sitecore.net/Community/Technical-Blogs/Sitecore-7-Development-Team/Posts/2013/04/Sitecore-7-Inbound-and-Outbound-Filter-Pipelines.aspx
UPDATE: @Jason in the comments below pointed out that is now a support fix for this - see knowledge base article - https://kb.sitecore.net/articles/992608
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With