Exemplo n.º 1
0
        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);
        }
 public ChannelExtensionsProcessor(IAzureBlobClient azureBlobClient, IAzureSearchClient <PersonIndex> azureSearchClient, ILogger logger)
 {
     _azureBlobClient   = azureBlobClient;
     _azureSearchClient = azureSearchClient;
     _logger            = logger;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="azureSearchClient"></param>
 public AzureSearchManagement(IAzureSearchClient azureSearchClient)
 {
     this.azureSearchClient = azureSearchClient;
 }