| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | |
|
| | 6 | | namespace Azure.Search.Documents.Indexes.Models |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// A simple field using a primitive type or a collection of a primitive type. |
| | 10 | | /// </summary> |
| | 11 | | public class SimpleField : SearchFieldTemplate |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// Initializes a new instance of the <see cref="SimpleField"/> class. |
| | 15 | | /// </summary> |
| | 16 | | /// <param name="name">The name of the field, which must be unique within the index or parent field.</param> |
| | 17 | | /// <param name="type">The data type of the field.</param> |
| | 18 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 19 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| 16402 | 20 | | public SimpleField(string name, SearchFieldDataType type) : base(name, type) |
| | 21 | | { |
| 16402 | 22 | | } |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Gets or sets whether the field is the key field. The default is false. |
| | 26 | | /// A <see cref="SearchIndex"/> must have exactly one key field of type <see cref="SearchFieldDataType.String"/> |
| | 27 | | /// </summary> |
| 16412 | 28 | | public bool IsKey { get; set; } |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Gets or sets whether the field is returned in search results. The default is false. |
| | 32 | | /// A key field where <see cref="IsKey"/> is true must have this property set to false. |
| | 33 | | /// </summary> |
| 0 | 34 | | public bool IsHidden { get; set; } |
| | 35 | |
|
| | 36 | | /// <summary> |
| | 37 | | /// Gets or sets a value indicating whether the field can be referenced in <c>$filter</c> queries. The default i |
| | 38 | | /// </summary> |
| | 39 | | /// <remarks> |
| | 40 | | /// Filterable differs from searchable in how strings are handled. Fields of type <see cref="SearchFieldDataType |
| | 41 | | /// For example, if you set such a field <c>f</c> to "sunny day", <c>$filter=f eq 'sunny'</c> will find no match |
| | 42 | | /// </remarks> |
| 16497 | 43 | | public bool IsFilterable { get; set; } |
| | 44 | |
|
| | 45 | | /// <summary> |
| | 46 | | /// Gets or sets a value indicating whether the field can be retrieved in facet queries. The default is false. |
| | 47 | | /// </summary> |
| | 48 | | /// <remarks> |
| | 49 | | /// Facets are used in presentation of search results that include hit counts by categories. |
| | 50 | | /// For example, in a search for digital cameras, facets might include branch, megapixels, price, etc. |
| | 51 | | /// </remarks> |
| 16483 | 52 | | public bool IsFacetable { get; set; } |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Gets or sets a value indicating whether to enable the field can be referenced in <c>$orderby</c> expressions |
| | 56 | | /// </summary> |
| | 57 | | /// <remarks> |
| | 58 | | /// By default Azure Cognitive Search sorts results by score, but in many experiences users may want to sort by |
| | 59 | | /// </remarks> |
| 16464 | 60 | | public bool IsSortable { get; set; } |
| | 61 | |
|
| | 62 | | /// <inheritdoc/> |
| | 63 | | private protected override void Save(SearchField field) |
| | 64 | | { |
| 16402 | 65 | | field.IsKey = IsKey; |
| 16402 | 66 | | field.IsHidden = IsHidden; |
| 16402 | 67 | | field.IsFilterable = IsFilterable; |
| 16402 | 68 | | field.IsFacetable = IsFacetable; |
| 16402 | 69 | | field.IsSortable = IsSortable; |
| | 70 | |
|
| | 71 | | // Use a SearchableField instead, which will override this property. |
| | 72 | | // The service will return Searchable == false for all non-searchable simple types. |
| 16402 | 73 | | field.IsSearchable = false; |
| 16402 | 74 | | } |
| | 75 | | } |
| | 76 | | } |