/// <summary> /// We will need to first check if the document was loaded by Examine, if so we'll need to check if this property exists /// in the results, if it does not, then we'll have to revert to looking up in the db. /// </summary> /// <param name="dd"> </param> /// <param name="alias"></param> /// <returns></returns> private IPublishedProperty GetProperty(DictionaryPublishedContent dd, string alias) { if (dd.LoadedFromExamine) { //if this is from Examine, lets check if the alias does not exist on the document if (dd.Properties.All(x => x.PropertyTypeAlias != alias)) { //ok it doesn't exist, we might assume now that Examine didn't index this property because the index is not set up correctly //so before we go loading this from the database, we can check if the alias exists on the content type at all, this information //is cached so will be quicker to look up. if (dd.Properties.Any(x => x.PropertyTypeAlias == UmbracoContentIndexer.NodeTypeAliasFieldName)) { // so in dd.Properties, there is an IPublishedProperty with property type alias "__NodeTypeAlias" and // that special property would contain the node type alias, which we use to get "aliases & names". That // special property is going to be a PropertyResult (with Value == DataValue) and we // want its value in the most simple way = it is OK to use DataValue here. var aliasesAndNames = ContentType.GetAliasesAndNames(dd.Properties.First(x => x.PropertyTypeAlias.InvariantEquals(UmbracoContentIndexer.NodeTypeAliasFieldName)).DataValue.ToString()); if (aliasesAndNames != null) { if (!aliasesAndNames.ContainsKey(alias)) { //Ok, now we know it doesn't exist on this content type anyways return(null); } } } //if we've made it here, that means it does exist on the content type but not in examine, we'll need to query the db :( var media = global::umbraco.library.GetMedia(dd.Id, true); if (media != null && media.Current != null) { media.MoveNext(); var mediaDoc = ConvertFromXPathNavigator(media.Current); return(mediaDoc.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(alias))); } } } //We've made it here which means that the value is stored in the Examine index. //We are going to check for a special field however, that is because in some cases we store a 'Raw' //value in the index such as for xml/html. var rawValue = dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(UmbracoContentIndexer.RawFieldPrefix + alias)); return(rawValue ?? dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(alias))); }
/// <summary> /// We will need to first check if the document was loaded by Examine, if so we'll need to check if this property exists /// in the results, if it does not, then we'll have to revert to looking up in the db. /// </summary> /// <param name="dd"> </param> /// <param name="alias"></param> /// <returns></returns> private IPublishedContentProperty GetProperty(DictionaryPublishedContent dd, string alias) { if (dd.LoadedFromExamine) { //if this is from Examine, lets check if the alias does not exist on the document if (dd.Properties.All(x => x.Alias != alias)) { //ok it doesn't exist, we might assume now that Examine didn't index this property because the index is not set up correctly //so before we go loading this from the database, we can check if the alias exists on the content type at all, this information //is cached so will be quicker to look up. if (dd.Properties.Any(x => x.Alias == "__NodeTypeAlias")) { var aliasesAndNames = ContentType.GetAliasesAndNames(dd.Properties.First(x => x.Alias.InvariantEquals("__NodeTypeAlias")).Value.ToString()); if (aliasesAndNames != null) { if (!aliasesAndNames.ContainsKey(alias)) { //Ok, now we know it doesn't exist on this content type anyways return(null); } } } //if we've made it here, that means it does exist on the content type but not in examine, we'll need to query the db :( var media = global::umbraco.library.GetMedia(dd.Id, true); if (media != null && media.Current != null) { media.MoveNext(); var mediaDoc = ConvertFromXPathNavigator(media.Current); return(mediaDoc.Properties.FirstOrDefault(x => x.Alias.InvariantEquals(alias))); } } } return(dd.Properties.FirstOrDefault(x => x.Alias.InvariantEquals(alias))); }