Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Uri searchEndpointUri = new Uri(SEARCH_ENDPOINT);

            SearchClient client = new SearchClient(
                searchEndpointUri,
                SEARCH_INDEX_NAME,
                new AzureKeyCredential(SEARCH_KEY));

            SearchIndexClient clientIndex = new SearchIndexClient(
                searchEndpointUri,
                new AzureKeyCredential(SEARCH_KEY));

            CreateIndexAsync(clientIndex).Wait();
            BulkInsertAsync(client).Wait();
        }
        public DocumentSearchResult <JObject> GetBlobByHash(SearchIndexClient indexClient, string md5Hash, ILogger log)
        {
            SearchParameters parameters;

            parameters =
                new SearchParameters()
            {
                //SearchFields = new[] { "hash" },
                Select = new[] { "id", "blobInfo/name", "blobInfo/url", "blobInfo/hash", "blobInfo/modified" }
            };

            //return indexClient.Documents.Search<BlobInfo>(hash, parameters);
            DocumentSearchResult <JObject> result = indexClient.Documents.Search <JObject>(md5Hash);

            return(result);
        }
Exemplo n.º 3
0
        public async Task ThrowsWhenMalformed()
        {
            await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this);

            SearchIndexClient      client = resources.GetQueryClient();
            RequestFailedException ex     = await CatchAsync <RequestFailedException>(
                async() => await client.GetDocumentAsync(
                    "3",
                    new GetDocumentOptions()
            {
                SelectedFields = new[] { "ThisFieldDoesNotExist" }
            }));

            Assert.AreEqual(400, ex.Status);
            StringAssert.StartsWith("Invalid expression: Could not find a property named 'ThisFieldDoesNotExist' on type 'search.document'.", ex.Message);
        }
Exemplo n.º 4
0
        public void SuggestThrowsWhenGivenBadSuggesterName()
        {
            Run(() =>
            {
                SearchIndexClient client = Data.GetSearchIndexClient();

                CloudException e =
                    Assert.Throws <CloudException>(
                        () => client.Documents.Suggest("hotel", "Suggester does not exist", new SuggestParameters()));

                Assert.Equal(HttpStatusCode.BadRequest, e.Response.StatusCode);
                Assert.Contains(
                    "The specified suggester name 'Suggester does not exist' does not exist in this index definition.",
                    e.Message);
            });
        }
Exemplo n.º 5
0
        public void CanSuggestWithMinimumCoverage()
        {
            Run(() =>
            {
                SearchIndexClient client = Data.GetSearchIndexClientForQuery();

                var parameters = new SuggestParameters()
                {
                    MinimumCoverage = 50
                };
                DocumentSuggestResponse <Hotel> response = client.Documents.Suggest <Hotel>("luxury", "sg", parameters);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.Equal(100, response.Coverage);
            });
        }
Exemplo n.º 6
0
        protected void TestSearchFieldsExcludesFieldsFromSuggest()
        {
            SearchIndexClient client = GetClientForQuery();

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

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

            Assert.NotNull(response.Results);
            Assert.Equal(0, response.Results.Count);
        }
 public AiSearchIndexService(SearchIndexClient indexClient,
                             SearchIndexerClient searchIndexerClient,
                             string storageConnectionString,
                             string containerName,
                             string indexName,
                             string indexerName,
                             string cognitiveServicesKey)
 {
     _indexClient             = indexClient;
     _indexerClient           = searchIndexerClient;
     _storageConnectionString = storageConnectionString;
     _containerName           = containerName;
     _indexName            = indexName;
     _indexerName          = indexerName;
     _cognitiveServicesKey = cognitiveServicesKey;
 }
Exemplo n.º 8
0
        protected void TestCanFilter()
        {
            SearchIndexClient client = GetClientForQuery();

            var suggestParameters =
                new SuggestParameters()
            {
                Filter  = "rating gt 3 and lastRenovationDate gt 2000-01-01T00:00:00Z",
                OrderBy = new[] { "hotelId" }       // Use OrderBy so changes in ranking don't break the test.
            };

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

            AssertKeySequenceEqual(response, "1", "5");
        }
