Пример #1
0
        private static void CreateIndex()
        {
            // Create the Azure Search index based on the included schema
            try
            {
                // Create the suggester for suggestions
                Suggester sg = new Suggester();
                sg.Name = "sg";
                sg.SearchMode = SuggesterSearchMode.AnalyzingInfixMatching;
                sg.SourceFields = new List<string>() { "FEATURE_NAME", "COUNTY_NAME" };


                var definition = new Index()
                {
                    Name = "geonames",
                    Fields = new[] 
                    { 
                        new Field("FEATURE_ID",     DataType.String)         { IsKey = true,  IsSearchable = false, IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true},
                        new Field("FEATURE_NAME",   DataType.String)         { IsKey = false, IsSearchable = true,  IsFilterable = true,  IsSortable = true,  IsFacetable = false, IsRetrievable = true},
                        new Field("FEATURE_CLASS",  DataType.String)         { IsKey = false, IsSearchable = true,  IsFilterable = true,  IsSortable = true,  IsFacetable = false, IsRetrievable = true},
                        new Field("STATE_ALPHA",    DataType.String)         { IsKey = false, IsSearchable = true,  IsFilterable = true,  IsSortable = true,  IsFacetable = true, IsRetrievable = true},
                        new Field("STATE_NUMERIC",  DataType.Int32)          { IsKey = false, IsSearchable = false, IsFilterable = true,  IsSortable = true,  IsFacetable = false,  IsRetrievable = true},
                        new Field("COUNTY_NAME",    DataType.String)         { IsKey = false, IsSearchable = true,  IsFilterable = true,  IsSortable = true,  IsFacetable = true, IsRetrievable = true},
                        new Field("COUNTY_NUMERIC", DataType.Int32)          { IsKey = false, IsSearchable = false, IsFilterable = true,  IsSortable = true,  IsFacetable = false,  IsRetrievable = true},
                        new Field("ELEV_IN_M",      DataType.Int32)          { IsKey = false, IsSearchable = false, IsFilterable = true,  IsSortable = true,  IsFacetable = true,  IsRetrievable = true},
                        new Field("ELEV_IN_FT",     DataType.Int32)          { IsKey = false, IsSearchable = false, IsFilterable = true,  IsSortable = true,  IsFacetable = true,  IsRetrievable = true},
                        new Field("MAP_NAME",       DataType.String)         { IsKey = false, IsSearchable = true,  IsFilterable = true,  IsSortable = true,  IsFacetable = false, IsRetrievable = true},
                        new Field("DESCRIPTION",    DataType.String)         { IsKey = false, IsSearchable = true,  IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true},
                        new Field("HISTORY",        DataType.String)         { IsKey = false, IsSearchable = true,  IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true},
                        new Field("LOCATION",       DataType.GeographyPoint) { IsKey = false, IsSearchable = false, IsFilterable = true,  IsSortable = false, IsFacetable = false, IsRetrievable = true},
                        new Field("DATE_CREATED",   DataType.DateTimeOffset) { IsKey = false, IsSearchable = false, IsFilterable = true,  IsSortable = true,  IsFacetable = true,  IsRetrievable = true},
                        new Field("DATE_EDITED",    DataType.DateTimeOffset) { IsKey = false, IsSearchable = false, IsFilterable = true,  IsSortable = true,  IsFacetable = true,  IsRetrievable = true}
                    },
                    Suggesters = new List<Suggester> { sg }
                };

                _searchClient.Indexes.Create(definition);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error creating index: {0}\r\n", ex.Message.ToString());
            }

        }
Пример #2
0
        private static void CreateIndex()
        {
            try
            {
                Suggester sg = new Suggester();
                sg.Name = "sg";
                sg.SearchMode = SuggesterSearchMode.AnalyzingInfixMatching;
                sg.SourceFields = new string[] { "brand_name", "product_name", "sku", "product_subcategory", "product_category", "product_department", "product_family" };

                var definition = new Index()
                {
                    Name = IndexName,
                    Fields = new[]
                    {
                        new Field("product_id",         DataType.String)        { IsKey = true,  IsSearchable = false, IsFilterable = true,  IsSortable = false, IsFacetable = false, IsRetrievable = true  },
                        new Field("product_class_id",   DataType.Int32)         { IsKey = false, IsSearchable = false, IsFilterable = false, IsSortable = true,  IsFacetable = false, IsRetrievable = true  },
                        new Field("brand_name",         DataType.String)        { IsKey = false, IsSearchable = true,  IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true  },
                        new Field("product_name",       DataType.String)        { IsKey = false, IsSearchable = true,  IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true  },
                        new Field("sku",                DataType.String)        { IsKey = false, IsSearchable = true,  IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true  },
                        new Field("srp",                DataType.Int32)         { IsKey = false, IsSearchable = false, IsFilterable = true,  IsSortable = true,  IsFacetable = true,  IsRetrievable = true  },
                        new Field("gross_weight",       DataType.Double)        { IsKey = false, IsSearchable = false, IsFilterable = true,  IsSortable = true,  IsFacetable = true,  IsRetrievable = true  },
                        new Field("net_weight",         DataType.Double)        { IsKey = false, IsSearchable = false, IsFilterable = true,  IsSortable = true,  IsFacetable = true,  IsRetrievable = true  },
                        new Field("recyclable_package", DataType.String)        { IsKey = false, IsSearchable = false, IsFilterable = true,  IsSortable = false, IsFacetable = true,  IsRetrievable = true  },
                        new Field("low_fat",            DataType.String)        { IsKey = false, IsSearchable = false, IsFilterable = true,  IsSortable = false, IsFacetable = true,  IsRetrievable = true  },
                        new Field("units_per_case",     DataType.Int32)         { IsKey = false, IsSearchable = false, IsFilterable = true,  IsSortable = true,  IsFacetable = true,  IsRetrievable = true  },
                        new Field("cases_per_pallet",   DataType.Int32)         { IsKey = false, IsSearchable = false, IsFilterable = true,  IsSortable = true,  IsFacetable = true,  IsRetrievable = true  },
                        new Field("shelf_width",        DataType.Double)        { IsKey = false, IsSearchable = false, IsFilterable = true,  IsSortable = true,  IsFacetable = true,  IsRetrievable = true  },
                        new Field("shelf_height",       DataType.Double)        { IsKey = false, IsSearchable = false, IsFilterable = true,  IsSortable = true,  IsFacetable = true,  IsRetrievable = true  },
                        new Field("shelf_depth",        DataType.Double)        { IsKey = false, IsSearchable = false, IsFilterable = true,  IsSortable = true,  IsFacetable = true,  IsRetrievable = true  },
                        new Field("product_subcategory",DataType.String)        { IsKey = false, IsSearchable = true,  IsFilterable = false, IsSortable = false, IsFacetable = true,  IsRetrievable = true  },
                        new Field("product_category",   DataType.String)        { IsKey = false, IsSearchable = true,  IsFilterable = false, IsSortable = false, IsFacetable = true,  IsRetrievable = true  },
                        new Field("product_department", DataType.String)        { IsKey = false, IsSearchable = true,  IsFilterable = false, IsSortable = false, IsFacetable = true,  IsRetrievable = true  },
                        new Field("product_family",     DataType.String)        { IsKey = false, IsSearchable = true,  IsFilterable = false, IsSortable = false, IsFacetable = true,  IsRetrievable = true  },
                        new Field("url",                DataType.String)        { IsKey = false, IsSearchable = false, IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true  },
                        new Field("recommendations",    DataType.Collection(DataType.String)) { IsSearchable = true, IsFilterable = true, IsFacetable = true }
                    }
                };
                definition.Suggesters.Add(sg);
                _searchClient.Indexes.Create(definition);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error creating index: {0}:\r\n", ex.Message.ToString());
            }
        }
