public async Task <Suggestion[]> GetSuggestions(string dictionary, AudienceType audience, string language, string query,
                                                        [FromQuery] bool contains = false, [FromQuery] int size = 20, [FromQuery] int from = 0)
        {
            if (String.IsNullOrWhiteSpace(dictionary) || String.IsNullOrWhiteSpace(language) || !Enum.IsDefined(typeof(AudienceType), audience))
            {
                throw new APIErrorException(400, "You must supply a valid dictionary, audience and language.");
            }

            if (language.ToLower() != "en" && language.ToLower() != "es")
            {
                throw new APIErrorException(404, "Unsupported Language. Valid values are 'en' and 'es'.");
            }

            if (size <= 0)
            {
                size = 20;
            }

            if (from < 0)
            {
                from = 0;
            }


            return(await _autosuggestQueryService.GetSuggestions(dictionary, audience, language, query, contains, size, from));
        }
Exemplo n.º 2
0
        public async Task <Suggestion[]> GetSuggestions(string dictionary, AudienceType audience, string language, string searchText,
                                                        [FromQuery] MatchType matchType = MatchType.Begins, [FromQuery] int size = 20)
        {
            if (String.IsNullOrWhiteSpace(dictionary) || String.IsNullOrWhiteSpace(language) || !Enum.IsDefined(typeof(AudienceType), audience))
            {
                throw new APIErrorException(400, "You must supply a valid dictionary, audience and language.");
            }

            if (!Enum.IsDefined(typeof(MatchType), matchType))
            {
                throw new APIErrorException(400, "The 'matchType' parameter must be either 'Begins' or 'Contains'.");
            }

            if (language.ToLower() != "en" && language.ToLower() != "es")
            {
                throw new APIErrorException(400, "Unsupported Language. Valid values are 'en' and 'es'.");
            }

            if (size <= 0)
            {
                size = 20;
            }

            // searchText uses a catch-all route, make sure it's been decoded.
            searchText = WebUtility.UrlDecode(searchText);

            return(await _autosuggestQueryService.GetSuggestions(dictionary, audience, language, searchText, matchType, size));
        }