public JsonResult Get([FromQuery] SearchUrl searchUrl)
        {
            var search = _provider.TypeAhead(searchUrl);

            if (search.Failed)
            {
                _logger.LogError("Autocomplete exception - {errorMessage}. Search url - {searchUrl}.",
                                 search.ErrorMessage,
                                 searchUrl
                                 );

                return(new JsonResult(Enumerable.Empty <object>())
                {
                    StatusCode = 500
                });
            }

            var autoCompleteResponses = from result in search.Results
                                        select new AutocompleteItemResponse
            {
                Title         = result.Title,
                TypeAheadType = result.TypeAheadType,
                Link          = GetLink(result)
            };

            // Use Capitalized property names, rather than the default camel cased as this is what global nav looks for
            return(new JsonResult(autoCompleteResponses, new JsonSerializerOptions {
                PropertyNamingPolicy = null
            }));
        }
示例#2
0
        public async Task <string> Post([FromBody] SearchUrl data)
        {
            //var content = new StringContent(JsonConvert.SerializeObject(data).ToString(),
            //Encoding.UTF8, "application/json");

            var session = System.Web.HttpContext.Current.Session;

            if (session != null)
            {
                if (session["Values"] == null)
                {
                    using (HttpClient client = new HttpClient())
                    {
                        client.DefaultRequestHeaders.Add("User-Agent", "your_user_agent");
                        using (HttpResponseMessage response = await client.GetAsync(data.URL))
                            using (HttpContent content = response.Content)
                            {
                                // ... Read the string.
                                session["Values"] = await content.ReadAsStringAsync();

                                return("Send request one more time to fetch data from session!");
                            }
                    }
                }
            }

            return(JsonConvert.SerializeObject((Object)session["Values"]));
        }
        public void AutocompleteCallsSearchProviderWithSearchUrl()
        {
            var searchUrl = new SearchUrl()
            {
                q = "dia"
            };
            var result = autocompleteController.Get(searchUrl);

            mockSearchProvider.Verify(mock => mock.TypeAhead(searchUrl), Times.Once());
        }
示例#4
0
 public override int GetHashCode()
 {
     return(MoveFrom.GetHashCode() ^ SetMark.GetHashCode()
            ^ BodyFilter.GetHashCode() ^ NameFilter.GetHashCode()
            ^ SearchBoth.GetHashCode() ^ SearchUrl.GetHashCode()
            ^ UseRegex.GetHashCode() ^ ExBodyFilter.GetHashCode()
            ^ ExNameFilter.GetHashCode() ^ ExSearchBoth.GetHashCode()
            ^ ExSearchUrl.GetHashCode() ^ ExUseRegex.GetHashCode()
            ^ IsRt.GetHashCode() ^ Source.GetHashCode()
            ^ IsExRt.GetHashCode() ^ ExSource.GetHashCode()
            ^ UseLambda.GetHashCode() ^ ExUseLambda.GetHashCode());
 }
示例#5
0
        private void setSearchUrl()
        {
            SearchUrl = String.Format("{0}/SearchResults.aspx", SiteUtils.GetNavigationSiteRoot());

            if (Request.IsSecureConnection)
            {
                if ((CurSettings != null) && (!CurSettings.UseSslOnAllPages))
                {
                    SearchUrl = SearchUrl.Replace("https", "http");
                }
            }
        }
        public void ShouldSetDefaultPageSize()
        {
            var searchProvider = new Mock <ISearchProvider>();

            searchProvider.Setup(sp => sp.Search(It.IsAny <ISearchUrl>())).Returns(new SearchResults()
            {
            });

            var searchController = new SearchController(Mock.Of <ILogger <SearchController> >(), searchProvider.Object);

            var searchUrl = new SearchUrl();

            searchController.Get(searchUrl);

            searchUrl.ps.ShouldBe(SearchController.DEFAULT_PAGE_SIZE);
        }
示例#7
0
        public override List <SearchResultItem> Search(string query, string category = null)
        {
            List <SearchResultItem> results = new List <SearchResultItem>();
            string  searchUrl = SearchUrl.Replace("{term}", HttpUtility.UrlEncode(query));
            JObject json      = GetWebData <JObject>(searchUrl);

            if (json["_embedded"] != null && json["_embedded"]["formats"] != null && json["_embedded"]["formats"].Count() > 0)
            {
                foreach (JToken format in json["_embedded"]["formats"])
                {
                    results.Add(new RssLink()
                    {
                        Name             = format["title"].Value <string>(),
                        Url              = format["_links"]["self"]["href"].Value <string>(),
                        Thumb            = format["_links"]["image"]["href"].Value <string>().Replace("{size}", "230x150"),
                        HasSubCategories = true,
                        Other            = "title"
                    });
                }
            }
            return(results);
        }
        public JsonResult Get([FromQuery] SearchUrl searchUrl)
        {
            searchUrl.ps = searchUrl.ps.HasValue ? Math.Max(searchUrl.ps.Value, MIN_PAGE_SIZE) : DEFAULT_PAGE_SIZE;

            var search     = _provider.Search(searchUrl);
            int statusCode = 200;

            if (search.Failed)
            {
                _logger.LogError("Search exception - {errorMessage}. Search url - {searchUrl}.",
                                 search.ErrorMessage,
                                 searchUrl
                                 );

                statusCode = 500;
            }

            return(new JsonResult(search)
            {
                StatusCode = statusCode
            });
        }
        public JsonResult GetOpenSearchSuggestions([FromQuery] SearchUrl searchUrl)
        {
            var search = _provider.TypeAhead(searchUrl);

            if (search.Failed)
            {
                _logger.LogError("Opensearch autocomplete exception - {errorMessage}. Search url - {searchUrl}.",
                                 search.ErrorMessage,
                                 searchUrl
                                 );

                return(new JsonResult(new object[] { searchUrl.q, Enumerable.Empty <string>(), Enumerable.Empty <string>(), Enumerable.Empty <string>() })
                {
                    StatusCode = 500
                });
            }

            // Open search suggestions have this weird nested list format
            // https://github.com/dewitt/opensearch/blob/master/mediawiki/Specifications/OpenSearch/Extensions/Suggestions/1.1/Draft%201.wiki
            var results = new object[] {
                // Query String
                searchUrl.q,
                // Completions
                search.Results.Select(r => r.Title),
                // Descriptions - we don't have any but the opensearch spec wants them so we just re-use the title
                search.Results.Select(r => r.Title),
                // Query URLs
                search.Results.Select(r => GetLink(r))
            };

            // Custom mime type for opensearch suggestions
            return(new JsonResult(results)
            {
                ContentType = "application/x-suggestions+json"
            });
        }
示例#10
0
 public SEOBLLUnitTests()
 {
     _mockSEORequestService = new Mock <ISEORequestService>();
     _searchUrl             = new SearchUrl(_mockSEORequestService.Object);
 }