コード例 #1
0
ファイル: SearchIndex.cs プロジェクト: itverket/geek-retreat
        private static List<ScoringProfile> CreateScoringProfiles()
        {
            var freshnessScoringFunction = new FreshnessScoringFunction
            {
                Boost = 10,
                FieldName = "CreatedAt",
                Parameters = new FreshnessScoringParameters(new TimeSpan(7, 0, 0)),
                Interpolation = ScoringFunctionInterpolation.Quadratic
            };

            var distanceScoringFunction = new DistanceScoringFunction
            {
                Boost = 10,
                FieldName = "TweetCoordinates",
                Parameters = new DistanceScoringParameters("clientLocation", 3)
            };
            var retweetCountScoringFunction = new MagnitudeScoringFunction
            {
                Boost = 10,
                FieldName = "RetweetCount",
                Parameters = new MagnitudeScoringParameters(10, 1000),
                Interpolation = ScoringFunctionInterpolation.Logarithmic
            };

            var freshGeeksProfile = new ScoringProfile
            {
                Name = "FreshGeeks",
                Functions = new List<ScoringFunction>
                {
                    freshnessScoringFunction

                },
            };
            var neighbourGeeksProfile = new ScoringProfile
            {
                Name = "GeeklyNeighbours",
                Functions = new List<ScoringFunction>
                {
                    distanceScoringFunction
                }
            };
            var popularGeeksProfile = new ScoringProfile
            {
                Name = "PopularGeeks",
                Functions = new List<ScoringFunction>
                {
                    retweetCountScoringFunction
                }
            };

            return new List<ScoringProfile>
            {
                freshGeeksProfile,
                neighbourGeeksProfile,
                popularGeeksProfile
            };
        }
コード例 #2
0
        public void BuildAzureIndexSchema(AzureField keyField, AzureField idField)
        {
            if (!this.AzureSchemaBuilt)
            {
                try
                {
                    //this.AzureIndexFields = this.AzureIndexFields.Where(f => f.Name != keyField.Name).ToList();
                    AddAzureIndexField(keyField);
                    AddAzureIndexField(idField);

                    var indexName = index.Name;
                    var fields = AzureIndexFields
                        .GroupBy(f => f.Name)
                        .Select(f => f.First().Field).ToList();

                    var definition = new Index()
                    {
                        Name = indexName,
                        Fields = fields
                    };

                    var boostFields = AzureIndexFields.Where(f => f.Boost > 0 && f.Field.IsSearchable);
                    if (boostFields.Any())
                    {
                        var scoringProfile = new ScoringProfile();
                        scoringProfile.Name = index.AzureConfiguration.AzureDefaultScoringProfileName;
                        scoringProfile.TextWeights = new TextWeights(new Dictionary<string, double>());

                        foreach (var boostField in boostFields)
                        {
                            if (!scoringProfile.TextWeights.Weights.Any(w => w.Key == boostField.Name))
                            {
                                scoringProfile.TextWeights.Weights.Add(boostField.Name, boostField.Boost);
                            }
                        }

                        if (scoringProfile.TextWeights.Weights.Any())
                        {
                            definition.ScoringProfiles = new List<ScoringProfile>();
                            definition.ScoringProfiles.Add(scoringProfile);
                            definition.DefaultScoringProfile = index.AzureConfiguration.AzureDefaultScoringProfileName;
                        }
                    }

                    AzureIndex = index.AzureServiceClient.Indexes.Create(definition);
                    this.AzureSchemaBuilt = true;
                }
                catch (Exception ex)
                {
                    CrawlingLog.Log.Fatal("Error creating index" + index.Name, ex);
                }
            }
        }