private static ScoringProfile BuildScoringProfile() { var sp = new ScoringProfile("dvachatbotprofile1", new TextWeights(new Dictionary <string, double>() { { "purpose", 2D }, { "curatedKeyWords", 3D }, { "factsheetId", 5D } }), new List <ScoringFunction>() { new MagnitudeScoringFunction() { FieldName = "uniquePageViews", Interpolation = ScoringFunctionInterpolation.Linear, Boost = 2, Parameters = new MagnitudeScoringParameters() { BoostingRangeStart = 0, BoostingRangeEnd = 25000, ShouldBoostBeyondRangeByConstant = true } } } ); return(sp); }
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; } }
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); } } }
/// <summary> /// Create the topic index. /// </summary> /// <returns>create index task</returns> public async Task CreateIndex() { // form the index Index index = new Index(IndexName) .WithStringField("topicHandle", f => f.IsKey(true).IsRetrievable(true).IsSearchable(false).IsFilterable(false).SupportSuggestions(false).IsSortable(false).IsFacetable(false)) .WithStringField("topicTitle", f => f.IsKey(false).IsRetrievable(false).IsSearchable(true).IsFilterable(false).SupportSuggestions(false).IsSortable(false).IsFacetable(false)) .WithStringField("topicText", f => f.IsKey(false).IsRetrievable(false).IsSearchable(true).IsFilterable(false).SupportSuggestions(false).IsSortable(false).IsFacetable(false)) .WithStringCollectionField("topicTags", f => f.IsKey(false).IsRetrievable(true).IsSearchable(true).IsFilterable(false).SupportSuggestions(true).IsSortable(false).IsFacetable(true)) .WithStringField("appHandle", f => f.IsKey(false).IsRetrievable(true).IsSearchable(false).IsFilterable(true).SupportSuggestions(false).IsSortable(false).IsFacetable(false)) .WithStringField("userHandle", f => f.IsKey(false).IsRetrievable(true).IsSearchable(false).IsFilterable(true).SupportSuggestions(false).IsSortable(false).IsFacetable(false)) .WithIntegerField("searchWeight", f => f.IsKey(false).IsRetrievable(false).IsSearchable(false).IsFilterable(true).SupportSuggestions(false).IsSortable(true).IsFacetable(false)) .WithDateTimeField("topicLastModifiedTime", f => f.IsKey(false).IsRetrievable(false).IsSearchable(false).IsFilterable(true).SupportSuggestions(false).IsSortable(true).IsFacetable(false)); // create custom scoring profile ScoringProfile weightedScore = new ScoringProfile(); weightedScore.Name = ScoringProfileName; // function for scoring searchWeight ScoringProfileFunction weightedFunction1 = new ScoringProfileFunction(); weightedFunction1.Type = ScoringProfileFunctionType.Magnitude; weightedFunction1.Boost = 10; weightedFunction1.FieldName = "searchWeight"; weightedFunction1.Interpolation = InterpolationType.Quadratic; weightedFunction1.Magnitude = new ScoringProfileFunctionMagnitude(); weightedFunction1.Magnitude.BoostingRangeStart = 1; weightedFunction1.Magnitude.BoostingRangeEnd = 100; weightedFunction1.Magnitude.ConstantBoostBeyondRange = true; weightedScore.Functions.Add(weightedFunction1); // function for scoring freshness ScoringProfileFunction weightedFunction2 = new ScoringProfileFunction(); weightedFunction2.Type = ScoringProfileFunctionType.Freshness; weightedFunction2.Boost = 10; weightedFunction2.FieldName = "topicLastModifiedTime"; weightedFunction2.Interpolation = InterpolationType.Linear; weightedFunction2.Freshness = new ScoringProfileFunctionFreshness(); weightedFunction2.Freshness.BoostingDuration = new TimeSpan(2, 0, 0, 0); weightedScore.Functions.Add(weightedFunction2); weightedScore.FunctionAggregation = FunctionAggregation.Sum; index.ScoringProfiles.Add(weightedScore); index.DefaultScoringProfile = ScoringProfileName; // submit the create task await this.CreateIndex(index); }
private static void AssertScoringProfilesEqual(ScoringProfile expected, ScoringProfile actual) { Assert.Equal(expected.Name, actual.Name); if (expected.TextWeights == null) { Assert.Null(actual.TextWeights); } else { AssertCollectionsEqual( expected.TextWeights.Weights, actual.TextWeights.Weights, AssertTextWeightsEqual); } AssertCollectionsEqual(expected.Functions, actual.Functions, AssertScoringFunctionsEqual); }