Example #1
0
        public async Task GetStastistics()
        {
            await using SearchResources search = await SearchResources.CreateWithEmptyHotelsIndexAsync(this);

            SearchServiceClient client = search.GetServiceClient();
            Response <SearchServiceStatistics> response = await client.GetStatisticsAsync();

            Assert.AreEqual(200, response.GetRawResponse().Status);
            Assert.IsNotNull(response.Value);
            Assert.IsNotNull(response.Value.Counters);
            Assert.IsNotNull(response.Value.Counters.DataSourceCounter);
            Assert.IsNotNull(response.Value.Counters.DocumentCounter);
            Assert.IsNotNull(response.Value.Counters.IndexCounter);
            Assert.IsNotNull(response.Value.Counters.IndexerCounter);
            Assert.IsNotNull(response.Value.Counters.StorageSizeCounter);
            Assert.IsNotNull(response.Value.Counters.SynonymMapCounter);
            Assert.IsNotNull(response.Value.Limits);

            Assert.NotZero(response.Value.Counters.IndexCounter.Quota ?? 0);
            Assert.AreEqual(1, response.Value.Counters.IndexCounter.Usage ?? 0);
        }
Example #2
0
        public async Task CreateIndex()
        {
            await using SearchResources resources = SearchResources.CreateWithNoIndexes(this);
            Environment.SetEnvironmentVariable("SEARCH_ENDPOINT", resources.Endpoint.ToString());
            Environment.SetEnvironmentVariable("SEARCH_API_KEY", resources.PrimaryApiKey);

            #region Snippet:Azure_Search_Tests_Samples_Readme_CreateIndex
            Uri    endpoint = new Uri(Environment.GetEnvironmentVariable("SEARCH_ENDPOINT"));
            string key      = Environment.GetEnvironmentVariable("SEARCH_API_KEY");

            // Create a service client
            AzureKeyCredential  credential = new AzureKeyCredential(key);
            SearchServiceClient client     = new SearchServiceClient(endpoint, credential);
            /*@@*/ client = resources.GetServiceClient();

            // Create the index
            //@@SearchIndex index = new SearchIndex("hotels")
            /*@@*/ SearchIndex index = new SearchIndex(Recording.Random.GetName())
            {
                Fields =
                {
                    new SimpleField("hotelId",                    SearchFieldDataType.String)
                    {
                        IsKey = true,                             IsFilterable= true, IsSortable  = true
                    },
                    new SearchableField("hotelName")
                    {
                        IsFilterable = true,                      IsSortable  = true
                    },
                    new SearchableField("description")
                    {
                        Analyzer = LexicalAnalyzerName.EnLucene
                    },
                    new SearchableField("tags",                   collection: true)
                    {
                        IsFilterable = true,                      IsFacetable = true
                    },
                    new ComplexField("address")
                    {
                        Fields =
                        {
                            new SearchableField("streetAddress"),
                            new SearchableField("city")
                            {
                                IsFilterable = true,             IsSortable                = true, IsFacetable = true
                            },
                            new SearchableField("stateProvince")
                            {
                                IsFilterable = true,             IsSortable                = true, IsFacetable = true
                            },
                            new SearchableField("country")
                            {
                                IsFilterable = true,             IsSortable                = true, IsFacetable = true
                            },
                            new SearchableField("postalCode")
                            {
                                IsFilterable = true,             IsSortable                = true, IsFacetable = true
                            }
                        }
                    }
                },
                Suggesters =
                {
                    // Suggest query terms from both the hotelName and description fields.
                    new SearchSuggester("sg", "hotelName", "description")
                }
            };

            client.CreateIndex(index);
            #endregion Snippet:Azure_Search_Tests_Samples_Readme_CreateIndex
        }