| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using Azure.Search.Documents.Indexes.Models; |
| | 6 | |
|
| | 7 | | namespace Azure.Search.Documents.Indexes |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// Attributes a simple field using a primitive type or a collection of a primitive type. |
| | 11 | | /// </summary> |
| | 12 | | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] |
| | 13 | | public class SearchableFieldAttribute : SimpleFieldAttribute, ISearchFieldAttribute |
| | 14 | | { |
| | 15 | | /// <summary> |
| | 16 | | /// Gets or sets the name of the language analyzer. This property cannot be set when either <see cref="SearchAna |
| | 17 | | /// Once the analyzer is chosen, it cannot be changed for the field in the index. |
| | 18 | | /// </summary> |
| | 19 | | /// <value>String values from <see cref="LexicalAnalyzerName.Values">LexicalAnalyzerName</see>, or the name of a |
| 5841 | 20 | | public string AnalyzerName { get; set; } |
| | 21 | |
|
| | 22 | | /// <summary> |
| | 23 | | /// Gets or sets the name of the language analyzer for searching. This property must be set together with <see c |
| | 24 | | /// This property cannot be set to the name of a language analyzer; use the <see cref="AnalyzerName"/> property |
| | 25 | | /// Once the analyzer is chosen, it cannot be changed for the field in the index. |
| | 26 | | /// </summary> |
| | 27 | | /// <value>String values from <see cref="LexicalAnalyzerName.Values">LexicalAnalyzerName</see>, or the name of a |
| 4277 | 28 | | public string SearchAnalyzerName { get; set; } |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Gets or sets the name of the language analyzer for indexing. This property must be set together with <see cr |
| | 32 | | /// This property cannot be set to the name of a language analyzer; use the <see cref="AnalyzerName"/> property |
| | 33 | | /// Once the analyzer is chosen, it cannot be changed for the field in the index. |
| | 34 | | /// </summary> |
| | 35 | | /// <value>String values from <see cref="LexicalAnalyzerName.Values">LexicalAnalyzerName</see>, or the name of a |
| 4277 | 36 | | public string IndexAnalyzerName { get; set; } |
| | 37 | |
|
| | 38 | | /// <summary> |
| | 39 | | /// Gets or sets a list of names of synonym maps to associate with this field. |
| | 40 | | /// Currently, only one synonym map per field is supported. |
| | 41 | | /// </summary> |
| | 42 | | /// <remarks> |
| | 43 | | /// Assigning a synonym map to a field ensures that query terms targeting that field are expanded at query-time |
| | 44 | | /// This attribute can be changed on existing fields. |
| | 45 | | /// </remarks> |
| 5049 | 46 | | public string[] SynonymMapNames { get; set; } |
| | 47 | |
|
| | 48 | | /// <inheritdoc/> |
| | 49 | | void ISearchFieldAttribute.SetField(SearchField field) |
| | 50 | | { |
| 2725 | 51 | | SetField(field); |
| | 52 | |
|
| 2725 | 53 | | field.IsSearchable = true; |
| | 54 | |
|
| 2725 | 55 | | if (SynonymMapNames != null) |
| | 56 | | { |
| 386 | 57 | | field.SynonymMapNames.Clear(); |
| 1544 | 58 | | for (int i = 0; i < SynonymMapNames.Length; ++i) |
| | 59 | | { |
| 386 | 60 | | field.SynonymMapNames.Add(SynonymMapNames[i]); |
| | 61 | | } |
| | 62 | | } |
| | 63 | |
|
| 2725 | 64 | | if (AnalyzerName != null) |
| | 65 | | { |
| 1168 | 66 | | field.AnalyzerName = AnalyzerName; |
| | 67 | | } |
| | 68 | |
|
| 2725 | 69 | | if (SearchAnalyzerName != null) |
| | 70 | | { |
| 386 | 71 | | field.SearchAnalyzerName = SearchAnalyzerName; |
| | 72 | | } |
| | 73 | |
|
| 2725 | 74 | | if (IndexAnalyzerName != null) |
| | 75 | | { |
| 386 | 76 | | field.IndexAnalyzerName = IndexAnalyzerName; |
| | 77 | | } |
| 2725 | 78 | | } |
| | 79 | | } |
| | 80 | | } |