Exemplo n.º 9
0
        public void CanSearchWithSearchModeAll()
        {
            Run(() =>
            {
                SearchIndexClient client = Data.GetSearchIndexClientForQuery();

                var searchParameters = new SearchParameters()
                {
                    SearchMode = SearchMode.All
                };
                DocumentSearchResponse <Hotel> response =
                    client.Documents.Search <Hotel>("Cheapest hotel", searchParameters);

                AssertKeySequenceEqual(response, "2");
            });
        }
Exemplo n.º 10
0
        public async Task <Uri> GetDataBlobUriFromJson(string md5Hash)
        {
            SearchIndexClient indexClient = await GetJsonBindingSearchIndex();

            JObject searchResult = JsonBindingSearchResult(indexClient, md5Hash);
            JToken  urlToken     = searchResult.SelectToken("url");

            if (urlToken != null)
            {
                return(new Uri(urlToken.ToString()));
            }
            else
            {
                throw (new MissingRequiredObject($"\nBound JSON for {md5Hash} does not contain a url value."));
            }
        }
Exemplo n.º 11
0
        public void RequestIdIsReturnedInResponse()
        {
            Run(() =>
            {
                SearchIndexClient client = Data.GetSearchIndexClient();

                // We need to use a constant GUID so that this test will still work in playback mode.
                Guid myRequestId = new Guid("c4cfce79-eb42-4e61-9909-84510c04706f");
                client.SetClientRequestId(myRequestId);

                DocumentCountResponse countResponse = client.Documents.Count();
                Assert.Equal(HttpStatusCode.OK, countResponse.StatusCode);

                Assert.Equal(myRequestId.ToString(), countResponse.RequestId);
            });
        }
Exemplo n.º 12
0
        protected void TestSuggestThrowsWhenRequestIsMalformed()
        {
            SearchIndexClient client = GetClient();

            var invalidParameters = new SuggestParameters()
            {
                OrderBy = new[] { "This is not a valid orderby." }
            };
            CloudException e =
                Assert.Throws <CloudException>(() => client.Documents.Suggest("hotel", "sg", invalidParameters));

            Assert.Equal(HttpStatusCode.BadRequest, e.Response.StatusCode);
            Assert.Contains(
                "Invalid expression: Syntax error at position 7 in 'This is not a valid orderby.'",
                e.Message);
        }
Exemplo n.º 13
0
        static BabyNameSearch()
        {
            try
            {
                string searchServiceName = ConfigurationManager.AppSettings["SearchServiceName"];
                string apiKey            = ConfigurationManager.AppSettings["SearchServiceApiKey"];

                // Create an HTTP reference to the catalog index
                var searchClient = new SearchServiceClient(searchServiceName, new SearchCredentials(apiKey));
                IndexClient = searchClient.Indexes.GetClient("babynames");
            }
            catch (Exception e)
            {
                ErrorMessage = e.Message;
            }
        }
Exemplo n.º 14
0
        static FeaturesSearch()
        {
            try
            {
                string searchServiceName = ConfigurationManager.AppSettings["SearchServiceName"];
                string apiKey            = ConfigurationManager.AppSettings["SearchServiceApiKey"];

                // Create an HTTP reference to the catalog index
                _searchClient = new SearchServiceClient(searchServiceName, new SearchCredentials(apiKey));
                _indexClient  = _searchClient.Indexes.GetClient("geonames");
            }
            catch (Exception e)
            {
                errorMessage = e.Message.ToString();
            }
        }
Exemplo n.º 15
0
        protected void TestTopTrimsResults()
        {
            SearchIndexClient client = GetClientForQuery();

            var suggestParameters =
                new SuggestParameters()
            {
                OrderBy = new string[] { "hotelId" },
                Top     = 3
            };

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

            AssertKeySequenceEqual(response, "1", "2", "3");
        }
Exemplo n.º 16
0
        protected void TestCanFilter()
        {
            SearchIndexClient client = GetClientForQuery();

            var searchParameters =
                new SearchParameters()
            {
                Filter = "rating gt 3 and lastRenovationDate gt 2000-01-01T00:00:00Z"
            };

            // Also test that searchText can be null.
            DocumentSearchResult <Hotel> response =
                client.Documents.Search <Hotel>(null, searchParameters);

            AssertKeySequenceEqual(response, "1", "5");
        }
