public static T GetPropertyValue <T>(this ISearchContent item, string property, T defaultValue) { if (item.Properties.ContainsKey(property)) { return((T)item.Properties[property]); } return(defaultValue); }
public static SearchResultItem Map(ISearchContent item) { var e = new SearchResultItem(); e.Name = item.Name; e.Id = item.Id; e.ParentId = item.ParentId; e.Key = new System.Guid(item.Key); e.Icon = item.GetPropertyValue <string>("Icon"); e.Trashed = item.GetPropertyValue <bool>("Trashed"); e.Alias = null; var path = item.Path; if (path != null) { e.Path = string.Join(",", path); } return(e); }
private SearchResult Convert(ISearchContent azureResult) { if (azureResult == null) { return(null); } var result = new SearchResult { Id = azureResult.Id, Score = (float)azureResult.Score, }; if (result.Fields == null) { return(result); } var indexType = "content"; var publishedContentType = PublishedItemType.Content; if (azureResult.IsMedia) { indexType = "media"; result.Fields.Add("umbracoFile", azureResult.Url); publishedContentType = PublishedItemType.Media; } if (azureResult.IsMember) { indexType = "member"; publishedContentType = PublishedItemType.Member; } var matchHighlights = string.Empty; if (azureResult.Properties?.ContainsKey("__match") == true) { if (azureResult.Properties["__match"] is HitHighlights matchObj) { matchHighlights = JsonConvert.SerializeObject(matchObj, BaseAzureSearch.GetSerializationSettings()); } } result.Fields.Add("__IndexType", indexType); result.Fields.Add("__NodeId", azureResult.Id.ToString()); result.Fields.Add("__Path", $"-{azureResult.SearchablePath}"); result.Fields.Add("__NodeTypeAlias", azureResult.ContentTypeAlias?.ToLower()); result.Fields.Add("__Key", azureResult.Key); result.Fields.Add("__Match", matchHighlights); result.Fields.Add("id", azureResult.Id.ToString()); result.Fields.Add("key", azureResult.Key); result.Fields.Add("parentID", azureResult.ParentId.ToString()); result.Fields.Add("level", azureResult.Level.ToString()); result.Fields.Add("creatorID", azureResult.CreatorId.ToString()); result.Fields.Add("creatorName", azureResult.CreatorName); result.Fields.Add("writerID", azureResult.WriterId.ToString()); result.Fields.Add("writerName", azureResult.CreatorName); result.Fields.Add("template", azureResult.Template.IsNullOrWhiteSpace() ? "0" : azureResult.Template); result.Fields.Add("urlName", azureResult.UrlName ?? ""); result.Fields.Add("sortOrder", azureResult.SortOrder.ToString()); result.Fields.Add("createDate", azureResult.CreateDate.ToString("yyyyMMddHHmmsss")); result.Fields.Add("updateDate", azureResult.UpdateDate.ToString("yyyyMMddHHmmsss")); result.Fields.Add("path", $"-{azureResult.SearchablePath}"); result.Fields.Add("nodeType", azureResult.ContentTypeId.ToString()); result.Fields.Add("nodeName", azureResult.Name); if (azureResult.Properties == null) { return(result); } // only add valid properties for this content type var contentType = PublishedContentType.Get(publishedContentType, azureResult.ContentTypeAlias); var validProperties = contentType?.PropertyTypes?.Select(p => p.PropertyTypeAlias).ToList(); foreach (var prop in azureResult.Properties) { if (prop.Key == null || prop.Value == null) { continue; } if (validProperties?.Contains(prop.Key) == true) { result.Fields[prop.Key] = GetPropertyString(prop.Value); } } var icon = ""; object iconObj = null; if (azureResult.Properties?.TryGetValue("Icon", out iconObj) == true) { icon = iconObj.ToString(); } result.Fields.Add("__Icon", icon); return(result); }
public static string GetPropertyValue(this ISearchContent item, string property) { return(GetPropertyValue <string>(item, property, default(string))); }
public static T GetPropertyValue <T>(this ISearchContent item, string property) { return(GetPropertyValue(item, property, default(T))); }