다음을 통해 공유


SearchIndex.Fields Property

Definition

Gets or sets the fields in the index. Use FieldBuilder to define fields based on a model class, or SimpleField, SearchableField, and ComplexField to manually define fields. Index fields have many constraints that are not validated with SearchField until the index is created on the server.

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)

Property Value

Examples

You can create fields from a model class using FieldBuilder:

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

For this reason, Fields is settable. In scenarios when the model is not known or cannot be modified, you can also create fields manually using helper classes:

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

Applies to