Exemple #1
0
        private void AssertKeySequenceEqual(DocumentSearchResponse response, params string[] expectedKeys)
        {
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.NotNull(response.Results);

            IEnumerable <string> actualKeys = response.Results.Select(r => (string)r.Document["hotelId"]);

            SearchAssert.SequenceEqual(expectedKeys, actualKeys);
        }
Exemple #2
0
        private static void AssertIsPartialFailure(
            IndexBatchException e,
            IndexBatch <Hotel> batch,
            params string[] failedKeys)
        {
            Assert.Equal((HttpStatusCode)207, e.Response.StatusCode);
            Assert.Equal((HttpStatusCode)207, e.IndexResponse.StatusCode);

            IndexBatch <Hotel> retryBatch = e.FindFailedActionsToRetry(batch, a => a.HotelId);

            Assert.Equal(failedKeys.Length, retryBatch.Actions.Count());
            SearchAssert.SequenceEqual(failedKeys, retryBatch.Actions.Select(a => a.Document.HotelId));
        }
Exemple #3
0
        private static void AssertIsPartialFailure(
            IndexBatchException e,
            IndexBatch batch,
            params string[] failedKeys)
        {
            Assert.Equal((HttpStatusCode)207, e.Response.StatusCode);
            Assert.Equal((HttpStatusCode)207, e.IndexResponse.StatusCode);

            const string KeyFieldName = "hotelId";
            IndexBatch   retryBatch   = e.FindFailedActionsToRetry(batch, KeyFieldName);

            Assert.Equal(failedKeys.Length, retryBatch.Actions.Count());
            SearchAssert.SequenceEqual(failedKeys, retryBatch.Actions.Select(a => a.Document[KeyFieldName].ToString()));
        }
Exemple #4
0
        public void CanUseHitHighlighting()
        {
            const string Description = "description";
            const string Category    = "category";

            Run(() =>
            {
                SearchIndexClient client = Data.GetSearchIndexClientForQuery();

                var searchParameters =
                    new SearchParameters()
                {
                    Filter           = "rating eq 5",
                    HighlightPreTag  = "<b>",
                    HighlightPostTag = "</b>"
                };

                // Try using the collection without initializing it to make sure it is lazily initialized.
                searchParameters.HighlightFields.Add(Description);
                searchParameters.HighlightFields.Add(Category);

                DocumentSearchResponse <Hotel> response =
                    client.Documents.Search <Hotel>("luxury hotel", searchParameters);

                AssertKeySequenceEqual(response, "1");

                HitHighlights highlights = response.Results[0].Highlights;
                Assert.NotNull(highlights);
                SearchAssert.SequenceEqual(new[] { Description, Category }, highlights.Keys);

                string categoryHighlight = highlights[Category].Single();
                Assert.Equal("<b>Luxury</b>", categoryHighlight);

                string[] expectedDescriptionHighlights =
                    new[]
                {
                    "Best <b>hotel</b> in town if you like <b>luxury</b> hotels.",
                    "We highly recommend this <b>hotel</b>."
                };

                SearchAssert.SequenceEqual(expectedDescriptionHighlights, highlights[Description]);
            });
        }
Exemple #5
0
        protected void TestCanSearchStaticallyTypedDocuments()
        {
            SearchIndexClient client = GetClientForQuery();
            DocumentSearchResponse <Hotel> response = client.Documents.Search <Hotel>("*");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Null(response.ContinuationToken);
            Assert.Null(response.Count);
            Assert.Null(response.Coverage);
            Assert.Null(response.Facets);
            Assert.NotNull(response.Results);

            Assert.Equal(Data.TestDocuments.Length, response.Results.Count);

            for (int i = 0; i < response.Results.Count; i++)
            {
                Assert.Equal(1, response.Results[i].Score);
                Assert.Null(response.Results[i].Highlights);
            }

            SearchAssert.SequenceEqual(response.Results.Select(r => r.Document), Data.TestDocuments);
        }