diff --git a/src/Umbraco.Web/Models/Mapping/EntityModelMapper.cs b/src/Umbraco.Web/Models/Mapping/EntityModelMapper.cs index 0711f0a866..585b4d4d51 100644 --- a/src/Umbraco.Web/Models/Mapping/EntityModelMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/EntityModelMapper.cs @@ -8,6 +8,7 @@ using Umbraco.Core.Models; using Umbraco.Core.Models.Mapping; using Umbraco.Core.Models.Membership; using Umbraco.Web.Models.ContentEditing; +using UmbracoExamine; namespace Umbraco.Web.Models.Mapping { @@ -46,7 +47,7 @@ namespace Umbraco.Web.Models.Mapping config.CreateMap() //default to document icon - .ForMember(x => x.Icon, expression => expression.UseValue("icon-document")) + .ForMember(x => x.Icon, expression => expression.Ignore()) .ForMember(x => x.Id, expression => expression.MapFrom(result => result.Id)) .ForMember(x => x.Name, expression => expression.Ignore()) .ForMember(x => x.Key, expression => expression.Ignore()) @@ -57,6 +58,11 @@ namespace Umbraco.Web.Models.Mapping .ForMember(x => x.AdditionalData, expression => expression.Ignore()) .AfterMap((result, basic) => { + //get the icon if there is one + basic.Icon = result.Fields.ContainsKey(UmbracoContentIndexer.IconFieldName) + ? result.Fields[UmbracoContentIndexer.IconFieldName] + : "icon-document"; + basic.Name = result.Fields.ContainsKey("nodeName") ? result.Fields["nodeName"] : "[no name]"; if (result.Fields.ContainsKey("__NodeKey")) { diff --git a/src/Umbraco.Web/Search/ExamineEvents.cs b/src/Umbraco.Web/Search/ExamineEvents.cs index ed1e01f407..8b21ce60ae 100644 --- a/src/Umbraco.Web/Search/ExamineEvents.cs +++ b/src/Umbraco.Web/Search/ExamineEvents.cs @@ -392,8 +392,12 @@ namespace Umbraco.Web.Search private static void ReIndexForMedia(IMedia sender, bool isMediaPublished) { + var xml = sender.ToXml(); + //add an icon attribute to get indexed + xml.Add(new XAttribute("icon", sender.ContentType.Icon)); + ExamineManager.Instance.ReIndexNode( - sender.ToXml(), IndexTypes.Media, + xml, IndexTypes.Media, ExamineManager.Instance.IndexProviderCollection.OfType() //Index this item for all indexers if the media is not trashed, otherwise if the item is trashed @@ -433,8 +437,12 @@ namespace Umbraco.Web.Search /// private static void ReIndexForContent(IContent sender, bool isContentPublished) { + var xml = sender.ToXml(); + //add an icon attribute to get indexed + xml.Add(new XAttribute("icon", sender.ContentType.Icon)); + ExamineManager.Instance.ReIndexNode( - sender.ToXml(), IndexTypes.Content, + xml, IndexTypes.Content, ExamineManager.Instance.IndexProviderCollection.OfType() //Index this item for all indexers if the content is published, otherwise if the item is not published diff --git a/src/UmbracoExamine/DataServices/UmbracoContentService.cs b/src/UmbracoExamine/DataServices/UmbracoContentService.cs index 236a5bf27a..ccea38dfc8 100644 --- a/src/UmbracoExamine/DataServices/UmbracoContentService.cs +++ b/src/UmbracoExamine/DataServices/UmbracoContentService.cs @@ -70,7 +70,7 @@ namespace UmbracoExamine.DataServices /// /// /// - + [Obsolete("This should no longer be used, latest content will be indexed by using the IContentService directly")] public XDocument GetLatestContentByXPath(string xpath) { var xmlContent = XDocument.Parse(""); diff --git a/src/UmbracoExamine/UmbracoContentIndexer.cs b/src/UmbracoExamine/UmbracoContentIndexer.cs index 43d53325e5..49db3da8b1 100644 --- a/src/UmbracoExamine/UmbracoContentIndexer.cs +++ b/src/UmbracoExamine/UmbracoContentIndexer.cs @@ -125,6 +125,7 @@ namespace UmbracoExamine /// public const string IndexPathFieldName = "__Path"; public const string NodeTypeAliasFieldName = "__NodeTypeAlias"; + public const string IconFieldName = "__Icon"; /// /// The prefix added to a field when it is duplicated in order to store the original raw value. @@ -417,11 +418,16 @@ namespace UmbracoExamine var serializer = new EntityXmlSerializer(); foreach (var m in media) { - yield return serializer.Serialize( + var xml = serializer.Serialize( _mediaService, _dataTypeService, _userService, m); + + //add a custom 'icon' attribute + xml.Add(new XAttribute("icon", m.ContentType.Icon)); + + yield return xml; } } @@ -430,11 +436,16 @@ namespace UmbracoExamine var serializer = new EntityXmlSerializer(); foreach (var c in content) { - yield return serializer.Serialize( + var xml = serializer.Serialize( _contentService, _dataTypeService, _userService, c); + + //add a custom 'icon' attribute + xml.Add(new XAttribute("icon", c.ContentType.Icon)); + + yield return xml; } } @@ -476,6 +487,7 @@ namespace UmbracoExamine protected override void OnGatheringNodeData(IndexingNodeDataEventArgs e) { + //strip html of all users fields if we detect it has HTML in it. //if that is the case, we'll create a duplicate 'raw' copy of it so that we can return //the value of the field 'as-is'. @@ -497,15 +509,21 @@ namespace UmbracoExamine base.OnGatheringNodeData(e); - //ensure the special path and node type alis fields is added to the dictionary to be saved to file + //ensure the special path and node type alias fields is added to the dictionary to be saved to file var path = e.Node.Attribute("path").Value; if (!e.Fields.ContainsKey(IndexPathFieldName)) e.Fields.Add(IndexPathFieldName, path); - //this needs to support both schemas so get the nodeTypeAlias if it exists, otherwise the name + //this needs to support both schema's so get the nodeTypeAlias if it exists, otherwise the name var nodeTypeAlias = e.Node.Attribute("nodeTypeAlias") == null ? e.Node.Name.LocalName : e.Node.Attribute("nodeTypeAlias").Value; if (!e.Fields.ContainsKey(NodeTypeAliasFieldName)) e.Fields.Add(NodeTypeAliasFieldName, nodeTypeAlias); + + //add icon + var icon = (string)e.Node.Attribute("icon"); + if (!e.Fields.ContainsKey(IconFieldName)) + e.Fields.Add(IconFieldName, icon); + } /// @@ -536,6 +554,9 @@ namespace UmbracoExamine //adds the special node type alias property to the index fields.Add(NodeTypeAliasFieldName, allValuesForIndexing[NodeTypeAliasFieldName]); + //icon + fields.Add(IconFieldName, allValuesForIndexing[IconFieldName]); + return fields; }