Exemplo n.º 17
0
        protected void TestCanSearchWithSearchModeAll()
        {
            SearchIndexClient client = GetClientForQuery();

            var searchParameters =
                new SearchParameters()
            {
                QueryType  = QueryType.Simple,      // Set explicitly at least once for test coverage.
                SearchMode = SearchMode.All
            };

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

            AssertKeySequenceEqual(response, "2");
        }
Exemplo n.º 18
0
 private async Task LoadDataFileAsync(string file, SearchIndexClient indexClient)
 {
     using (var sr = System.IO.File.OpenText(file))
     {
         var json      = sr.ReadToEnd();
         var documents = JsonConvert.DeserializeObject <List <dynamic> >(json);
         var actions   = new List <IndexAction <dynamic> >();
         foreach (var doc in documents)
         {
             var x = IndexAction.MergeOrUpload <dynamic>(doc);
             actions.Add(x);
         }
         var batch = new IndexBatch <dynamic>(actions);
         await indexClient.Documents.IndexAsync(batch);
     }
 }
Exemplo n.º 19
0
        protected void TestSearchThrowsWhenRequestIsMalformed()
        {
            SearchIndexClient client = GetClient();

            var invalidParameters = new SearchParameters()
            {
                Filter = "This is not a valid filter."
            };
            CloudException e =
                Assert.Throws <CloudException>(() => client.Documents.Search("*", invalidParameters));

            Assert.Equal(HttpStatusCode.BadRequest, e.Response.StatusCode);
            Assert.Contains(
                "Invalid expression: Syntax error at position 7 in 'This is not a valid filter.'",
                e.Message);
        }
Exemplo n.º 20
0
        public DocumentSearchResult <JObject> GetBlobByHash(SearchIndexClient indexClient, string md5Hash)
        {
            SearchParameters parameters;

            parameters =
                new SearchParameters()
            {
                //SearchFields = new[] { "Hash" },
                Select = new[] { "Id", "Name", "Hash", "metadata_storage_path" }
            };

            //return indexClient.Documents.Search<BlobInfo>(Hash, parameters);
            DocumentSearchResult <JObject> result = indexClient.Documents.Search <JObject>(md5Hash);

            return(result);
        }