Пример #3
0
        private static void LoadPackagesIntoAzureSearch(IEnumerable<Package> packagesToLoad)
        {
            _searchServiceName = ConfigurationManager.AppSettings["SearchServiceName"];
              _apiKey = ConfigurationManager.AppSettings["SearchServiceApiKey"];

              _SearchClient = new SearchServiceClient(_searchServiceName, new SearchCredentials(_apiKey));
              _IndexClient = new SearchIndexClient(_searchServiceName, "packages", new SearchCredentials(_apiKey));

              Suggester sg = new Suggester();
              sg.Name = "sg";
              sg.SearchMode = SuggesterSearchMode.AnalyzingInfixMatching;
              sg.SourceFields = new List<string> { "NuGetIdRaw", "NuGetIdCollection" };

              var indexDefinition = new Index()
              {
            Name = "packages",
            Suggesters = new List<Suggester> { sg },
            Fields = new[]
            {
              new Field("NuGetIdRaw", DataType.String) { IsKey=false, IsSearchable=true, IsSortable=true, IsRetrievable=true },
              new Field("NuGetIdCollection", DataType.Collection(DataType.String)) { IsKey=false, IsSearchable=true, IsSortable=false, IsRetrievable=true, IsFacetable=true, IsFilterable=true },
              new Field("NuGetId", DataType.String) { IsKey=true, IsSearchable=false, IsSortable=false, IsRetrievable=true }
            }
              };

              // NOTE: ALready exists
              _SearchClient.Indexes.Delete("packages");
              _SearchClient.Indexes.Create(indexDefinition);

              // Populate
              try
              {

            for (var i = 0; i < packagesToLoad.Count(); i += 1000)
            {

              _IndexClient.Documents.Index(
            IndexBatch.Create(
              packagesToLoad.Skip(i).Take(1000).Select(
                doc => IndexAction.Create(new
                {
                  NuGetId = Guid.NewGuid(),
                  NuGetIdRaw = doc.NuGetId,
                  NuGetIdCollection = doc.NuGetId.Split('.')
                })
              )
            )
              );

            }
              }
              catch (IndexBatchException e)
              {
            // 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(", ", e.IndexResponse.Results.Where(r => !r.Succeeded).Select(r => r.Key)));
              }

              Console.Out.WriteLine("Completed");
        }
Пример #4
0
        private static void CreateIndex(string indexName, string suggesterName)
        {
            // Create the Azure Search index based on the included schema
            try
            {
                // Create the suggester for suggestions
                Suggester sg = new Suggester();
                sg.Name = suggesterName;
                sg.SearchMode = SuggesterSearchMode.AnalyzingInfixMatching;
                sg.SourceFields = new List<string>() { "name", "county" };

                var definition = new Index()
                {
                    Name = indexName,
                    Fields = new[]
                    {
                        new Field("id",     DataType.String)         { IsKey = true,  IsSearchable = false, IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true},
                        new Field("name",   DataType.String)         { IsKey = false, IsSearchable = true,  IsFilterable = true,  IsSortable = true,  IsFacetable = false, IsRetrievable = true},
                        new Field("county",    DataType.String)         { IsKey = false, IsSearchable = true,  IsFilterable = true,  IsSortable = true,  IsFacetable = true, IsRetrievable = true},
                        new Field("elevation",    DataType.Int64)         { IsKey = false, IsSearchable = false,  IsFilterable = true,  IsSortable = true,  IsFacetable = true, IsRetrievable = true},
                        new Field("location",       DataType.GeographyPoint) { IsKey = false, IsSearchable = false, IsFilterable = false,  IsSortable = false, IsFacetable = false, IsRetrievable = true},
                    },
                    Suggesters = new List<Suggester> { sg }
                };

                _searchClient.Indexes.Create(definition);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error creating index: {0}\r\n", ex.Message.ToString());
            }
        }