| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | |
|
| | 7 | | namespace Azure.Search.Documents.Indexes.Models |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// A complex field or collection of complex fields that contain child fields. |
| | 11 | | /// Child fields may be <see cref="SimpleField"/> or <see cref="ComplexField"/>. |
| | 12 | | /// </summary> |
| | 13 | | public class ComplexField : SearchFieldTemplate |
| | 14 | | { |
| | 15 | | /// <summary> |
| | 16 | | /// Initializes a new instance of the <see cref="ComplexField"/> class. |
| | 17 | | /// </summary> |
| | 18 | | /// <param name="name">The name of the field, which must be unique within the index or parent field.</param> |
| | 19 | | /// <param name="collection">Whether the field is a collection of strings.</param> |
| | 20 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 21 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| 12 | 22 | | public ComplexField(string name, bool collection = false) : base(name, collection ? SearchFieldDataType.Collecti |
| | 23 | | { |
| 12 | 24 | | } |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Initializes a new instance of the <see cref="ComplexField"/> class. |
| | 28 | | /// </summary> |
| | 29 | | /// <param name="name">The name of the field, which must be unique within the index or parent field.</param> |
| | 30 | | /// <param name="type">The data type of the field.</param> |
| | 31 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 32 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 33 | | /// <remarks> |
| | 34 | | /// This is used internally by FieldBuilder to avoid detecting if the type is a collection just |
| | 35 | | /// to return the same type we started with. |
| | 36 | | /// </remarks> |
| 3127 | 37 | | internal ComplexField(string name, SearchFieldDataType type) : base(name, type) |
| | 38 | | { |
| 3127 | 39 | | } |
| | 40 | |
|
| | 41 | | /// <summary> |
| | 42 | | /// Gets a collection of <see cref="SimpleField"/> or <see cref="ComplexField"/> child fields. |
| | 43 | | /// </summary> |
| 6343 | 44 | | public IList<SearchFieldTemplate> Fields { get; } = new List<SearchFieldTemplate>(); |
| | 45 | |
|
| | 46 | | /// <inheritdoc/> |
| | 47 | | private protected override void Save(SearchField field) |
| | 48 | | { |
| 3139 | 49 | | IList<SearchField> fields = field.Fields; |
| 6408 | 50 | | foreach (SearchFieldTemplate child in Fields) |
| | 51 | | { |
| 65 | 52 | | fields.Add(child); |
| | 53 | | } |
| 3139 | 54 | | } |
| | 55 | | } |
| | 56 | | } |