U4-2344 - 6.1.1 Examine Management Dashboard: Rebuilding index removes all media items from the index

Created by Ben A. 09 Jun 2013, 22:08:21 Updated by Brad Cannon 16 Jul 2013, 13:25:43

Relates to: U4-2297

Steps to reproduce:

  1. fresh install of 6.1.1 via NuGet
  2. create a media folder, upload a PDF, and then save it.
  3. confirm that the file has been added to both the Internal and External indexes.
  4. go the Examine Management dashboard, select either Internal or External Indexer (same issue for both), and hit the 'Rebuild index' button

Expected behaviour: The Examine index(s) should be unchanged, since we already saved the media file in step 2

Actual behaviour: The media file is removed from the index. Additionally, further testing showed that using the 'Rebuild index' tool removed ALL media items from the index.

Confirmed same behaviour in 6.1.0.

Using VS 2012, WebMatrix, SQLCE; Have not been able to test with IIS7/SQL Server.


Mikkel Keller Stubkjær 18 Jun 2013, 14:03:25

I have the same issue and I need to index media element, so I investigated the issue. This issue is caused by a change in the UmbracoMediaService implementation, which was introduced when UmbracoExamine was moved from a standalone project to the Umbraco project.

In the standalone UmbracoExamine implementation on codeplex, the service loops over root media items. http://examine.codeplex.com/SourceControl/latest#Projects/UmbracoExamine/DataServices/UmbracoMediaService.cs

.. foreach (Media media in rootMedia) { xmlMedia.Root.Add(GetMediaItem(media.Id)); } .. and uses the private helper method GetMediaItem to convert to xml:

private XElement GetMediaItem(int nodeId) { var nodes = umbraco.library.GetMedia(nodeId, true); return XElement.Parse(nodes.Current.OuterXml); } The xml convertin is is done by calling library.GetMedia(int MediaId, bool Deep) with the deep parameter set to true and then the outerxml is added to the root document.

In Umbraco v6.1.1 source the implementation uses the Umbraco.Core.Models.ContentExtensions.ToXml(this IMedia media) extension method which is a shallow xml representation, thereby eliminating all children from indexable data. https://github.com/umbraco/Umbraco-CMS/blob/release-6.1.1/src/UmbracoExamine/DataServices/UmbracoMediaService.cs

.. foreach (var m in _services.MediaService.GetRootMedia()) { xmlMedia.Root.Add(m.ToXml()); } .. I don't know how to remedy this in the most performant way in v6.1.1, so in order to fix my very urgent issue without modifying the core, I extended the UmbracoExamine.DataServices.UmbracoDataService class like shown below. Making use of the old implementation of UmbracoMediaService

namespace noerd.Integration.Examine { public class LegacyUmbracoDataService : UmbracoDataService { public LegacyUmbracoDataService() { MediaService = new LegacyMediaService(); } }

public class LegacyMediaService : IMediaService
    public XDocument GetLatestMediaByXpath(string xpath)
        Media[] rootMedia = Media.GetRootMedias();
        var xmlMedia = XDocument.Parse("<media></media>");
        foreach (Media media in rootMedia)
        var result = ((IEnumerable)xmlMedia.XPathEvaluate(xpath)).Cast<XElement>();
        return result.ToXDocument();

    private XElement GetMediaItem(int nodeId)
        var nodes = umbraco.library.GetMedia(nodeId, true);
        return XElement.Parse(nodes.Current.OuterXml);

} and then added this datasource object to my examineSettings.config file

.. .. ..

Bradley Kronson 02 Jul 2013, 15:25:07

I can confirm that rebuilding of indexes removes all media items from Examine. Quite disconcerting if you are running a site that depends on this...

Shannon Deminick 03 Jul 2013, 09:48:22

Fixed in revision: 4077a01a6b90ce57f4bf9ad575b18d51a85f1d17

Due to the ToXml not being deep xml in the new APIs, needed to call ToDeepXml.

Shannon Deminick 03 Jul 2013, 09:49:21

I've bumped this to 'Major' since reindexing will never work properly for media, you'd have to go save each media item individually to get them back into the index.

Bradley Kronson 03 Jul 2013, 10:17:43

Thanks Shannon!

Ben A. 03 Jul 2013, 10:44:53

Thanks Shannon, much appreciated!

Priority: Major

Type: Bug

State: Fixed

Assignee: Shannon Deminick

Difficulty: Normal


Backwards Compatible: True

Fix Submitted:

Affected versions: 6.1.1, 6.1.2

Due in version: 6.1.3


Story Points: