public ActionResult Suggestions(string term, int maxNumberDisplayed, bool fuzzySearch)
        {
            if (!string.IsNullOrEmpty(term))
            {
                if (term.Length > AutoCompleteMaximumCharacters)
                {
                    term = term.Substring(0, AutoCompleteMaximumCharacters);
                }

                var props = new SuggestProperties
                {
                    UseFuzzyMatching = fuzzySearch,
                    MaxResultCount   = maxNumberDisplayed
                };
                var results     = searchQueryService.GetSuggestion(term, props);
                var suggestions = results.Results.Select(s => new Suggestion
                {
                    label = s.MatchedSuggestion.First().ToString().ToUpper() + s.MatchedSuggestion.Substring(1)
                });
                var distinctSuggestions = suggestions.GroupBy(x => x.label).Select(x => x.First());
                return(Json(distinctSuggestions, JsonRequestBehavior.AllowGet));
            }

            return(new EmptyResult());
        }
Exemple #2
0
        public void WhenITypeTheTerm(string suggestionTerm)
        {
            OutputHelper.WriteLine($"The suggestion term is '{suggestionTerm}'");
            try
            {
                results = searchQueryService.GetSuggestion(
                    suggestionTerm,
                    new SuggestProperties {
                    UseFuzzyMatching = true, MaxResultCount = 5
                });
            }
            catch (Exception ex)
            {
                OutputHelper.WriteLine($"Exception in When:- {ex}");
            }

            //Log results
            var actual = results?.Results.Select(r => r.Index);

            OutputHelper.WriteLine($"Actual order {actual?.ToJson()}");
        }