Ejemplo n.º 1
0
        public static void CreateSearchIndex()
        {
            try
            {
                //connect to Azure Search
                SearchServiceClient serviceClient = CreateSearchServiceClient();

                //defining the suggester
                Suggester sg = new Suggester
                {
                    Name         = "eecip_suggest",
                    SourceFields = new List <string>()
                    {
                        "Name"
                    }
                };

                //defining the scoring profile //boosts items updated in the last 180 days
                ScoringProfile sp = new ScoringProfile {
                    Name = "date_scoring"
                };

                var freshnessFunction = new FreshnessScoringFunction()
                {
                    FieldName     = "LastUpdated",
                    Boost         = 20,
                    Parameters    = new FreshnessScoringParameters(new TimeSpan(180, 0, 0, 0)),
                    Interpolation = ScoringFunctionInterpolation.Linear
                };
                // Assigns the freshness function to the scoring profile
                sp.Functions = new List <ScoringFunction>()
                {
                    freshnessFunction
                };


                //define the index (the fields, and link in the suggester and scoring)
                var definition = new Index()
                {
                    Name       = "eecip",
                    Fields     = FieldBuilder.BuildForType <EECIP_Index>(),
                    Suggesters = new List <Suggester> {
                        sg
                    },
                    ScoringProfiles = new List <ScoringProfile>()
                    {
                        sp
                    }
                };



                serviceClient.Indexes.Create(definition);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private static void AssertFreshnessScoringFunctionsEqual(
            FreshnessScoringFunction expected,
            FreshnessScoringFunction actual)
        {
            Assert.NotNull(expected.Parameters);
            Assert.NotNull(actual.Parameters);

            Assert.Equal(expected.Parameters.BoostingDuration, actual.Parameters.BoostingDuration);
        }