public IEnumerable <EntityTypeSearchResult> Search(string query) { var allowedSections = Security.CurrentUser.AllowedSections.ToArray(); if (string.IsNullOrEmpty(query)) { return(Enumerable.Empty <EntityTypeSearchResult>()); } var result = new List <EntityTypeSearchResult>(); var client = AzureSearchContext.Instance.GetSearchClient(); // if the search term contains a space this will be transformed to %20 and no search results returned // so lets decode the query term to turn it back into a proper space // will this mess up any other Url encoded terms? or fix them too? query = HttpUtility.UrlDecode(query); var searchResults = client.Term(query + "*").Results(); if (allowedSections.InvariantContains(Constants.Applications.Content)) { var entities = new List <EntityBasic>(); foreach (var searchResult in searchResults.Content) { if (searchResult.IsContent) { var entity = SearchContentToEntityBasicMapper.Map(searchResult); entities.Add(entity); } } result.Add(new EntityTypeSearchResult { Results = entities, EntityType = UmbracoEntityTypes.Document.ToString() }); } if (allowedSections.InvariantContains(Constants.Applications.Media)) { var entities = new List <EntityBasic>(); foreach (var searchResult in searchResults.Content) { if (searchResult.IsMedia) { var entity = SearchContentToEntityBasicMapper.Map(searchResult); entities.Add(entity); } } result.Add(new EntityTypeSearchResult { Results = entities, EntityType = UmbracoEntityTypes.Media.ToString() }); } if (allowedSections.InvariantContains(Constants.Applications.Members)) { var entities = new List <EntityBasic>(); foreach (var searchResult in searchResults.Content) { if (searchResult.IsMember) { var entity = SearchContentToEntityBasicMapper.Map(searchResult); entities.Add(entity); } } result.Add(new EntityTypeSearchResult { Results = entities, EntityType = UmbracoEntityTypes.Member.ToString() }); } return(result); }
public IEnumerable <EntityTypeSearchResult> Search(string query) { var allowedSections = Security.CurrentUser.AllowedSections.ToArray(); if (string.IsNullOrEmpty(query)) { return(Enumerable.Empty <EntityTypeSearchResult>()); } var result = new List <EntityTypeSearchResult>(); var client = AzureSearchContext.Instance.GetSearchClient(); var searchResults = client.Term(query + "*").Results(); if (allowedSections.InvariantContains(Constants.Applications.Content)) { var entities = new List <EntityBasic>(); foreach (var searchResult in searchResults.Content) { if (searchResult.IsContent) { var entity = SearchContentToEntityBasicMapper.Map(searchResult); entities.Add(entity); } } result.Add(new EntityTypeSearchResult { Results = entities, EntityType = UmbracoEntityTypes.Document.ToString() }); } if (allowedSections.InvariantContains(Constants.Applications.Media)) { var entities = new List <EntityBasic>(); foreach (var searchResult in searchResults.Content) { if (searchResult.IsMedia) { var entity = SearchContentToEntityBasicMapper.Map(searchResult); entities.Add(entity); } } result.Add(new EntityTypeSearchResult { Results = entities, EntityType = UmbracoEntityTypes.Media.ToString() }); } if (allowedSections.InvariantContains(Constants.Applications.Members)) { var entities = new List <EntityBasic>(); foreach (var searchResult in searchResults.Content) { if (searchResult.IsMember) { var entity = SearchContentToEntityBasicMapper.Map(searchResult); entities.Add(entity); } } result.Add(new EntityTypeSearchResult { Results = entities, EntityType = UmbracoEntityTypes.Member.ToString() }); } return(result); }
public IDictionary <string, TreeSearchResult> Search(string query) { IDictionary <string, TreeSearchResult> result = GetTreeSearchResultStructure(); if (string.IsNullOrEmpty(query)) { return(result); } IAzureSearchClient client = AzureSearchContext.Instance.GetSearchClient(); // if the search term contains a space this will be transformed to %20 and no search results returned // so lets decode the query term to turn it back into a proper space // will this mess up any other Url encoded terms? or fix them too? query = HttpUtility.UrlDecode(query); ISearchResult searchResults = client.Term(query + "*").Results(); if (result.Keys.Any(x => x.Equals(Constants.Applications.Content, StringComparison.CurrentCultureIgnoreCase))) { List <SearchResultItem> entities = new List <SearchResultItem>(); foreach (ISearchContent searchResult in searchResults.Content.Where(c => c.IsContent).Take(NumberOfItemsPerSection)) { var entity = SearchContentToEntityBasicMapper.Map(searchResult); entities.Add(entity); } result.First(x => x.Key.Equals(Constants.Applications.Content, StringComparison.CurrentCultureIgnoreCase)) .Value.Results = entities; } if (result.Keys.Any(x => x.Equals(Constants.Applications.Media, StringComparison.CurrentCultureIgnoreCase))) { List <SearchResultItem> entities = new List <SearchResultItem>(); foreach (ISearchContent searchResult in searchResults.Content.Where(c => c.IsMedia).Take(NumberOfItemsPerSection)) { var entity = SearchContentToEntityBasicMapper.Map(searchResult); entities.Add(entity); } result.First(x => x.Key.Equals(Constants.Applications.Media, StringComparison.CurrentCultureIgnoreCase)) .Value.Results = entities; } if (result.Keys.Any(x => x.Equals(Constants.Applications.Members, StringComparison.CurrentCultureIgnoreCase))) { List <SearchResultItem> entities = new List <SearchResultItem>(); ApplicationTree tree = Services.ApplicationTreeService.GetByAlias(Constants.Applications.Members); foreach (ISearchContent searchResult in searchResults.Content.Where(c => c.IsMember).Take(NumberOfItemsPerSection)) { var entity = SearchContentToEntityBasicMapper.Map(searchResult); entities.Add(entity); } result.First(x => x.Key.Equals(Constants.Applications.Members, StringComparison.CurrentCultureIgnoreCase)) .Value.Results = entities; } return(result); }