8
votes

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.

2
Are you talking about master or web? Web DB only has 1 version of each item so it should have that version. Master is your master repository and should have all versions, e.g. for Page Editor / Preview modes... - Mark Ursino
Hi Mark. I'm using the web database. The issue happens when a user adds a new version in the versions dropdown of an item and then submits it to the search index. The item is created with a new unique version in the solr index. So I'm looking for a way to remove the previous version from the index when this happens. - Ian Graham
Does rebuilding the indexes solve the issue? When you say "when a user adds a new version", the item is only get added to the web index on publish right? - jammykam
Does it give you any errors, warnings or messages while you try to delete it? Or is it just that it doesn't perform the Delete? - Shriroop
Rebuilding the entire index does resolve the issue, but ideally don't want to do this all the time; The item is only added to the index when it is published. I don't get any errors when calling the delete method and nothing comes up in the search.log or the crawling log. - Ian Graham

2 Answers

3
votes

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).

3
votes

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