Esempio n. 1
0
        protected void TestCanSearchWithSynonyms()
        {
            SearchServiceClient searchClient = Data.GetSearchServiceClient();

            const string SynonymMapName = "names";
            var          synonymMap     = new SynonymMap(name: SynonymMapName, synonyms: "luxury,fancy");

            searchClient.SynonymMaps.Create(synonymMap);

            SearchIndexClient client = GetClientForQuery();
            Index             index  = searchClient.Indexes.Get(client.IndexName);

            index.Fields.First(f => f.Name == "hotelName").SynonymMaps = new[] { SynonymMapName };

            searchClient.Indexes.CreateOrUpdate(index);

            // When this test runs live, it runs against a free service that has 3 replicas.
            // Sometimes the synonym map update doesn't make it to the replica that handles
            // the query below, causing a test failure. We wait here to increase the odds of
            // consistency and decrease the likelihood of spurious test failures.
            SearchTestUtilities.WaitForSynonymMapUpdate();

            var searchParameters =
                new SearchParameters()
            {
                QueryType    = QueryType.Full,
                SearchFields = new[] { "hotelName" },
                Select       = new[] { "hotelName", "rating" }
            };

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

            var expectedDoc = new Hotel()
            {
                HotelName = "Fancy Stay", Rating = 5
            };

            Assert.NotNull(response.Results);
            Assert.Equal(1, response.Results.Count);
            Assert.Equal(expectedDoc, response.Results.First().Document);
        }