| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using Azure.Core; |
| | 7 | |
|
| | 8 | | namespace Azure.Search.Documents |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// Options for <see cref="SearchClient.SuggestAsync"/> that |
| | 12 | | /// allow specifying filtering, sorting, and other suggestions query |
| | 13 | | /// behaviors. |
| | 14 | | /// </summary> |
| | 15 | | [CodeGenModel("SuggestRequest")] |
| | 16 | | [CodeGenSuppress(nameof(SuggestOptions), typeof(string), typeof(string))] |
| | 17 | | public partial class SuggestOptions |
| | 18 | | { |
| | 19 | | /// <summary> |
| | 20 | | /// Initializes new instance of <see cref="SuggestOptions"/> |
| | 21 | | /// </summary> |
| 48 | 22 | | public SuggestOptions() |
| | 23 | | { |
| 48 | 24 | | } |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// The search text to use to suggest documents. Must be at least 1 |
| | 28 | | /// character, and no more than 100 characters. |
| | 29 | | /// </summary> |
| | 30 | | [CodeGenMember("search")] |
| 96 | 31 | | internal string SearchText { get; set; } |
| | 32 | |
|
| | 33 | | /// <summary> |
| | 34 | | /// The name of the suggester as specified in the suggesters collection |
| | 35 | | /// that's part of the index definition. |
| | 36 | | /// </summary> |
| | 37 | | [CodeGenMember("suggesterName")] |
| 96 | 38 | | internal string SuggesterName { get; set; } |
| | 39 | |
|
| | 40 | | /// <summary> |
| | 41 | | /// An OData expression that filters the documents considered for |
| | 42 | | /// suggestions. You can use |
| | 43 | | /// <see cref="SearchFilter.Create(FormattableString)"/> to help |
| | 44 | | /// construct the filter expression. |
| | 45 | | /// </summary> |
| | 46 | | [CodeGenMember("filter")] |
| 78 | 47 | | public string Filter { get; set; } |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// The list of field names to search for the specified search text. |
| | 51 | | /// Target fields must be included in the specified suggester. |
| | 52 | | /// </summary> |
| 122 | 53 | | public IList<string> SearchFields { get; internal set; } = new List<string>(); |
| | 54 | |
|
| | 55 | | #pragma warning disable CA1822 // Only (unused but required) setters are static |
| | 56 | | /// <summary> |
| | 57 | | /// Join SearchFields so it can be sent as a comma separated string. |
| | 58 | | /// </summary> |
| | 59 | | [CodeGenMember("searchFields")] |
| | 60 | | internal string SearchFieldsRaw |
| | 61 | | { |
| 28 | 62 | | get => SearchFields.CommaJoin(); |
| 0 | 63 | | set => throw new InvalidOperationException($"Cannot deserialize {nameof(SuggestOptions)}."); |
| | 64 | | } |
| | 65 | | #pragma warning restore CA1822 |
| | 66 | |
|
| | 67 | | /// <summary> |
| | 68 | | /// The list of fields to retrieve. If unspecified, only the key field |
| | 69 | | /// will be included in the results. |
| | 70 | | /// </summary> |
| 122 | 71 | | public IList<string> Select { get; internal set; } = new List<string>(); |
| | 72 | |
|
| | 73 | | #pragma warning disable CA1822 // Only (unused but required) setters are static |
| | 74 | | /// <summary> |
| | 75 | | /// Join Select so it can be sent as a comma separated string. |
| | 76 | | /// </summary> |
| | 77 | | [CodeGenMember("select")] |
| | 78 | | internal string SelectRaw |
| | 79 | | { |
| 28 | 80 | | get => Select.CommaJoin(); |
| 0 | 81 | | set => throw new InvalidOperationException($"Cannot deserialize {nameof(SuggestOptions)}."); |
| | 82 | | } |
| | 83 | | #pragma warning restore CA1822 |
| | 84 | |
|
| | 85 | | /// <summary> |
| | 86 | | /// The number of suggestions to retrieve. This must be a value between |
| | 87 | | /// 1 and 100. The default is 5. |
| | 88 | | /// </summary> |
| | 89 | | [CodeGenMember("top")] |
| 78 | 90 | | public int? Size { get; set; } |
| | 91 | |
|
| | 92 | | /// <summary> |
| | 93 | | /// The list of OData $orderby expressions by which to sort the |
| | 94 | | /// results. Each expression can be either a field name or a call to |
| | 95 | | /// either the geo.distance() or the search.score() functions. Each |
| | 96 | | /// expression can be followed by asc to indicate ascending, or desc |
| | 97 | | /// to indicate descending. The default is ascending order. Ties will |
| | 98 | | /// be broken by the match scores of documents. If no $orderby is |
| | 99 | | /// specified, the default sort order is descending by document match |
| | 100 | | /// score. There can be at most 32 $orderby clauses. |
| | 101 | | /// </summary> |
| 142 | 102 | | public IList<string> OrderBy { get; internal set; } = new List<string>(); |
| | 103 | |
|
| | 104 | | #pragma warning disable CA1822 // Only (unused but required) setters are static |
| | 105 | | /// <summary> |
| | 106 | | /// Join OrderBy so it can be sent as a comma separated string. |
| | 107 | | /// </summary> |
| | 108 | | [CodeGenMember("orderby")] |
| | 109 | | internal string OrderByRaw |
| | 110 | | { |
| 38 | 111 | | get => OrderBy.CommaJoin(); |
| 0 | 112 | | set => throw new InvalidOperationException($"Cannot deserialize {nameof(SuggestOptions)}."); |
| | 113 | | } |
| | 114 | | #pragma warning restore CA1822 |
| | 115 | |
|
| | 116 | | /// <summary> |
| | 117 | | /// Creates a shallow copy of the SuggestOptions. |
| | 118 | | /// </summary> |
| | 119 | | /// <returns>The cloned SuggestOptions.</returns> |
| | 120 | | internal SuggestOptions Clone() => |
| 22 | 121 | | new SuggestOptions |
| 22 | 122 | | { |
| 22 | 123 | | SearchText = SearchText, |
| 22 | 124 | | SuggesterName = SuggesterName, |
| 22 | 125 | | Filter = Filter, |
| 22 | 126 | | SearchFields = SearchFields, |
| 22 | 127 | | Select = Select, |
| 22 | 128 | | Size = Size, |
| 22 | 129 | | OrderBy = OrderBy, |
| 22 | 130 | | HighlightPostTag = HighlightPostTag, |
| 22 | 131 | | HighlightPreTag = HighlightPreTag, |
| 22 | 132 | | MinimumCoverage = MinimumCoverage, |
| 22 | 133 | | UseFuzzyMatching = UseFuzzyMatching, |
| 22 | 134 | | }; |
| | 135 | | } |
| | 136 | | } |