Exemple #1
0
        public void When_getting_suggestions_with_nearestDocument_then_returns_suggestions_correctly(bool usePreprocessedQuerySearchRecommender)
        {
            var questions = GetQuestions();

            this._recommenderSettings.UseNearestDocumentsRecommender        = true;
            this._recommenderSettings.UsePreprocessedQuerySearchRecommender = usePreprocessedQuerySearchRecommender;

            this.NlpCallHttpMessageHandleMock(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(this.GetRelevantNlpAnalysis())));
            this.IndexSearchHttpMessageHandleMock(HttpStatusCode.OK, this.GetSearchResultStringContent());
            this.NearestDocumentsHttpMessageHandleMock(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(GetNearestDocumentResult())));
            this.DocumentFacetsHttpMessageHandleMock(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(questions)));
            var searchQuery = SearchQueryBuilder.Build.Instance;

            this._suggestionController.OnActionExecuting(this.GetActionExecutingContext(searchQuery));
            var result = this._suggestionController.GetSuggestions(searchQuery);

            var suggestion = result.As <OkObjectResult>().Value as Suggestion;

            var questionsToClient = questions.Select(q => QuestionToClient.FromQuestion(q.FacetQuestion)).ToList();

            suggestion.Documents.Select(d => d.Value).Count().Should().Be(4);
            suggestion.Documents.Select(d => d.Value.Uri).Contains(GetNearestDocumentResult()[0].Document.Uri).Should().BeTrue();
            suggestion.Documents.Select(d => d.Value.Uri).Contains(GetNearestDocumentResult()[1].Document.Uri).Should().BeTrue();
            suggestion.Questions.Select(q => q.Value).Should().BeEquivalentTo(questionsToClient);
        }
Exemple #2
0
        public void When_getting_suggestions_with_good_query_then_returns_suggestions_correctly()
        {
            var questions = GetQuestions();

            this.NlpCallHttpMessageHandleMock(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(this.GetRelevantNlpAnalysis())));
            this.IndexSearchHttpMessageHandleMock(HttpStatusCode.OK, this.GetSearchResultStringContent());
            this.DocumentFacetsHttpMessageHandleMock(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(questions)));
            var searchQuery = SearchQueryBuilder.Build.Instance;

            this._suggestionController.OnActionExecuting(this.GetActionExecutingContext(searchQuery));
            var result = this._suggestionController.GetSuggestions(searchQuery);

            var suggestion = result.As <OkObjectResult>().Value as Suggestion;

            var questionsToClient = questions.Select(q => QuestionToClient.FromQuestion(q.FacetQuestion)).ToList();

            suggestion.Documents.Select(d => d.Value).Should().BeEquivalentTo(GetSuggestedDocuments());
            suggestion.Questions.Select(q => q.Value).Should().BeEquivalentTo(questionsToClient);
        }
Exemple #3
0
        public void When_getting_suggestions_and_agent_click_on_question_and_agent_asks_question_to_customer_then_question_is_filter_out_then_facet_is_clear()
        {
            // Customer says: I need help with CoveoSearch API
            var searchQuery = SearchQueryBuilder.Build
                              .WithQuery("I need help with CoveoSearch API")
                              .Instance;

            var questions = GetQuestions();

            this.NlpCallHttpMessageHandleMock(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(this.GetRelevantNlpAnalysis())));
            this.IndexSearchHttpMessageHandleMock(HttpStatusCode.OK, this.GetSearchResultStringContent());
            this.DocumentFacetsHttpMessageHandleMock(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(questions)));

            this._suggestionController.OnActionExecuting(this.GetActionExecutingContext(searchQuery));
            var result = this._suggestionController.GetSuggestions(searchQuery);

            var suggestion = result.As <OkObjectResult>().Value as Suggestion;

            var questionsToClient = questions.Select(q => QuestionToClient.FromQuestion(q.FacetQuestion)).ToList();

            suggestion.Documents.Select(d => d.Value).Should().BeEquivalentTo(GetSuggestedDocuments());
            suggestion.Questions.Select(q => q.Value).Should().BeEquivalentTo(questionsToClient);

            // Agent click on a question in the UI
            var selectQuery = SelectQueryBuilder.Build.WithChatKey(searchQuery.ChatKey).WithId(questions[0].FacetQuestion.Id).Instance;

            this._suggestionController.SelectSuggestion(selectQuery);

            // Agent asks the question he clicked to the custommer
            searchQuery = SearchQueryBuilder.Build
                          .WithMessageType(SearchQuery.MessageType.Agent)
                          .WithQuery(questions[0].FacetQuestion.Text)
                          .Instance;
            result     = this._suggestionController.GetSuggestions(searchQuery);
            suggestion = result.As <OkObjectResult>().Value as Suggestion;

            suggestion.Documents.Select(d => d.Value).Should().BeEquivalentTo(GetSuggestedDocuments());

            var questionsReceived = suggestion.Questions.Select(q => q.Value);

            questionsReceived.Count().Should().Be(1);
            questionsReceived.Single().Should().BeEquivalentTo(questionsToClient[1]);

            // Client respond to the answer
            var answerFromClient = (questions[0].FacetQuestion as FacetQuestion)?.FacetValues.FirstOrDefault();

            searchQuery.Type  = SearchQuery.MessageType.Customer;
            searchQuery.Query = answerFromClient;
            result            = this._suggestionController.GetSuggestions(searchQuery);
            suggestion        = result.As <OkObjectResult>().Value as Suggestion;

            suggestion.ActiveFacets.Should().HaveCount(1);
            suggestion.ActiveFacets[0].Values.Contains(answerFromClient).Should().BeTrue();

            // Agent clear the facet
            result = this._suggestionController.RemoveFacet(suggestion.ActiveFacets[0].Id, searchQuery);
            result.Should().BeOfType <NoContentResult>();

            // Get the suggestion after clear
            var query = SuggestionQueryBuilder.Build.WithChatKey(searchQuery.ChatKey).Instance;

            result     = this._suggestionController.GetSuggestions(query);
            suggestion = result.As <OkObjectResult>().Value as Suggestion;
            suggestion.Should().NotBeNull();
            suggestion.ActiveFacets.Should().HaveCount(0);
            suggestion.Documents.Select(d => d.Value).Should().BeEquivalentTo(GetSuggestedDocuments());
        }
