public void Convert_From_Search_Result() { var result = new SearchResult() { Id = 1234, Score = 1 }; result.Fields.Add("__IndexType", "media"); result.Fields.Add("__NodeId", "1234"); result.Fields.Add("__NodeTypeAlias", "Image"); result.Fields.Add("__Path", "-1,1234"); result.Fields.Add("__nodeName", "Test"); result.Fields.Add("id", "1234"); result.Fields.Add("nodeName", "Test"); result.Fields.Add("nodeTypeAlias", "Image"); result.Fields.Add("parentID", "-1"); result.Fields.Add("path", "-1,1234"); result.Fields.Add("updateDate", "2012-07-16T10:34:09"); result.Fields.Add("writerName", "Shannon"); var store = new DefaultPublishedMediaStore(); var doc = store.ConvertFromSearchResult(result); DoAssert(doc, 1234, 0, 0, "", "Image", 0, "Shannon", "", 0, 0, "-1,1234", default(DateTime), DateTime.Parse("2012-07-16T10:34:09"), 2); Assert.AreEqual(null, doc.Parent); }
/// <summary> /// Initializes a new instance of the <see cref="UwbsImage"/> class. /// </summary> /// <param name="examineNode">The examine node.</param> public UwbsImage(SearchResult examineNode) { if (examineNode.Fields.ContainsKey("umbracoFile")) { UmbracoFile = examineNode.Fields["umbracoFile"]; } }
public static string GetMultiStoreItemExamine(string propertyAlias, SearchResult examineNode, string storeAlias = null, string currencyCode = null) { if (examineNode != null) { propertyAlias = StoreHelper.MakeRTEItemPropertyAliasIfApplicable(propertyAlias); return StoreHelper.ReadMultiStoreItemFromPropertiesDictionary(propertyAlias, StoreHelper.GetLocalizationOrCurrent(storeAlias, currencyCode), new DictionaryPropertyProvider(examineNode)); } return string.Empty; }
public MemberModel(SearchResult member) { Id = member.Id; var firstName = member.Fields.ContainsKey("memberFirstName") ? member.Fields["memberFirstName"] : ""; var lastName = member.Fields.ContainsKey("memberLastName") ? member.Fields["memberLastName"] : ""; var loginName = member.Fields.ContainsKey("loginName") ? member.Fields["loginName"] : ""; var hasMultipleData = member.Fields.ContainsKey("hasMultipleData") && member.Fields["hasMultipleData"] == "1"; var memberName = firstName + " " + lastName + (hasMultipleData ? " **" : ""); Title = String.IsNullOrEmpty(memberName.Trim()) ? loginName : memberName; Date = String.Format("{0}/{1}/{2}", member.Fields["createDate"].Substring(4, 2), member.Fields["createDate"].Substring(6, 2), member.Fields["createDate"].Substring(0, 4)); }
/// <summary> /// Maps an Umbraco 'Examine' Search Result to the ForumCategory type /// </summary> /// <param name="nodetomap"></param> /// <returns></returns> public ForumCategory MapForumCategory(SearchResult nodetomap) { if (nodetomap == null) return null; var fCat = new ForumCategory { Id = nodetomap.Id, Name = CheckFieldExists(nodetomap, "nodeName"), Url = library.NiceUrl(nodetomap.Id), CreatedOn = Convert.ToDateTime(CheckFieldExists(nodetomap, "__Sort_createDate")), ParentId = CheckFieldExists(nodetomap, "parentID").ToInt32(), Description = CheckFieldExists(nodetomap, "forumCategoryDescription"), IsMainCategory = CheckFieldExists(nodetomap, "forumCategoryIsMainCategory") == "1", IsPrivate = CheckFieldExists(nodetomap, "forumCategoryIsPrivate") == "1", KarmaAccessAmount = CheckFieldExists(nodetomap, "forumCategoryPermissionKarmaAmount").ToInt32(), KarmaPostAmount = CheckFieldExists(nodetomap, "forumCategoryPostPermissionKarmaAmount").ToInt32(), ParentCategoryId = CheckFieldExists(nodetomap, "forumCategoryParentID").ToInt32(), SortOrder = CheckFieldExists(nodetomap, "sortOrder").ToInt32() }; return fCat; }
private SelfServiceActionPage(SearchResult result, IPublishedContent content) { Id = result.Id; if (content == null) { string title; Title = result.Fields.TryGetValue("title", out title) ? title : result.Fields["nodeName"]; Categories = new SelfServiceCategory[0]; } else { Title = content.HasValue("title") ? content.GetPropertyValue<string>("title") : content.Name; Url = content.Url; Categories = content.GetPropertyValue<SelfServiceCategory[]>("skySelfServiceCategories") ?? new SelfServiceCategory[0]; } }
/// <summary> /// Maps an Umbraco Examine 'Topic' Search Result to the ForumTopic type /// </summary> /// <param name="nodetomap"></param> /// <returns></returns> public ForumTopic MapForumTopic(SearchResult nodetomap) { if (nodetomap == null) return null; var fCat = new ForumTopic { Id = nodetomap.Id, Url = library.NiceUrl(nodetomap.Id), Name = CheckFieldExists(nodetomap, "nodeName"), CreatedOn = Convert.ToDateTime(CheckFieldExists(nodetomap, "__Sort_createDate")), ParentId = CheckFieldExists(nodetomap, "parentID").ToInt32(), CategoryId = CheckFieldExists(nodetomap, "forumTopicParentCategoryID").ToInt32(), Owner = MembershipHelper.ReturnMember(CheckFieldExists(nodetomap, "forumTopicOwnedBy").ToInt32()), IsClosed = CheckFieldExists(nodetomap, "forumTopicClosed") == "1", IsSolved = CheckFieldExists(nodetomap, "forumTopicSolved") == "1", IsSticky = CheckFieldExists(nodetomap, "forumTopicIsSticky") == "1", SubscriberIds = Helpers.StringArrayToIntList(CheckFieldExists(nodetomap, "forumTopicSubscribedList")), SortOrder = CheckFieldExists(nodetomap, "sortOrder").ToInt32(), LastPostDate = Helpers.InternalDateFixer(CheckFieldExists(nodetomap, "__Sort_forumTopicLastPostDate")) }; return fCat; }
/// <summary> /// Maps an Umbraco Examine 'Post' Search Result to the ForumPost type /// </summary> /// <param name="nodetomap"></param> /// <returns></returns> public ForumPost MapForumPost(SearchResult nodetomap) { if (nodetomap == null) return null; var fCat = new ForumPost { Id = nodetomap.Id, Url = library.NiceUrl(nodetomap.Id), Name = CheckFieldExists(nodetomap, "nodeName"), CreatedOn = Convert.ToDateTime(CheckFieldExists(nodetomap, "__Sort_createDate")), ParentId = CheckFieldExists(nodetomap, "parentID").ToInt32(), Content = Helpers.HtmlDecode(CheckFieldExists(nodetomap, "forumPostContent")), Owner = MembershipHelper.ReturnMember(CheckFieldExists(nodetomap, "forumPostOwnedBy").ToInt32()), LastEdited = Helpers.InternalDateFixer(CheckFieldExists(nodetomap, "__Sort_forumPostLastEdited")), IsSolution = CheckFieldExists(nodetomap, "forumPostIsSolution") == "1", IsTopicStarter = CheckFieldExists(nodetomap, "forumPostIsTopicStarter") == "1", Karma = CheckFieldExists(nodetomap, "forumPostKarma").ToInt32(), VotedMembersIds = Helpers.StringArrayToIntList(CheckFieldExists(nodetomap, "forumPostUsersVoted")), ParentTopicId = CheckFieldExists(nodetomap, "forumPostParentID").ToInt32(), SortOrder = CheckFieldExists(nodetomap, "sortOrder").ToInt32() }; return fCat; }
protected SearchResult CreateSearchResult(Document doc, float score) { string id = doc.Get("id"); if (string.IsNullOrEmpty(id)) { id = doc.Get(LuceneIndexer.IndexNodeIdFieldName); } var sr = new SearchResult() { Id = int.Parse(id), Score = score }; //we can use lucene to find out the fields which have been stored for this particular document //I'm not sure if it'll return fields that have null values though var fields = doc.GetFields(); //ignore our internal fields though foreach (Field field in fields.Cast<Field>()) { sr.Fields.Add(field.Name(), doc.Get(field.Name())); } return sr; }
internal UmbracoNode(SearchResult searchResult) { propertyProvider = new DictionaryPropertyProvider(searchResult); LoadFieldsFromExamine(propertyProvider); }
protected SearchResult CreateSearchResult(Document doc, float score) { string id = doc.Get("id"); if (string.IsNullOrEmpty(id)) { id = doc.Get(LuceneIndexer.IndexNodeIdFieldName); } var sr = new SearchResult() { Id = int.Parse(id), Score = score }; //we can use lucene to find out the fields which have been stored for this particular document //I'm not sure if it'll return fields that have null values though var fields = doc.GetFields(); //ignore our internal fields though foreach (var field in fields.Cast<Field>()) { var fieldName = field.Name(); var values = doc.GetValues(fieldName); if (values.Length > 1) { sr.MultiValueFields[fieldName] = values.ToList(); //ensure the first value is added to the normal fields sr.Fields[fieldName] = values[0]; } else if (values.Length > 0) { sr.Fields[fieldName] = values[0]; } } return sr; }
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); }
/// <summary> /// Initializes a new instance of the <see cref="DictionaryPropertyProvider"/> class. /// </summary> /// <param name="searchResult">The search result.</param> public DictionaryPropertyProvider(SearchResult searchResult) { _searchResult = searchResult; }
public static SelfServiceActionPage GetFromResult(SearchResult result) { if (result == null) return null; IPublishedContent content = (UmbracoContext.Current == null ? null : UmbracoContext.Current.ContentCache.GetById(result.Id)); return new SelfServiceActionPage(result, content); }
public SelfServiceActionPageResult(SearchResult result, SelfServiceActionPage page) { Result = result; Page = page; }
/// <summary> /// This just checks the field exists and then returns the value, /// lucene is a frickin pain in the arse /// </summary> /// <returns></returns> private string CheckFieldExists(SearchResult result, string keyName) { return result.Fields.ContainsKey(keyName) ? result.Fields[keyName] : ""; }
public SelfServiceActionPage ParseActionPage(SearchResult result) { // If "result" is NULL, we don't bother doing any further parsing if (result == null) return null; // Iterate through the added plugins foreach (SelfServicePluginBase plugin in Context.Plugins) { // Let the plugin parse the action page (NULL means the plugin didn't handle or parse the category) SelfServiceActionPage actionPage = plugin.ParseActionPage(result); if (actionPage != null) return actionPage; } // Fallback if no plugins did handle or parse the action page return SelfServiceActionPage.GetFromResult(result); }
/// <summary> /// Parses the specified <code>result</code> into an instance of <code>SelfServiceActionPage</code>. /// </summary> /// <param name="result">An instance of <code>SearchResult</code> representing the action page.</param> /// <returns>Returns an instance of <code>SelfServiceActionPage</code>.</returns> public SelfServiceActionPage ParseActionPage(SearchResult result) { return null; }