Exemplo n.º 21
0
        public void RequestIdIsReturnedInResponse()
        {
            Run(() =>
            {
                SearchIndexClient client = Data.GetSearchIndexClient();

                // We need to use a constant GUID so that this test will still work in playback mode.
                var options = new SearchRequestOptions(new Guid("c4cfce79-eb42-4e61-9909-84510c04706f"));

                AzureOperationResponse<long> countResponse = 
                    client.Documents.CountWithHttpMessagesAsync(options).Result;
                Assert.Equal(HttpStatusCode.OK, countResponse.Response.StatusCode);

                Assert.Equal(options.ClientRequestId.Value.ToString("D"), countResponse.RequestId);
            });
        }
        // This sample shows how to use Azure Active Directory (AAD) together with Azure Search to restrict document access based on user group membership through Azure Search filters.
        public static void Main(string[] args)
        {
            // Application Id as obtained by creating an application from https://apps.dev.microsoft.com
            // See also the guided setup:https://docs.microsoft.com/en-us/azure/active-directory/develop/guidedsetups/active-directory-windesktop
            ClientId = ConfigurationManager.AppSettings["ClientId"];
            _microsoftGraphHelper = new MicrosoftGraphHelper(ClientId);
            _microsoftGraphHelper.CreateGraphServiceClient();
            string tenant = ConfigurationManager.AppSettings["Tenant"];

            // Azure Search Initialization
            string searchServicEndpoint = ConfigurationManager.AppSettings["SearchServicEndpoint"];
            string apiKey    = ConfigurationManager.AppSettings["SearchServiceApiKey"];
            string indexName = "securedfiles";

            Dictionary <Group, List <User> > groups = CreateGroupsWithUsers(tenant);

            // Create a group, a user and associate both
            _microsoftGraphHelper.CreateUsersAndGroups(groups).Wait();

            // Create a cache that contains the users and the list of groups they are part of
            Console.WriteLine("Refresh cache...\n");
            var users = groups.SelectMany(u => u.Value);

            RefreshCache(users);

            // Create an HTTP reference to the catalog index
            indexClient  = new SearchIndexClient(new Uri(searchServicEndpoint), new AzureKeyCredential(apiKey));
            searchClient = indexClient.GetSearchClient(indexName);

            if (DeleteIndex(indexName))
            {
                Console.WriteLine("Creating index...\n");
                CreateIndex(indexName);
            }

            Console.WriteLine("Indexing documents...\n");
            // Index documents with relevant group ids
            IndexDocuments(indexName, groups.Keys.Select(g => g.Id).ToList());

            foreach (var user in users)
            {
                // Retrieve user's groups so that a search filter could be built using the groups list
                Console.WriteLine("Get groups for user {0}...\n", user.UserPrincipalName);
                RefreshCacheIfRequired(user.UserPrincipalName);
                SearchQueryWithFilter(user.UserPrincipalName);
            }
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            bool clear = false;

            SearchServiceClient client = new SearchServiceClient(ConfigurationManager.AppSettings["AzureSearchName"],
                                                                 new SearchCredentials(ConfigurationManager.AppSettings["AzureSearchKey"]));
            SearchIndexClient indexClient = client.Indexes.GetClient("restaurant");

            AzureMLRecommendations recos = new AzureMLRecommendations();

            recos.Init(ConfigurationManager.AppSettings["RecoUser"], ConfigurationManager.AppSettings["RecoKey"]);
            string modelId = ConfigurationManager.AppSettings["RecoModelId"];

            List <IndexAction> actions = new List <IndexAction>();

            foreach (int id in GetCurrentRestaurantIds())
            {
                List <string> recommendedIds = new List <string>();
                if (!clear)
                {
                    var r = recos.GetRecommendation(modelId, new List <string> {
                        id.ToString()
                    }, 3);
                    recommendedIds.AddRange(r.Select(i => i.Id));
                }
                actions.Add(IndexAction.Merge(new Document {
                    { "RestaurantId", id.ToString() }, { "RecommendedIds", recommendedIds }
                }));
            }

            // Assume < 1000 actions, otherwise we'd need to split it in 1000-actions batches
            try
            {
                DocumentIndexResult indexResult = indexClient.Documents.Index(new IndexBatch(actions));
                int succeeded = indexResult.Results.Where(r => r.Succeeded).Count();
                Console.WriteLine($"Indexed completed. Items: {indexResult.Results.Count}, Succeeded: {succeeded}");
            }
            catch (IndexBatchException ex)
            {
                // Sometimes when your Search service is under load, indexing will fail for some of the documents in
                // the batch. Depending on your application, you can take compensating actions like delaying and
                // retrying. For this simple demo, we just log the failed document keys and continue.
                Console.WriteLine(
                    "Failed to index some of the documents: {0}",
                    string.Join(", ", ex.IndexingResults.Where(r => !r.Succeeded).Select(r => r.Key)));
            }
        }
Exemplo n.º 24
0
        private async Task IndexPriceListPageAsync(
            SearchIndexClient searchIndexClient,
            ElitPriceListRecord[] priceListPage,
            long updateUtcTimestamp,
            PriceListSynchronizationStatistics statistics)
        {
            var tryNumber = 1;

            while (true)
            {
                try
                {
                    var indexActions = priceListPage
                                       .Select(x => ConvertHelper.ElitUaApiModelToIndexAction(x, updateUtcTimestamp))
                                       .ToArray();
                    var indexBatch = IndexBatch.New(indexActions);
                    try
                    {
                        await searchIndexClient.Documents.IndexAsync(indexBatch);
                    }
                    catch (IndexBatchException ex)
                    {
                        var reasons = string.Join(", ", ex.IndexingResults
                                                  .Where(x => !x.Succeeded)
                                                  .Select(x => $"{x.Key}-{x.ErrorMessage}"));
                        var message = $"Failed to index products: {reasons}.";

                        throw new InvalidOperationException(message);
                    }

                    _logger.LogTrace(LoggingEvents.Synchronization, "Success.");
                    statistics.Received += priceListPage.Length;

                    return;
                }
                catch (Exception ex)
                {
                    _logger.LogError(LoggingEvents.UnhandledException, ex, $"Try {tryNumber}.");
                    if (tryNumber >= 3)
                    {
                        throw;
                    }

                    tryNumber++;
                }
            }
        }