Exemple #4
0
        public void When_getting_suggestions_with_agent_sending_uri_then_suggestion_is_filter_then_returns_suggestions_correctly()
        {
            // Customer says: Hello
            var searchQuery = SearchQueryBuilder.Build
                              .WithQuery("Hello")
                              .Instance;

            this.NlpCallHttpMessageHandleMock(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(this.GetIrrelevantNlpAnalysis())));

            this._suggestionController.OnActionExecuting(this.GetActionExecutingContext(searchQuery));
            var result = this._suggestionController.GetSuggestions(searchQuery);

            var suggestion = result.As <OkObjectResult>().Value as Suggestion;

            suggestion.Documents.Should().BeEquivalentTo(new List <Recommendation <Document> >());
            suggestion.Questions.Should().BeEquivalentTo(new List <Recommendation <Question> >());

            // Customer says: I need help with CoveoSearch API
            searchQuery = SearchQueryBuilder.Build
                          .WithQuery("I need help with CoveoSearch API")
                          .WithChatKey(searchQuery.ChatKey)
                          .Instance;

            var questions = GetQuestions();

            this.NlpCallHttpMessageHandleMock(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(this.GetRelevantNlpAnalysis())));

            this.IndexSearchHttpMessageHandleMock(HttpStatusCode.OK, this.GetSearchResultStringContent());

            this.DocumentFacetsHttpMessageHandleMock(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(questions)));

            this._suggestionController.OnActionExecuting(this.GetActionExecutingContext(searchQuery));
            result = this._suggestionController.GetSuggestions(searchQuery);

            suggestion = result.As <OkObjectResult>().Value as Suggestion;

            var questionsToClient = questions.Select(q => QuestionToClient.FromQuestion(q.FacetQuestion)).ToList();

            suggestion.Documents.Select(d => d.Value).Should().BeEquivalentTo(GetSuggestedDocuments());
            suggestion.Questions.Select(q => q.Value).Should().BeEquivalentTo(questionsToClient);

            // Agent says: Maybe this could help: https://onlinehelp.coveo.com/en/cloud/Available_Coveo_Cloud_V2_Source_Types.htm
            searchQuery = SearchQueryBuilder.Build
                          .WithQuery("Maybe this can help: https://onlinehelp.coveo.com/en/cloud/Available_Coveo_Cloud_V2_Source_Types.htm")
                          .WithMessageType(SearchQuery.MessageType.Agent)
                          .WithChatKey(searchQuery.ChatKey)
                          .Instance;

            this.NlpCallHttpMessageHandleMock(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(this.GetRelevantNlpAnalysis())));

            this._suggestionController.OnActionExecuting(this.GetActionExecutingContext(searchQuery));
            result = this._suggestionController.GetSuggestions(searchQuery);

            result.Should().NotBeNull();

            suggestion = result.As <OkObjectResult>().Value as Suggestion;

            suggestion.Documents.Count.Should().NotBe(0);
            suggestion.Documents.Select(d => d.Value).Select(x => x.Uri)
            .Contains("https://onlinehelp.coveo.com/en/cloud/Available_Coveo_Cloud_V2_Source_Types.htm").Should().BeFalse();
        }