使用 .NET 客户端添加评分配置文件

Adding a scoring profile with the .NET client

我找不到如何使用 Azure 搜索的 .NET 客户端添加评分配置文件。是的,我知道 there's a doc 使用 REST API 谢谢

评分配置文件必须与索引同时创建:

private async Task CreateIndexAsync<T>(string index) where T : class
{
    var definition = new Index()
    {
       Name = index,
       Fields = FieldBuilder.BuildForType<T>(),
       ScoringProfiles = new List<ScoringProfile>
       {
           //your scoring profiles here
       }
   };

   if (!_adminServiceClient.Indexes.Exists(index))
   {
       await _adminServiceClient.Indexes.CreateAsync(definition);
   }

 }

如果您使用 Azure 搜索库的 v11 .Net,您可以像这样将评分配置文件添加到搜索索引:

var fieldBuilder = new FieldBuilder();
var searchFields = fieldBuilder.Build(typeof(MyType));
var definition = new SearchIndex(name: "MyIndexName", searchFields);

definition.ScoringProfiles.Add(new ScoringProfile(name: "default")
{
  // Your scoring profile definition
}

await _searchIndexClient.CreateIndexAsync(definition);