Exemplo n.º 25
0
        public void GetDynamicDocumentCannotAlwaysDetermineCorrectType()
        {
            Run(() =>
            {
                SearchIndexClient client = Data.GetSearchIndexClient();

                var indexedDoc =
                    new Document()
                {
                    ["hotelId"]   = "1",
                    ["hotelName"] = "2015-02-11T12:58:00Z",
                    ["location"]  = GeographyPoint.Create(40.760586, -73.975403),    // Test that we don't confuse Geo-JSON & complex types.
                    ["rooms"]     = new[]
                    {
                        new Document()
                        {
                            ["baseRate"] = double.NaN
                        }
                    }
                };

                var expectedDoc =
                    new Document()
                {
                    ["hotelId"]   = "1",
                    ["hotelName"] = new DateTimeOffset(2015, 2, 11, 12, 58, 0, TimeSpan.Zero),
                    ["location"]  = GeographyPoint.Create(40.760586, -73.975403),
                    ["rooms"]     = new[]
                    {
                        new Document()
                        {
                            ["baseRate"] = "NaN"
                        }
                    }
                };

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

                // Select only the fields set in the test case so we don't get superfluous data back.
                IEnumerable <string> selectedFields = SelectPopulatedFields(indexedDoc);

                Document actualDoc = client.Documents.Get("1", selectedFields);
                Assert.Equal(expectedDoc, actualDoc);
            });
        }
Exemplo n.º 26
0
        /// <summary>
        /// Creates, populates, and queries an index of mountains.
        /// </summary>
        /// <param name="endpoint">The Search service URI.</param>
        /// <param name="key">The admin key for the Search service.</param>
        /// <param name="query">Keywords to query. The default is "*".</param>
        /// <param name="wait">The number of seconds to wait for indexing, if created. The default is 2 seconds.</param>
        /// <returns></returns>
        private static async Task Main(Uri endpoint, string key, string query = "*", int wait = 2)
        {
            using var cts           = new CancellationTokenSource();
            Console.CancelKeyPress += (sender, args) =>
            {
                cts.Cancel();
                args.Cancel = true;
            };

            var serviceName = endpoint.Host.Substring(0, endpoint.Host.IndexOf('.'));

            var credentials   = new SearchCredentials(key);
            var serviceClient = new SearchServiceClient(serviceName, credentials);
            var indexClient   = new SearchIndexClient(serviceName, Mountain.IndexName, credentials);

            if (!await serviceClient.Indexes.ExistsAsync(Mountain.IndexName, cancellationToken: cts.Token))
            {
                var fields = FieldBuilder.BuildForType <Mountain>();
                var index  = new Index(Mountain.IndexName, fields);

                await serviceClient.Indexes.CreateOrUpdateAsync(index, cancellationToken : cts.Token);

                var batch = new IndexBatch <Mountain>(new []
                {
                    new IndexAction <Mountain>(new Mountain
                    {
                        Name   = "Mount Rainier",
                        Summit = GeographyPoint.Create(46.85287, -121.76044),
                    }),
                });

                await indexClient.Documents.IndexAsync(batch);

                await Task.Delay(TimeSpan.FromSeconds(wait));
            }

            var results = await indexClient.Documents.SearchAsync <Mountain>(query, cancellationToken : cts.Token);

            foreach (var result in results.Results)
            {
                var mountain = result.Document;
                Console.WriteLine("https://www.bing.com/maps?cp={0}~{1}&sp=point.{0}_{1}_{2}",
                                  mountain.Summit.Latitude,
                                  mountain.Summit.Longitude,
                                  Uri.EscapeUriString(mountain.Name));
            }
        }
