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());
        }
        public void BuildSuggestParametersTest(int count, bool fuzzy)
        {
            var props = new SuggestProperties
            {
                MaxResultCount   = count,
                UseFuzzyMatching = fuzzy
            };

            var queryConverter = new AzSearchQueryConverter();
            var result         = queryConverter.BuildSuggestParameters(props);

            result.Top.Should().Be(count);
            result.UseFuzzyMatching.Should().Be(fuzzy);
        }
        public void ConvertToSuggestionResultTest()
        {
            var suggestResult = new DocumentSuggestResult <JobProfileIndex>
            {
                Coverage = 1,
                Results  = new List <SuggestResult <JobProfileIndex> >
                {
                    new SuggestResult <JobProfileIndex>
                    {
                        Document = DummyJobProfileIndex.GenerateJobProfileIndexDummy("one"),
                        Text     = "one"
                    },
                    new SuggestResult <JobProfileIndex>
                    {
                        Document = DummyJobProfileIndex.GenerateJobProfileIndexDummy("two"),
                        Text     = "two"
                    }
                }
            };

            var properties = new SuggestProperties
            {
                MaxResultCount   = 5,
                UseFuzzyMatching = true
            };

            var queryConverter = new AzSearchQueryConverter();
            var result         = queryConverter.ConvertToSuggestionResult(suggestResult, properties);

            result.Coverage.Should().Be(1);
            result.Results.Count().Should().Be(suggestResult.Results.Count());
            result.Results.First().Index.Should().BeEquivalentTo(DummyJobProfileIndex.GenerateJobProfileIndexDummy("one"));
            result.Results.First().MatchedSuggestion.Should().Be("one");
            result.Results.Last().Index.Should().BeEquivalentTo(DummyJobProfileIndex.GenerateJobProfileIndexDummy("two"));
            result.Results.Last().MatchedSuggestion.Should().Be("two");
        }
        private async Task <SuggestionResult <T> > GetSuggestionAsyncWithIndexClient(ISearchIndexClient searchIndexClient, string partialTerm, SuggestProperties properties)
        {
            var suggestParameters = queryConverter.BuildSuggestParameters(properties);
            var result            = await searchIndexClient.Documents.SuggestAsync <T>(partialTerm, DefaultSuggesterName, suggestParameters).ConfigureAwait(false);

            return(queryConverter.ConvertToSuggestionResult(result, properties));
        }