protected void TestCanSuggestWithSelectedFields()
        {
            SearchIndexClient client = GetClientForQuery();

            var suggestParameters =
                new SuggestParameters()
                {
                    Select = new[] { "hotelName", "baseRate" }
                };

            DocumentSuggestResponse<Hotel> response =
                client.Documents.Suggest<Hotel>("luxury", "sg", suggestParameters);

            var expectedDoc = new Hotel() { HotelName = "Fancy Stay", BaseRate = 199.0 };

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.NotNull(response.Results);
            Assert.Equal(1, response.Results.Count);
            Assert.Equal(expectedDoc, response.Results.First().Document);
        }
Ejemplo n.º 2
0
        public void GetStaticallyTypedDocumentSetsUnselectedFieldsToNull()
        {
            Run(() =>
            {
                SearchIndexClient client = Data.GetSearchIndexClient();

                var indexedDoc =
                    new Hotel()
                {
                    HotelId            = "2",
                    HotelName          = "Countryside Hotel",
                    Description        = "Save up to 50% off traditional hotels.  Free WiFi, great location near downtown, full kitchen, washer & dryer, 24/7 support, bowling alley, fitness center and more.",
                    DescriptionFr      = "Économisez jusqu'à 50% sur les hôtels traditionnels.  WiFi gratuit, très bien situé près du centre-ville, cuisine complète, laveuse & sécheuse, support 24/7, bowling, centre de fitness et plus encore.",
                    Category           = "Budget",
                    Tags               = new[] { "24-hour front desk service", "coffee in lobby", "restaurant" },
                    ParkingIncluded    = false,
                    SmokingAllowed     = true,
                    LastRenovationDate = new DateTimeOffset(1999, 9, 6, 0, 0, 0, TimeSpan.Zero),       //aka.ms/sre-codescan/disable
                    Rating             = 3,
                    Location           = GeographyPoint.Create(35.904160, -78.940483),
                    Address            = new HotelAddress()
                    {
                        StreetAddress = "6910 Fayetteville Rd",
                        City          = "Durham",
                        StateProvince = "NC",
                        Country       = "USA",
                        PostalCode    = "27713"
                    },
                    Rooms = new[]
                    {
                        new HotelRoom()
                        {
                            Description    = "Suite, 1 King Bed (Amenities)",
                            DescriptionFr  = "Suite, 1 très grand lit (Services)",
                            Type           = "Suite",
                            BaseRate       = 2.44,
                            BedOptions     = "1 King Bed",
                            SleepsCount    = 2,
                            SmokingAllowed = true,
                            Tags           = new[] { "coffee maker" }
                        },
                        new HotelRoom()
                        {
                            Description    = "Budget Room, 1 Queen Bed (Amenities)",
                            DescriptionFr  = "Chambre Économique, 1 grand lit (Services)",
                            Type           = "Budget Room",
                            BaseRate       = 7.69,
                            BedOptions     = "1 Queen Bed",
                            SleepsCount    = 2,
                            SmokingAllowed = false,
                            Tags           = new [] { "coffee maker" }
                        }
                    }
                };

                var expectedDoc =
                    new Hotel()
                {
                    HotelName   = "Countryside Hotel",
                    Description = "Save up to 50% off traditional hotels.  Free WiFi, great location near downtown, full kitchen, washer & dryer, 24/7 support, bowling alley, fitness center and more.",
                    Address     = new HotelAddress()
                    {
                        City = "Durham"
                    },
                    Rooms = new[]
                    {
                        new HotelRoom()
                        {
                            BaseRate = 2.44
                        },
                        new HotelRoom()
                        {
                            BaseRate = 7.69
                        }
                    }
                };

                var batch = IndexBatch.Upload(new[] { indexedDoc });
                client.Documents.Index(batch);

                var selectedFields = new[] { "description", "hotelName", "address/city", "rooms/baseRate" };
                Hotel actualDoc    = client.Documents.Get <Hotel>("2", selectedFields);
                Assert.Equal(expectedDoc, actualDoc);
            });
        }
