Ejemplo n.º 1
0
        private static void CreateCatalogIndex()
        {
            var definition = new
            {
                Name   = _indexName,
                Fields = new[]
                {
                    new { Name = "productID", Type = "Edm.String", Key = true, Searchable = false, Filterable = false, Sortable = false, Facetable = false, Retrievable = true, Suggestions = false },
                    new { Name = "name", Type = "Edm.String", Key = false, Searchable = true, Filterable = false, Sortable = true, Facetable = false, Retrievable = true, Suggestions = true },
                    new { Name = "productNumber", Type = "Edm.String", Key = false, Searchable = true, Filterable = false, Sortable = false, Facetable = false, Retrievable = true, Suggestions = true },
                    new { Name = "color", Type = "Edm.String", Key = false, Searchable = true, Filterable = true, Sortable = true, Facetable = true, Retrievable = true, Suggestions = false },
                    new { Name = "standardCost", Type = "Edm.Double", Key = false, Searchable = false, Filterable = false, Sortable = false, Facetable = false, Retrievable = true, Suggestions = false },
                    new { Name = "listPrice", Type = "Edm.Double", Key = false, Searchable = false, Filterable = true, Sortable = true, Facetable = true, Retrievable = true, Suggestions = false },
                    new { Name = "size", Type = "Edm.String", Key = false, Searchable = true, Filterable = true, Sortable = true, Facetable = true, Retrievable = true, Suggestions = false },
                    new { Name = "weight", Type = "Edm.Double", Key = false, Searchable = false, Filterable = true, Sortable = false, Facetable = true, Retrievable = true, Suggestions = false },
                    new { Name = "sellStartDate", Type = "Edm.DateTimeOffset", Key = false, Searchable = false, Filterable = true, Sortable = false, Facetable = false, Retrievable = false, Suggestions = false },
                    new { Name = "sellEndDate", Type = "Edm.DateTimeOffset", Key = false, Searchable = false, Filterable = true, Sortable = false, Facetable = false, Retrievable = false, Suggestions = false },
                    new { Name = "discontinuedDate", Type = "Edm.DateTimeOffset", Key = false, Searchable = false, Filterable = true, Sortable = false, Facetable = false, Retrievable = true, Suggestions = false },
                    new { Name = "categoryName", Type = "Edm.String", Key = false, Searchable = true, Filterable = true, Sortable = false, Facetable = true, Retrievable = true, Suggestions = true },
                    new { Name = "modelName", Type = "Edm.String", Key = false, Searchable = true, Filterable = true, Sortable = false, Facetable = true, Retrievable = true, Suggestions = true },
                    new { Name = "description", Type = "Edm.String", Key = false, Searchable = true, Filterable = true, Sortable = false, Facetable = false, Retrievable = true, Suggestions = false }
                }
            };

            Uri    uri  = new Uri(_serviceUri, "/indexes");
            string json = AzureSearchHelper.SerializeJson(definition);
            HttpResponseMessage response = AzureSearchHelper.SendRequest(_httpClient, HttpMethod.Post, uri, json);

            response.EnsureSuccessStatusCode();
        }
Ejemplo n.º 2
0
        private static bool DeleteCatalogIndex()
        {
            Uri uri = new Uri(_serviceUri, "/indexes/" + _indexName);
            HttpResponseMessage response = AzureSearchHelper.SendRequest(_httpClient, HttpMethod.Delete, uri);

            if (response.StatusCode == HttpStatusCode.NotFound)
            {
                return(false);
            }
            response.EnsureSuccessStatusCode();
            return(true);
        }
Ejemplo n.º 3
0
        private static bool IndexCatalogBatch(List <Dictionary <string, object> > changes)
        {
            try
            {
                var batch = new
                {
                    value = changes
                };

                Uri    uri  = new Uri(_serviceUri, "/indexes/catalog/docs/index");
                string json = AzureSearchHelper.SerializeJson(batch);
                HttpResponseMessage response = AzureSearchHelper.SendRequest(_httpClient, HttpMethod.Post, uri, json);
                response.EnsureSuccessStatusCode();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }