private List <BlendedListItem> GetContentFor() { List <Type> dynamicTypes = new List <Type>(); string postUrl = "/"; List <BlendedListItem> result = new List <BlendedListItem>(); try { //var dynamicModuleManager = DynamicModuleManager.GetManager(); //var taxonomyManager = TaxonomyManager.GetManager(); var currentContext = System.Web.HttpContext.Current; IList <SitefinityWebApp.Mvc.Models.BlendedListItem> actResult = new List <BlendedListItem>(); postUrl = currentContext.Request.Url.AbsolutePath; var dynamicTypeNames = AppSettingsUtility.GetValue <string>("RelatedItems.DynamicType.List").Split('|').ToList(); dynamicTypes = dynamicTypeNames.Select(dynamicTypeName => TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model." + dynamicTypeName)).ToList(); /*if (postUrl.Contains('?')) * { * //log.Debug("postUrl contains a '?'."); * postUrl = postUrl.Split('?').First(); * //log.Trace("postUrl: {0}", postUrl.IsNullOrEmpty() ? "There is no url available" : postUrl); * }*/ postUrl = currentContext.Request.Url.AbsolutePath.Split('/').Last(); result = GetNewsBlendedForUrl(dynamicTypes, postUrl); } catch (Exception ex) { log.Info(StringExtensions.Fmt("error {0}", ex.Message)); } return(result); }
void directorySearchSubmit_Click(object sender, EventArgs e) { var urlString = "http://" + HttpContext.Current.Request.Url.Host + AppSettingsUtility.GetValue <String>("Url.MaxxDirectorySearch"); var searchUrl = new Uri(urlString); var parameters = HttpUtility.ParseQueryString(searchUrl.Query); parameters.Add(new NameValueCollection() { { "anyName", anyName.Text } }); Response.Redirect(searchUrl.GetLeftPart(UriPartial.Path) + "?" + parameters); }
//public static IResultSet GetNewsItems(string[] providers, out int hitCount, Guid[] categories = null, string terms = null, int skip = 0, int take = 0) public static IResultSet GetNewsItems(out int hitCount, Guid[] categories = null, string terms = null, int skip = 0, int take = 0) { var searchService = ServiceBus.ResolveService <ISearchService>(); var searchQuery = BuildQuery(categories); var catalogName = AppSettingsUtility.GetValue <string>("KeyIssuesCatalogName"); var orderBy = new[] { "PublishDate DESC" }; IResultSet resultSet; if (skip == 0 && take == 0) { resultSet = searchService.Search(catalogName, searchQuery, null, orderBy, new object[0]); } else { resultSet = searchService.Search(catalogName, searchQuery, null, skip, take, orderBy, new object[0]); } hitCount = resultSet.HitCount; return(resultSet); }
public static List <Tuple <string, string, int> > SearchTypes() { return(SearchTypes(AppSettingsUtility.GetValue <string>("ContentListContentTypeFilterMapList"))); }
protected override void HandleUnknownAction(string actionName = "") { try { log.Info("Begin HandleUnknownAction. view:{0}", _viewTemplate); var dynamicModuleManager = DynamicModuleManager.GetManager(); /*if (string.IsNullOrEmpty(_viewTemplate)) * { * this.View(new EmptyResult()).ExecuteResult(ControllerContext); * * }*/ var dynamicTypes = new List <Type>(); var dynamicTypeNames = AppSettingsUtility.GetValue <string>("RelatedItems.DynamicType.List").Split('|').ToList(); foreach (var dynamicTypeName in dynamicTypeNames) { if (!string.IsNullOrWhiteSpace(dynamicTypeName)) { dynamicTypes.Add(TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model." + dynamicTypeName)); } } // set default if (dynamicTypes.Count == 0) { dynamicTypes.Add(TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.OnSceneArticles.OnSceneArticle")); } var taxonomyManager = TaxonomyManager.GetManager(); var currentContext = System.Web.HttpContext.Current; var postUrl = currentContext.Request.Url.AbsolutePath; if (postUrl.Contains('?')) { postUrl = postUrl.Split('?').First(); log.Trace("postUrl: {0}", SitefinityExtensions.IsNullOrEmpty(postUrl) ? "There is no url available" : postUrl); } postUrl = currentContext.Request.Url.AbsolutePath.Split('/').Last(); log.Debug("postUrl: {0}", SitefinityExtensions.IsNullOrEmpty(postUrl) ? "There is no url available" : postUrl); foreach (var dynamicType in dynamicTypes) { var item = dynamicModuleManager.GetDataItems(dynamicType) .FirstOrDefault(bp => bp.UrlName == postUrl && bp.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live); if (item != null) { //log.Debug("item: {0}", SitefinityExtensions.IsNullOrEmpty(item.GetValue<Lstring>("Title").Value) ? "There is no title set" : item.GetValue<Lstring>("Title").Value); //---item = dynamicModuleManager.Lifecycle.GetLive(item) as DynamicContent; //log.Trace("Got the live version of the Blog Post."); try { //var allCategories = Enumerable.ToArray(item.GetValue<IList<Guid>>("Category")); var allCategories = item.GetValue <IList <Guid> >("Category")?.ToArray(); //log.Debug("Got a list of category ids for the post, {0}.", allCategories.Count()); List <Guid> categories = new List <Guid>(); //log.Trace("Set the list for Blended List Query."); int hitCount = 0; //log.Trace("Set the hitcount variable required for Sitefinity Search."); if (allCategories != null && allCategories.Any()) { foreach (var currGuid in allCategories) { var currTaxon = taxonomyManager.GetTaxon <HierarchicalTaxon>(currGuid); if (currTaxon != null) { //log.Debug("Got taxonomy, {0}, for the id, {1}", SitefinityExtensions.IsNullOrEmpty(currTaxon.Title.Value) ? "There is no title set" : currTaxon.Title.Value); categories.Add(currGuid); //log.Trace("Taxon added to the list for the search."); } } } IEnumerable <IDocument> resultListItems = BlendedNewsHelper.GetNewsDocs(Providers, _searchIndex, out hitCount, categories?.ToArray(), null, 0, this.NumberOfPosts + 10); List <BlendedListItem> blendedListItems = new List <BlendedListItem>(); if (resultListItems != null) { var rs = SetBlendedListItems(resultListItems); if (rs != null) { blendedListItems = rs .Where(bli => !bli.Link.Contains(item.UrlName) && !bli.Featured).Take(this.NumberOfPosts).ToList(); } } //string template = _viewTemplate; //log.Info("Finishing HandleUnknownAction"); this.View(_viewTemplate, blendedListItems).ExecuteResult(ControllerContext); } catch (Exception ex) { log.Error("Source: {0}", ex.Source); log.Error("Stack Trace: {0}", ex.StackTrace); log.Error("HandleUnknownAction-relatedContentForDyn: {0}", ex.Message); } } else { log.Debug("There was no item for the given url, ({0}).", SitefinityExtensions.IsNullOrEmpty(postUrl) ? "There is no url available" : postUrl); } } } catch (Exception ex) { log.Info("exceptionRelatedContent:{0}, inner:{1}", ex.Message, ex.InnerException?.Message); } }
private void AddMetaDataTagsFromArticle(DynamicContent dynamicContent) { Page.RemoveExistingPublishedTags(); // add published date tags Page.AddCustomMetaTags("Published", dynamicContent.PublicationDate.ToString("yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture)); TaxonomyManager taxonomyManager = TaxonomyManager.GetManager(); if (dynamicContent.DoesFieldExist("Category")) { TrackedList <Guid> categoryIds = dynamicContent.GetValue("Category") as TrackedList <Guid>; if (categoryIds != null && categoryIds.Any()) { var categoryList = string.Join(",", categoryIds.Select(cid => taxonomyManager.GetTaxon(cid).Title)); Page.AddCustomMetaTags("webcategory", categoryList); } } if (dynamicContent.DoesFieldExist("resourcetypes")) { TrackedList <Guid> resourcetypesIds = dynamicContent.GetValue("resourcetypes") as TrackedList <Guid>; if (resourcetypesIds != null && resourcetypesIds.Any()) { var resourcetypesList = string.Join(",", resourcetypesIds.Select(cid => taxonomyManager.GetTaxon(cid).Title)); Page.AddCustomMetaTags("resourcetypes", resourcetypesList); } } Page.RemoveExistingModuleTags(); string modulePage = dynamicContent.GetType().Name; try { if (!AppSettingsUtility.GetValue <string>("MetaDataTags.Article.Name").IsNullOrWhitespace()) { modulePage = AppSettingsUtility.GetValue <string>("MetaDataTags.Article.Name"); } } catch (Exception) { } Page.AddCustomMetaTags("Module", modulePage); Type type; if (dynamicContent.SystemParentItem != null) { type = dynamicContent.SystemParentItem.GetType(); } else { type = dynamicContent.GetType(); } string articleType = type.FullName.Split('.')[4]; //Could change this to work with On-Scene Articles... if (articleType.ToLower().Contains("healthprogress")) { Page.AddCustomMetaTags("Publication", "Health Progress"); //Health Progress } if (dynamicContent.DoesFieldExist("author")) { var authorname = dynamicContent.Author; if (authorname != null) { Page.AddCustomMetaTags("ContentAuthor", authorname); } } var authorsFieldName = "organizationalauthors"; if (dynamicContent.DoesFieldExist(authorsFieldName)) { TrackedList <Guid> authorIds = dynamicContent.GetValue(authorsFieldName) as TrackedList <Guid>; if (authorIds != null) { var authorList = string.Join(",", authorIds.Select(cid => taxonomyManager.GetTaxon(cid).Title)); Page.AddCustomMetaTags("contentauthor", authorList); } } }
public void metaData_ItemDataBound(object sender, RadListViewItemEventArgs e) { if (e.Item is RadListViewDataItem) { var dataItem = ((RadListViewDataItem)e.Item).DataItem; var contentItem = dataItem as Content; #region searchblox tags Page.RemoveExistingPublishedTags(); Page.RemoveExistingModuleTags(); // get data type and add content type var dataType = dataItem.GetType().Name; if (dataType == "NewsItem") { // add published date tags Page.AddCustomMetaTags("Published", contentItem.PublicationDate.ToString("yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture)); try { if (!AppSettingsUtility.GetValue <string>("MetaDataTags.NewsItem.Name").IsNullOrWhitespace()) { dataType = AppSettingsUtility.GetValue <string>("MetaDataTags.NewsItem.Name"); } } catch (Exception ex) { } Page.AddCustomMetaTags("Module", dataType); // get data type and add content type // add categories var taxonomyManager = TaxonomyManager.GetManager(); var categoryIds = contentItem.GetValue("Category") as TrackedList <Guid>; if (categoryIds.Any()) { var categoryList = string.Join(",", categoryIds.Select(cid => taxonomyManager.GetTaxon(cid).Title)); /* This works because the meta tag is allowed to have a * comma-separated list of values to denote multiple * categories. The list will simply be converted to * the correct format. */ Page.AddCustomMetaTags("webcategory", categoryList); } NewsItem newsContent = dataItem as NewsItem; if (newsContent != null && newsContent.Author != null) { string author = newsContent.Author.Value; Page.AddCustomMetaTags("Author", author); } } else if (dataType == "BlogPost") { try { if (!AppSettingsUtility.GetValue <string>("MetaDataTags.BlogPost.Name").IsNullOrWhitespace()) { dataType = AppSettingsUtility.GetValue <string>("MetaDataTags.BlogPost.Name"); } } catch (Exception ex) { } Page.AddCustomMetaTags("Module", dataType); } else if (dataType == "Event") { try { if (!AppSettingsUtility.GetValue <string>("MetaDataTags.Event.Name").IsNullOrWhitespace()) { dataType = AppSettingsUtility.GetValue <string>("MetaDataTags.Event.Name"); } } catch (Exception ex) { } Page.AddCustomMetaTags("Module", dataType); } #endregion } }
public static IEnumerable <SearchResult> GetSearchResults_stv(string catalog, SearchCriteria criteria, int skip, int take, int summaryWordCount, out int hitCount) { var searchService = ServiceBus.ResolveService <ISearchService>(); var searchQuery = ObjectFactory.Resolve <ISearchQuery>(); var queryBuilder = ObjectFactory.Resolve <IQueryBuilder>(); StringBuilder sb = new StringBuilder(); searchQuery.Skip = skip; searchQuery.Take = take; searchQuery.OrderBy = criteria.OrderBy == null ? new string[] { "PublicationDate DESC" } : new string[] { criteria.OrderBy }; searchQuery.HighlightedFields = null; searchQuery.IndexName = catalog; searchQuery.SearchGroup = BuildSearchQuery(criteria, new[] { "Title", "Content", "DocumentText" }); var resultSet = searchService.Search(searchQuery); hitCount = resultSet.HitCount; var results = new List <SearchResult>(); var taxonomyManager = TaxonomyManager.GetManager(); log.InfoFormat("ResourceLib:{0};", criteria.ToQueryString()); foreach (var result in resultSet.SetContentLinks()) { var searchResult = new SearchResult(); try { if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("CategoryIds").ToString())) { var categoryIds = result.GetValue("CategoryIds").ToString().Split(' ').ToList(); searchResult.CategoryPair = new List <CategoryPair>(); var parentGuidId = AppSettingsUtility.GetValue <Guid>("ResourceLibraryTaxonomyId"); foreach (var categoryId in categoryIds) { log.InfoFormat("ResourceLibraryTaxonomyId-cateids:{0}, parentGuidId:{1}", categoryIds, parentGuidId); var category = taxonomyManager.GetTaxon(Guid.Parse(categoryId)) as HierarchicalTaxon; do { if (category.Parent != null && category.Parent.Id == parentGuidId) { category = taxonomyManager.GetTaxon(Guid.Parse(categoryId)) as HierarchicalTaxon; var categoryPair = new CategoryPair(); categoryPair.Name = category.Title.Value; categoryPair.Guid = categoryId.ToString().Replace("-", ""); log.InfoFormat("CateInParent, Title:{0}, guid:{1}", categoryPair.Name, categoryPair.Guid); sb.Append(String.Format("CateInParent, Title:{0}, guid:{1}", categoryPair.Name, categoryPair.Guid)); searchResult.CategoryPair.Add(categoryPair); break; } category = taxonomyManager.GetTaxon(category.Parent.Id) as HierarchicalTaxon; } while (category.Parent != null); } } if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("OrganizationalAuthorsIds").ToString())) { var categoryIds = result.GetValue("OrganizationalAuthorsIds").ToString().Split(' ').ToList(); searchResult.Author = new List <CategoryPair>(); var taxonomyGuidId = AppSettingsUtility.GetValue <Guid>("ResourceLibraryTaxonomyAuthorId"); foreach (var categoryId in categoryIds) { var category = taxonomyManager.GetTaxon(Guid.Parse(categoryId)) as HierarchicalTaxon; if (category.Taxonomy.Id == taxonomyGuidId) { var categoryPair = new CategoryPair(); categoryPair.Name = category.Title.Value; categoryPair.Guid = categoryId.ToString().Replace("-", ""); searchResult.Author.Add(categoryPair); log.InfoFormat("ResourceLibraryTaxonomyAuthorId-Title:{0}, guid:{1}", categoryPair.Name, categoryPair.Guid); sb.AppendFormat("ResourceLibraryTaxonomyAuthorId-Title:{0}, guid:{1}", categoryPair.Name, categoryPair.Guid); } } } if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("ResourceTypesIds").ToString())) { var categoryIds = result.GetValue("ResourceTypesIds").ToString().Split(' ').ToList(); searchResult.ResourceTypes = new List <CategoryPair>(); var taxonomyGuidId = AppSettingsUtility.GetValue <Guid>("ResourceLibraryTaxonomyTypeId"); foreach (var categoryId in categoryIds) { var category = taxonomyManager.GetTaxon(Guid.Parse(categoryId)) as HierarchicalTaxon; if (category.Taxonomy.Id == taxonomyGuidId) { var categoryPair = new CategoryPair(); categoryPair.Name = category.Title.Value; categoryPair.Guid = categoryId.ToString().Replace("-", ""); searchResult.ResourceTypes.Add(categoryPair); log.InfoFormat("ResourceLibraryTaxonomyTypeId-Title:{0}, guid:{1}", categoryPair.Name, categoryPair.Guid); sb.AppendFormat("ResourceLibraryTaxonomyTypeId-Title:{0}, guid:{1}", categoryPair.Name, categoryPair.Guid); } } } if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("Title").ToString())) { searchResult.Title = result.GetValue("Title").ToString(); } if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("Link").ToString())) { searchResult.Link = result.GetValue("Link").ToString(); } if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("PublishDate").ToString())) { searchResult.PublicationDate = DateTime.Parse(result.GetValue("PublishDate").ToString()); } if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("DocumentLibrary").ToString())) { searchResult.DocumentFolder = result.GetValue("DocumentLibrary").ToString(); } if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("Summary").ToString())) { searchResult.Summary = result.GetValue("Summary").ToString(); } if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("ContentType").ToString())) { searchResult.Type = result.GetValue("ContentType").ToString(); } if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("ThumbnailUrl").ToString())) { searchResult.ImageUrl = result.GetValue("ThumbnailUrl").ToString(); } else if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("ImageUrl").ToString())) { searchResult.ImageUrl = result.GetValue("ImageUrl").ToString(); } var contentType = TypeResolutionService.ResolveType(searchResult.Type); searchResult.Type = contentType.Name; if (result.Fields.Any(f => f.Name == "EventStart") && !string.IsNullOrWhiteSpace(result.GetValue("EventStart").ToString())) { searchResult.EventStart = DateTime.Parse(result.GetValue("EventStart").ToString()); } if (result.Fields.Any(f => f.Name == "EventEnd") && !string.IsNullOrWhiteSpace(result.GetValue("EventEnd").ToString())) { searchResult.EventEnd = DateTime.Parse(result.GetValue("EventEnd").ToString()); } var content = result.GetValue("Content").ToString().StripHtmlTags(); var docLink = result.GetValue("DocumentLink"); var documentText = result.GetValue("DocumentText"); if (string.IsNullOrWhiteSpace(content) && !string.IsNullOrWhiteSpace(docLink.ToString())) { searchResult.Link = docLink.ToString(); content = documentText.ToString(); } if (string.IsNullOrWhiteSpace(searchResult.Summary)) { searchResult.Summary = SummaryParser.GetSummary(content, new SummarySettings(SummaryMode.Words, summaryWordCount, true, true)); } } catch (Exception ex) { //ex.ToString(); log.InfoFormat("Resources-Exception:{0}, details:{1}", ex.Message, sb.ToString()); } results.Add(searchResult); } return(results); }
public static SearchQueryGroup BuildSearchQuery(SearchCriteria model, string[] searchFields) { //GOAL: (Title:[term]* Content:[term*]) AND (Title:[secondTerm]* Content:[secondTerm]*) AND (Type:[t1] OR Type:[t2] ... OR Type:[tN]) AND (Category:[c1] ... OR Category:[cN]) //log.Trace("Keyword: {0}", keyword); var queryGroups = new SearchQueryGroup(QueryOperator.And); //var queryGroups = new List<string>(); //**** TERMS **** var documentLibraryToSearch = AppSettingsUtility.GetValue <string>("ResourceLibrary.DocumentLibrary.ToSearch"); if (!string.IsNullOrEmpty(documentLibraryToSearch)) { var SearchDocumentLibraryGroup = new SearchQueryGroup(QueryOperator.Or); var documentLibraries = documentLibraryToSearch.Split(',').ToList(); foreach (var documentLibrary in documentLibraries) { var searchTerm = new SearchTerm(); searchTerm.Field = "DocumentLibrary"; searchTerm.Value = documentLibrary; SearchDocumentLibraryGroup.AddTerm(searchTerm); } queryGroups.AddGroup(SearchDocumentLibraryGroup); } //**** TERMS **** if (!string.IsNullOrEmpty(model.Term)) { var SearchTermGroup = new SearchQueryGroup(QueryOperator.Or); var keyword = model.Term + " " + model.SecondTerm; foreach (var field in searchFields) { var keywords = keyword.Split(' '); var count = keywords.Count(); for (int i = 0; i < count; i++) { if (!SitefinityExtensions.IsNullOrEmpty(keywords[i])) { var searchTerm = new SearchTerm(); searchTerm.Field = field; //log.Trace("Search Term Field: {0}", searchTerm.Field); searchTerm.Value = keywords[i]; //log.Trace("Search Term Value: {0}", searchTerm.Value); SearchTermGroup.AddTerm(searchTerm); } } } queryGroups.AddGroup(SearchTermGroup); } //**** TYPES ***** if (model.Types != null && model.Types.Any()) { var searchTypeGroup = new SearchQueryGroup(QueryOperator.Or); foreach (var type in model.Types) { var searchTerm = new SearchTerm(); searchTerm.Field = "ResourceTypesIds"; searchTerm.Value = type; searchTypeGroup.AddTerm(searchTerm); } queryGroups.AddGroup(searchTypeGroup); } //**** TOPICS **** if (model.Topics != null && model.Topics.Any()) { var searchCategoriesGroup = new SearchQueryGroup(QueryOperator.Or); foreach (var cat in model.Topics) { var searchTerm = new SearchTerm(); searchTerm.Field = "CategoryIds"; searchTerm.Value = cat.ToString().Replace("-", ""); searchCategoriesGroup.AddTerm(searchTerm); } queryGroups.AddGroup(searchCategoriesGroup); } //**** Authors **** if (model.Authors != null && model.Authors.Any()) { var searchAuthorsGroup = new SearchQueryGroup(QueryOperator.Or); foreach (var cat in model.Authors) { var searchTerm = new SearchTerm(); searchTerm.Field = "OrganizationalAuthorsIds"; searchTerm.Value = cat.ToString().Replace("-", ""); searchAuthorsGroup.AddTerm(searchTerm); } queryGroups.AddGroup(searchAuthorsGroup); } if (model.Types == null && model.Topics == null && string.IsNullOrEmpty(model.Term) && string.IsNullOrEmpty(model.SecondTerm)) { SearchQueryGroup SearchAnyGroup = new SearchQueryGroup(QueryOperator.Or); var searchField = "Title"; var sTerm = "a* b* c* d* e* f* g* h* i* j* k* l* m* n* o* p* q* r* s* t* u* v* w* x* y* z*"; foreach (var term in sTerm.Split(' ')) { var searchTerm = new SearchTerm { Field = searchField, Value = term }; //add wildcards to the query terms SearchAnyGroup.AddTerm(searchTerm); } queryGroups.AddGroup(SearchAnyGroup); } return(queryGroups); }
public static IEnumerable <SearchResult> GetSearchResults(string catalog, SearchCriteria criteria, int skip, int take, int summaryWordCount, out int hitCount) { var searchService = ServiceBus.ResolveService <ISearchService>(); var searchQuery = ObjectFactory.Resolve <ISearchQuery>(); var queryBuilder = ObjectFactory.Resolve <IQueryBuilder>(); StringBuilder sb = new StringBuilder(); searchQuery.Skip = skip; searchQuery.Take = take; searchQuery.OrderBy = criteria.OrderBy == null ? new string[] { "PublicationDate DESC" } : new string[] { criteria.OrderBy }; searchQuery.HighlightedFields = null; searchQuery.IndexName = catalog; searchQuery.SearchGroup = BuildSearchQuery(criteria, new[] { "Title", "Content", "DocumentText" }); var resultSet = searchService.Search(searchQuery); hitCount = resultSet.HitCount; var results = new List <SearchResult>(); var taxonomyManager = TaxonomyManager.GetManager(); log.InfoFormat("ResourceLib:{0};", criteria.ToQueryString()); var searchResult = new SearchResult(); foreach (IDocument item in resultSet.SetContentLinks()) { try { var fields = item.Fields; searchResult = new SearchResult() { CategoryPair = new List <CategoryPair>(), Author = new List <CategoryPair>(), ResourceTypes = new List <CategoryPair>(), Title = item.GetValue("Title")?.ToString() ?? "", Link = item.GetValue("Link")?.ToString() ?? "", PublicationDate = DateTime.MinValue, DocumentFolder = item.GetValue("DocumentLibrary")?.ToString() ?? "", Summary = item.GetValue("Summary")?.ToString() ?? "", Type = item.GetValue("ContentType")?.ToString() ?? "", ImageUrl = item.GetValue("ThumbnailUrl")?.ToString() ?? item.GetValue("ImageUrl")?.ToString() ?? "", EventStart = DateTime.MinValue, EventEnd = DateTime.MinValue }; searchResult.Type = TypeResolutionService.ResolveType(searchResult.Type)?.Name ?? ""; if (!string.IsNullOrEmpty(item.GetValue("PublishDate")?.ToString())) { DateTime d1 = DateTime.MinValue; DateTime.TryParse(item.GetValue("PublishDate").ToString(), out d1); searchResult.PublicationDate = d1; } if (fields.Any(f => f.Name == "EventStart") && !string.IsNullOrWhiteSpace(item.GetValue("EventStart")?.ToString())) { DateTime d1 = DateTime.MinValue; DateTime.TryParse(item.GetValue("EventStart").ToString(), out d1); searchResult.EventStart = d1; } if (fields.Any(f => f.Name == "EventEnd") && !string.IsNullOrWhiteSpace(item.GetValue("EventEnd")?.ToString())) { DateTime d1 = DateTime.MinValue; DateTime.TryParse(item.GetValue("EventEnd").ToString(), out d1); searchResult.EventEnd = d1; } /*if (string.IsNullOrWhiteSpace(searchResult.Summary)) * { * searchResult.Summary = SummaryParser.GetSummary(content, new SummarySettings(SummaryMode.Words, summaryWordCount, true, true)); * }*/ sb.AppendFormat("getCategories"); if (fields.Any(f => f.Name == "CategoryIds")) { var parentGuidId = AppSettingsUtility.GetValue <Guid>("ResourceLibraryTaxonomyId"); item.GetValue("CategoryIds")?.ToString().Split(' ')? .ToList() .ForEach(m => { if (m.IsGuid()) { var category = taxonomyManager.GetTaxon(Guid.Parse(m)) as HierarchicalTaxon; //while (category?.Parent != null) //{ if (category?.Parent?.Id == parentGuidId) { searchResult.CategoryPair.Add(new CategoryPair() { Name = category.Title.Value, Guid = m.Replace("-", string.Empty) }); category = taxonomyManager.GetTaxon(category.Parent.Id) as HierarchicalTaxon; } //}; } }); } sb.AppendFormat("getAuthors"); if (fields.Any(f => f.Name == "OrganizationalAuthorsIds") && !string.IsNullOrEmpty(item.GetValue("OrganizationalAuthorsIds")?.ToString())) { item.GetValue("OrganizationalAuthorsIds").ToString().Split(' ').ToList() .ForEach(m => { var taxonomyGuidId = AppSettingsUtility.GetValue <Guid>("ResourceLibraryTaxonomyAuthorId"); if (m.IsGuid()) { var category = taxonomyManager.GetTaxon(Guid.Parse(m)) as HierarchicalTaxon; if (category?.Taxonomy?.Id != null && category.Taxonomy.Id == taxonomyGuidId) { searchResult.Author.Add(new CategoryPair() { Name = category.Title.Value, Guid = m.Replace("-", string.Empty) }); } } }); } sb.AppendFormat("getTypes"); if (fields.Any(f => f.Name == "ResourceTypesIds") && !string.IsNullOrEmpty(item.GetValue("ResourceTypesIds")?.ToString())) { item.GetValue("ResourceTypesIds").ToString().Split(' ').ToList() .ForEach(m => { var taxonomyGuidId = AppSettingsUtility.GetValue <Guid>("ResourceLibraryTaxonomyTypeId"); if (m.IsGuid()) { var category = taxonomyManager.GetTaxon(Guid.Parse(m)) as HierarchicalTaxon; if (category?.Taxonomy?.Id != null && category.Taxonomy.Id == taxonomyGuidId) { searchResult.ResourceTypes.Add(new CategoryPair() { Name = category.Title.Value, Guid = m.Replace("-", string.Empty) }); } } }); } results.Add(searchResult); log.InfoFormat("Resources-result:{0} item:{1} \r", sb.ToString(), StringExtensions.ToJson(searchResult)); } catch (Exception ex) { log.InfoFormat("testfailed:{0}, details:{1}", ex.Message, sb.ToString()); } } return(results); }