【问题标题】:Adding a scoring profile with the .NET client使用 .NET 客户端添加评分配置文件
【发布时间】:2019-07-02 03:47:13
【问题描述】:

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

【问题讨论】:

    标签: azure-cognitive-search azure-search-.net-sdk


    【解决方案1】:

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

    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);
       }
    
     }
    

    【讨论】:

      【解决方案2】:

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

      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);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多