Ejemplo n.º 3
0
        public void CanMergeStaticallyTypedDocuments()
        {
            Run(() =>
            {
                SearchIndexClient client = Data.GetSearchIndexClient();

                var originalDoc =
                    new Hotel()
                {
                    HotelId            = "1",
                    BaseRate           = 199.0,
                    Description        = "Best hotel in town",
                    DescriptionFr      = "Meilleur hôtel en ville",
                    HotelName          = "Fancy Stay",
                    Category           = "Luxury",
                    Tags               = new[] { "pool", "view", "wifi", "concierge" },
                    ParkingIncluded    = false,
                    SmokingAllowed     = false,
                    LastRenovationDate = new DateTimeOffset(2010, 6, 27, 0, 0, 0, TimeSpan.FromHours(-8)),
                    Rating             = 5,
                    Location           = GeographyPoint.Create(47.678581, -122.131577)
                };

                var updatedDoc =
                    new Hotel()
                {
                    HotelId            = "1",
                    BaseRate           = 99.0,
                    Description        = null,
                    Category           = "Business",
                    Tags               = new[] { "pool", "view", "wifi" },
                    ParkingIncluded    = true,
                    LastRenovationDate = null,
                    Rating             = 4,
                    Location           = null
                };

                var expectedDoc =
                    new Hotel()
                {
                    HotelId            = "1",
                    BaseRate           = 99.0,
                    Description        = "Best hotel in town",
                    DescriptionFr      = "Meilleur hôtel en ville",
                    HotelName          = "Fancy Stay",
                    Category           = "Business",
                    Tags               = new[] { "pool", "view", "wifi" },
                    ParkingIncluded    = true,
                    SmokingAllowed     = false,
                    LastRenovationDate = new DateTimeOffset(2010, 6, 27, 0, 0, 0, TimeSpan.FromHours(-8)),
                    Rating             = 4,
                    Location           = GeographyPoint.Create(47.678581, -122.131577)
                };

                client.Documents.Index(IndexBatch.MergeOrUpload(new[] { originalDoc }));
                SearchTestUtilities.WaitForIndexing();

                client.Documents.Index(IndexBatch.Merge(new[] { updatedDoc }));
                SearchTestUtilities.WaitForIndexing();

                Hotel actualDoc = client.Documents.Get <Hotel>("1");

                Assert.Equal(expectedDoc, actualDoc);

                client.Documents.Index(IndexBatch.MergeOrUpload(new[] { originalDoc }));
                SearchTestUtilities.WaitForIndexing();

                actualDoc = client.Documents.Get <Hotel>("1");

                Assert.Equal(originalDoc, actualDoc);
            });
        }
Ejemplo n.º 4
0
        public void CanGetStaticallyTypedDocument()
        {
            Run(() =>
            {
                SearchIndexClient client = Data.GetSearchIndexClient();

                var expectedDoc =
                    new Hotel()
                {
                    HotelId            = "1",
                    HotelName          = "Secret Point Motel",
                    Description        = "The hotel is ideally located on the main commercial artery of the city in the heart of New York. A few minutes away is Time's Square and the historic centre of the city, as well as other places of interest that make New York one of America's most attractive and cosmopolitan cities.",
                    DescriptionFr      = "L'hôtel est idéalement situé sur la principale artère commerciale de la ville en plein cœur de New York. A quelques minutes se trouve la place du temps et le centre historique de la ville, ainsi que d'autres lieux d'intérêt qui font de New York l'une des villes les plus attractives et cosmopolites de l'Amérique.",
                    Category           = "Boutique",
                    Tags               = new[] { "pool", "air conditioning", "concierge" },
                    ParkingIncluded    = false,
                    SmokingAllowed     = true,
                    LastRenovationDate = new DateTimeOffset(1970, 1, 18, 0, 0, 0, TimeSpan.FromHours(-5)),
                    Rating             = 4,
                    Location           = GeographyPoint.Create(40.760586, -73.975403),
                    Address            = new HotelAddress()
                    {
                        StreetAddress = "677 5th Ave",
                        City          = "New York",
                        StateProvince = "NY",
                        Country       = "USA",
                        PostalCode    = "10022"
                    },
                    Rooms = new[]
                    {
                        new HotelRoom()
                        {
                            Description    = "Budget Room, 1 Queen Bed (Cityside)",
                            DescriptionFr  = "Chambre Économique, 1 grand lit (côté ville)",
                            Type           = "Budget Room",
                            BaseRate       = 9.69,
                            BedOptions     = "1 Queen Bed",
                            SleepsCount    = 2,
                            SmokingAllowed = true,
                            Tags           = new[] { "vcr/dvd" }
                        },
                        new HotelRoom()
                        {
                            Description    = "Budget Room, 1 King Bed (Mountain View)",
                            DescriptionFr  = "Chambre Économique, 1 très grand lit (Mountain View)",
                            Type           = "Budget Room",
                            BaseRate       = 8.09,
                            BedOptions     = "1 King Bed",
                            SleepsCount    = 2,
                            SmokingAllowed = true,
                            Tags           = new[] { "vcr/dvd", "jacuzzi tub" }
                        }
                    }
                };

                var batch = IndexBatch.Upload(new[] { expectedDoc });
                client.Documents.Index(batch);

                Hotel actualDoc = client.Documents.Get <Hotel>("1");
                Assert.Equal(expectedDoc, actualDoc);
            });
        }