你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

SearchIndex.Fields 属性

定义

获取或设置索引中的字段。 使用 FieldBuilder 定义基于模型类的字段,或 SimpleFieldSearchableFieldComplexField 手动定义字段。 索引字段具有许多约束,在服务器上创建索引之前,这些约束不会进行 SearchField 验证。

public System.Collections.Generic.IList<Azure.Search.Documents.Indexes.Models.SearchField> Fields { get; set; }
member this.Fields : System.Collections.Generic.IList<Azure.Search.Documents.Indexes.Models.SearchField> with get, set
Public Property Fields As IList(Of SearchField)

属性值

示例

可以使用 从模型类 FieldBuilder创建字段:

SearchIndex index = new SearchIndex("hotels")
{
    Fields = new FieldBuilder().Build(typeof(Hotel)),
    Suggesters =
    {
        // Suggest query terms from the HotelName field.
        new SearchSuggester("sg", "HotelName")
    }
};

因此, Fields 可设置。 在模型未知或无法修改的情况下,还可以使用帮助程序类手动创建字段:

SearchIndex index = new SearchIndex("hotels")
{
    Fields =
    {
        new SimpleField("HotelId", SearchFieldDataType.String) { IsKey = true, IsFilterable = true, IsSortable = true },
        new SearchableField("HotelName") { IsFilterable = true, IsSortable = true },
        new SearchableField("Description") { AnalyzerName = LexicalAnalyzerName.EnLucene },
        new SearchableField("Tags", collection: true) { IsFilterable = true, IsFacetable = true },
        new ComplexField("Address")
        {
            Fields =
            {
                new SearchableField("StreetAddress"),
                new SearchableField("City") { IsFilterable = true, IsSortable = true, IsFacetable = true },
                new SearchableField("StateProvince") { IsFilterable = true, IsSortable = true, IsFacetable = true },
                new SearchableField("Country") { IsFilterable = true, IsSortable = true, IsFacetable = true },
                new SearchableField("PostalCode") { IsFilterable = true, IsSortable = true, IsFacetable = true }
            }
        }
    },
    Suggesters =
    {
        // Suggest query terms from the hotelName field.
        new SearchSuggester("sg", "HotelName")
    }
};

适用于