Sitecore Solr remove versions from index

2019-06-16 11:01发布

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条回答
姐就是有狂的资本
2楼-- · 2019-06-16 11:14

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

查看更多
Evening l夕情丶
3楼-- · 2019-06-16 11:31

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

查看更多
登录 后发表回答