Exemplo n.º 27
0
        protected void TestCanSearchWithRangeFacets()
        {
            SearchIndexClient client = GetClientForQuery();

            var searchParameters =
                new SearchParameters()
            {
                Facets = new[]
                {
                    "rooms/baseRate,values:5|8|10",
                    "lastRenovationDate,values:2000-01-01T00:00:00Z"
                }
            };

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

            AssertContainsKeys(response, Data.TestDocuments.Select(d => d.HotelId).ToArray());

            Assert.NotNull(response.Facets);

            RangeFacetResult <double>[] baseRateFacets = GetRangeFacetsForField <double>(response.Facets, "rooms/baseRate", 4);

            Assert.False(baseRateFacets[0].From.HasValue);
            Assert.Equal(5.0, baseRateFacets[0].To);
            Assert.Equal(5.0, baseRateFacets[1].From);
            Assert.Equal(8.0, baseRateFacets[1].To);
            Assert.Equal(8.0, baseRateFacets[2].From);
            Assert.Equal(10.0, baseRateFacets[2].To);
            Assert.Equal(10.0, baseRateFacets[3].From);
            Assert.False(baseRateFacets[3].To.HasValue);

            Assert.Equal(1, baseRateFacets[0].Count);
            Assert.Equal(1, baseRateFacets[1].Count);
            Assert.Equal(1, baseRateFacets[2].Count);
            Assert.Equal(0, baseRateFacets[3].Count);

            RangeFacetResult <DateTimeOffset>[] lastRenovationDateFacets =
                GetRangeFacetsForField <DateTimeOffset>(response.Facets, "lastRenovationDate", 2);

            Assert.False(lastRenovationDateFacets[0].From.HasValue);
            Assert.Equal(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), lastRenovationDateFacets[0].To);
            Assert.Equal(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), lastRenovationDateFacets[1].From);
            Assert.False(lastRenovationDateFacets[1].To.HasValue);

            Assert.Equal(5, lastRenovationDateFacets[0].Count);
            Assert.Equal(2, lastRenovationDateFacets[1].Count);
        }
Exemplo n.º 28
0
        public async Task Authenticate()
        {
            await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this);

            Environment.SetEnvironmentVariable("SEARCH_ENDPOINT", resources.Endpoint.ToString());
            Environment.SetEnvironmentVariable("SEARCH_API_KEY", resources.PrimaryApiKey);

            #region Snippet:Azure_Search_Tests_Samples_Readme_Authenticate
            // Get the service endpoint and API key from the environment
            Uri    endpoint = new Uri(Environment.GetEnvironmentVariable("SEARCH_ENDPOINT"));
            string key      = Environment.GetEnvironmentVariable("SEARCH_API_KEY");

            // Create a client
            AzureKeyCredential credential = new AzureKeyCredential(key);
            SearchIndexClient  client     = new SearchIndexClient(endpoint, credential);
            #endregion Snippet:Azure_Search_Tests_Samples_Readme_Authenticate
        }
Exemplo n.º 29
0
        protected void TestSearchWithScoringProfileBoostsScore()
        {
            SearchIndexClient client = GetClientForQuery();

            var searchParameters =
                new SearchParameters()
            {
                ScoringProfile    = "nearest",
                ScoringParameters = new[] { new ScoringParameter("myloc", GeographyPoint.Create(49, -122)) },
                Filter            = "rating eq 5 or rating eq 1"
            };

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

            AssertKeySequenceEqual(response, "2", "1");
        }
Exemplo n.º 30
0
        protected void TestCanUseTopAndSkipForClientSidePaging()
        {
            SearchIndexClient client = GetClientForQuery();

            var searchParameters = new SearchParameters()
            {
                Top = 3, Skip = 0, OrderBy = new[] { "hotelId" }
            };
            DocumentSearchResult <Hotel> response = client.Documents.Search <Hotel>("*", searchParameters);

            AssertKeySequenceEqual(response, "1", "10", "2");

            searchParameters.Skip = 3;
            response = client.Documents.Search <Hotel>("*", searchParameters);

            AssertKeySequenceEqual(response, "3", "4", "5");
        }
        private SearchIndexClient GetSearchIndexClientForKey(string indexName, string apiKey)
        {
            var factory = new CSMTestEnvironmentFactory();
            TestEnvironment currentEnvironment = factory.GetTestEnvironment();

            Uri baseUri = 
                new Uri(
                    currentEnvironment.GetBaseSearchUri(ExecutionMode.CSM, SearchServiceName), 
                    String.Format("indexes/{0}/", indexName));

            SearchIndexClient client = new SearchIndexClient(new SearchCredentials(apiKey), baseUri);
            return TestBaseCopy.AddMockHandler<SearchIndexClient>(ref client);
        }