Beispiel #1
0
        public async Task SendResultsAsync(ITurnContext context, DocumentSearchResult results)
        {
            IMessageActivity activity = context.Activity.CreateReply();

            if (results.Results.Count == 0)
            {
                await SearchResponses.ReplyWithNoResults(context, facet);
            }
            else
            {
                SearchHitStyler searchHitStyler = new SearchHitStyler();
                searchHitStyler.Apply(
                    ref activity,
                    "Here are the results that I found:",
                    results.Results.Select(r => ImageMapper.ToSearchHit(r)).ToList().AsReadOnly());
                await context.SendActivity(activity);
            }
        }
Beispiel #2
0
        private async Task SendResultsAsync(ITurnContext context, string searchText, DocumentSearchResult results)
        {
            IMessageActivity activity =
                context.Activity.CreateReply();

            if (!results.Results.Any())
            {
                await SearchResponses.ReplyWithNoResults(context, searchText);
            }
            else
            {
                SearchHitStyler searchHitStyler = new SearchHitStyler();
                searchHitStyler.Apply(ref activity,
                                      "Here are the results that i found",
                                      results.Results.Select(r =>
                                                             ImageMapper.ToSearchHit(r)).ToList().AsReadOnly());
                await context.SendActivityAsync(activity);
            }
        }
        public async Task SendResultsAsync(ITurnContext context, string searchText, DocumentSearchResult results)
        {
            IMessageActivity activity = context.Activity.CreateReply();

            // if the search returns no results
            if (results.Results.Count == 0)
            {
                await SearchResponses.ReplyWithNoResults(context, searchText);
            }
            else // this means there was at least one hit for the search
            {
                // create the response with the result(s) and send to the user
                SearchHitStyler searchHitStyler = new SearchHitStyler();
                searchHitStyler.Apply(
                    ref activity,
                    "Here are the results that I found:",
                    results.Results.Select(r => ImageMapper.ToSearchHit(r)).ToList().AsReadOnly());

                await context.SendActivityAsync(activity);
            }
        }
        private async Task SendResults(IDialogContext context, DocumentSearchResult results)
        {
            var message = context.MakeMessage();

            if (results.Results.Count == 0)
            {
                await context.PostAsync("There were no results found for \"" + searchText + "\".");

                context.Done <object>(null);
            }
            else
            {
                SearchHitStyler searchHitStyler = new SearchHitStyler();
                searchHitStyler.Apply(
                    ref message,
                    "Here are the results that I found:",
                    results.Results.Select(r => ImageMapper.ToSearchHit(r)).ToList().AsReadOnly());

                await context.PostAsync(message);

                context.Done <object>(null);
            }
        }
Beispiel #5
0
        private async Task <DialogTurnResult> SearchAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            //Here is the main event! This method will utilize Azure Search
            //to find results that the user asked for.
            var state = await _accessors.PictureState.GetAsync(stepContext.Context, () => new PictureState());

            //We can find the user's search two ways:
            // - As part of the state
            // - As the result coming to this step from a previous (Prompt) dialog

            //First, see if the query can be found on the "Search" property
            //of the state. If not, apply this stepcontext's result (as a string)
            //and update the conversation state
            var q = state.Search;

            if (string.IsNullOrWhiteSpace(q))
            {
                q            = stepContext.Result as string;
                state.Search = q;
                await _accessors.ConversationState.SaveChangesAsync(stepContext.Context);
            }

            //Next, establish a client using the helper method.
            //CTRL and click on this helper method to adjust for your service.
            var client = CreateSearchIndexClient();

            //Call SearchAsync on this client's Documents property
            //to retrieve the search results
            var searchResponse = await client.Documents.SearchAsync(q);

            //If the response's results have a count of 0...
            // - Either give a failure message
            // - Or keep going and search on Bing

            if (searchResponse.Results.Count == 0)
            {
                await SearchResponses.ReplyWithNoResults(stepContext.Context, q);

                return(await stepContext.PromptAsync("bingPrompt", new PromptOptions
                {
                    Prompt = MessageFactory.Text("Would you like to search on bing?")
                }, cancellationToken));
            }
            else
            {
                //Otherwise, create a new activity to reply with
                IMessageActivity activity = stepContext.Context.Activity.CreateReply();

                //Use the provided SearchHitStyler() class to apply
                //formatted results to the activity.
                //You will want to map the search response Results to a
                //list of SearchHit objects using the ImageMapper.ToSearchHit method
                var styler  = new SearchHitStyler();
                var options = searchResponse.Results.Select(r => ImageMapper.ToSearchHit(r)).ToList().AsReadOnly();

                styler.Apply(ref activity, "Here are the results:", options);

                //Send the activity to the user
                await stepContext.Context.SendActivityAsync(activity, cancellationToken);
            }

            //In any case, reset the search flags
            //(be sure to save the conversation state!)
            //and end the dialog. We are done! This dialog pops
            //off of the stack and we are left with the main dialog.
            state.IsSearching = false;
            state.Search      = string.Empty;

            await _accessors.ConversationState.SaveChangesAsync(stepContext.Context);

            return(await stepContext.EndDialogAsync());
        }