| | 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 <see cref="SearchFieldDataType.String"/> or "Collection(String)" field that can be searched. |
| | 11 | | /// </summary> |
| | 12 | | public class SearchableField : SimpleField |
| | 13 | | { |
| | 14 | | private readonly List<string> _synonymMapNames; |
| | 15 | |
|
| | 16 | | /// <summary> |
| | 17 | | /// Initializes a new instance of the <see cref="SearchableField"/> class. |
| | 18 | | /// </summary> |
| | 19 | | /// <param name="name">The name of the field, which must be unique within the index or parent field.</param> |
| | 20 | | /// <param name="collection">Whether the field is a collection of strings.</param> |
| | 21 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 22 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| 82 | 23 | | public SearchableField(string name, bool collection = false) : base(name, collection ? SearchFieldDataType.Colle |
| | 24 | | { |
| | 25 | | // NOTE: Types other than string may be searchable one day. Could add an overload in the future. |
| 82 | 26 | | _synonymMapNames = new List<string>(); |
| 82 | 27 | | } |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// Gets or sets the name of the language analyzer. This property cannot be set when either <see cref="SearchAna |
| | 31 | | /// Once the analyzer is chosen, it cannot be changed for the field in the index. |
| | 32 | | /// </summary> |
| 104 | 33 | | public LexicalAnalyzerName? AnalyzerName { get; set; } |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// Gets or sets the name of the language analyzer for searching. This property must be set together with <see c |
| | 37 | | /// This property cannot be set to the name of a language analyzer; use the <see cref="AnalyzerName"/> property |
| | 38 | | /// Once the analyzer is chosen, it cannot be changed for the field in the index. |
| | 39 | | /// </summary> |
| 0 | 40 | | public LexicalAnalyzerName? SearchAnalyzerName { get; set; } |
| | 41 | |
|
| | 42 | | /// <summary> |
| | 43 | | /// Gets or sets the name of the language analyzer for indexing. This property must be set together with <see cr |
| | 44 | | /// This property cannot be set to the name of a language analyzer; use the <see cref="AnalyzerName"/> property |
| | 45 | | /// Once the analyzer is chosen, it cannot be changed for the field in the index. |
| | 46 | | /// </summary> |
| 0 | 47 | | public LexicalAnalyzerName? IndexAnalyzerName { get; set; } |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Gets a list of names of synonym maps to associate with this field. |
| | 51 | | /// Currently, only one synonym map per field is supported. |
| | 52 | | /// </summary> |
| | 53 | | /// <remarks> |
| | 54 | | /// Assigning a synonym map to a field ensures that query terms targeting that field are expanded at query-time |
| | 55 | | /// This attribute can be changed on existing fields. |
| | 56 | | /// </remarks> |
| | 57 | | public IList<string> SynonymMapNames |
| | 58 | | { |
| 83 | 59 | | get => _synonymMapNames; |
| | 60 | | internal set |
| | 61 | | { |
| 1 | 62 | | _synonymMapNames.Clear(); |
| | 63 | |
|
| 1 | 64 | | if (value != null) |
| | 65 | | { |
| 1 | 66 | | _synonymMapNames.AddRange(value); |
| | 67 | | } |
| 1 | 68 | | } |
| | 69 | | } |
| | 70 | |
|
| | 71 | | /// <inheritdoc/> |
| | 72 | | private protected override void Save(SearchField field) |
| | 73 | | { |
| 82 | 74 | | base.Save(field); |
| | 75 | |
|
| 82 | 76 | | field.IsSearchable = true; |
| 82 | 77 | | field.AnalyzerName = AnalyzerName; |
| 82 | 78 | | field.SearchAnalyzerName = SearchAnalyzerName; |
| 82 | 79 | | field.IndexAnalyzerName = IndexAnalyzerName; |
| | 80 | |
|
| 82 | 81 | | if (SynonymMapNames.Count > 0) |
| | 82 | | { |
| 1 | 83 | | IList<string> fields = field.SynonymMapNames; |
| 4 | 84 | | foreach (string name in SynonymMapNames) |
| | 85 | | { |
| 1 | 86 | | fields.Add(name); |
| | 87 | | } |
| | 88 | | } |
| 82 | 89 | | } |
| | 90 | | } |
| | 91 | | } |