Azure 搜索:如何在 v11 中指定搜索字段

Azure Search: How to specify search fields in v11

在 Azure 搜索 SDK v10 中,我能够利用 SearchParameters class. In v11, I see there is SearchOptions, but the SearchFields parameter is get only. In v10, SearchFields 的 setter.

来准确指定要在索引中搜索的字段

如何选择在 v11 中搜索哪些字段?

您可以在 SearchFields 属性 上调用 .Add():

var options = new SearchOptions();
options.SearchFields.Add("field1");
options.SearchFields.Add("field2");

或者您可以使用 C# 的列表初始化语法:

var options = new SearchOptions() { SearchFields = { "field1", "field2" } };

示例改编自 this GitHub issue