| | 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 System.Diagnostics; |
| | 7 | | using Azure.Core; |
| | 8 | | using Azure.Search.Documents.Models; |
| | 9 | |
|
| | 10 | | namespace Azure.Search.Documents |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// Options for <see cref="SearchClient.SearchAsync"/> that |
| | 14 | | /// allow specifying filtering, sorting, faceting, paging, and other search |
| | 15 | | /// query behaviors. |
| | 16 | | /// </summary> |
| | 17 | | [CodeGenModel("SearchRequest")] |
| | 18 | | public partial class SearchOptions |
| | 19 | | { |
| | 20 | | /// <summary> |
| | 21 | | /// Initializes a new instance of SearchOptions from a continuation |
| | 22 | | /// token to continue fetching results from a previous search. |
| | 23 | | /// </summary> |
| | 24 | | /// <param name="continuationToken"> |
| | 25 | | /// Encapsulates the state required to fetch the next page of search |
| | 26 | | /// results from the index. |
| | 27 | | /// </param> |
| 14 | 28 | | internal SearchOptions(string continuationToken) => |
| 14 | 29 | | Copy(SearchContinuationToken.Deserialize(continuationToken), this); |
| | 30 | |
|
| | 31 | | /// <summary> |
| | 32 | | /// A full-text search query expression; Use "*" or omit this |
| | 33 | | /// parameter to match all documents. |
| | 34 | | /// </summary> |
| | 35 | | [CodeGenMember("search")] |
| 503 | 36 | | internal string SearchText { get; set; } |
| | 37 | |
|
| | 38 | | /// <summary> |
| | 39 | | /// The OData $filter expression to apply to the search query. You can |
| | 40 | | /// use <see cref="SearchFilter.Create(FormattableString)"/> to help |
| | 41 | | /// construct the filter expression. |
| | 42 | | /// </summary> |
| | 43 | | [CodeGenMember("filter")] |
| 323 | 44 | | public string Filter { get; set; } |
| | 45 | |
|
| | 46 | | /// <summary> |
| | 47 | | /// The list of field names to use for hit highlights. Only searchable |
| | 48 | | /// fields can be used for hit highlighting. |
| | 49 | | /// </summary> |
| 482 | 50 | | public IList<string> HighlightFields { get; internal set; } = new List<string>(); |
| | 51 | |
|
| | 52 | | #pragma warning disable CA1822 // Only (unused but required) setters are static |
| | 53 | | /// <summary> |
| | 54 | | /// Join HighlightFields so it can be sent as a comma separated string. |
| | 55 | | /// </summary> |
| | 56 | | [CodeGenMember("HighlightFields")] |
| | 57 | | internal string HighlightFieldsRaw |
| | 58 | | { |
| 117 | 59 | | get => HighlightFields.CommaJoin(); |
| 42 | 60 | | set => HighlightFields = SearchExtensions.CommaSplit(value); |
| | 61 | | } |
| | 62 | | #pragma warning restore CA1822 |
| | 63 | |
|
| | 64 | | /// <summary> |
| | 65 | | /// The list of field names to which to scope the full-text search. |
| | 66 | | /// When using fielded search (fieldName:searchExpression) in a full |
| | 67 | | /// Lucene query, the field names of each fielded search expression |
| | 68 | | /// take precedence over any field names listed in this parameter. |
| | 69 | | /// </summary> |
| 482 | 70 | | public IList<string> SearchFields { get; internal set; } = new List<string>(); |
| | 71 | |
|
| | 72 | | #pragma warning disable CA1822 // Only (unused but required) setters are static |
| | 73 | | /// <summary> |
| | 74 | | /// Join SearchFields so it can be sent as a comma separated string. |
| | 75 | | /// </summary> |
| | 76 | | [CodeGenMember("searchFields")] |
| | 77 | | internal string SearchFieldsRaw |
| | 78 | | { |
| 117 | 79 | | get => SearchFields.CommaJoin(); |
| 42 | 80 | | set => SearchFields = SearchExtensions.CommaSplit(value); |
| | 81 | | } |
| | 82 | | #pragma warning restore CA1822 |
| | 83 | |
|
| | 84 | | /// <summary> |
| | 85 | | /// The list of fields to retrieve. If unspecified, all fields marked |
| | 86 | | /// as retrievable in the schema are included. |
| | 87 | | /// </summary> |
| 570 | 88 | | public IList<string> Select { get; internal set; } = new List<string>(); |
| | 89 | |
|
| | 90 | | #pragma warning disable CA1822 // Only (unused but required) setters are static |
| | 91 | | /// <summary> |
| | 92 | | /// Join Select so it can be sent as a comma separated string. |
| | 93 | | /// </summary> |
| | 94 | | [CodeGenMember("select")] |
| | 95 | | internal string SelectRaw |
| | 96 | | { |
| 189 | 97 | | get => Select.CommaJoin(); |
| 42 | 98 | | set => Select = SearchExtensions.CommaSplit(value); |
| | 99 | | } |
| | 100 | | #pragma warning restore CA1822 |
| | 101 | |
|
| | 102 | | /// <summary> |
| | 103 | | /// The number of search results to retrieve. This can be used in |
| | 104 | | /// conjunction with <see cref="Skip"/> to implement client-side |
| | 105 | | /// paging of search results. If results are truncated due to |
| | 106 | | /// server-side paging, the response will include a continuation token |
| | 107 | | /// that can be used to issue another Search request for the next page |
| | 108 | | /// of results. |
| | 109 | | /// </summary> |
| | 110 | | [CodeGenMember("top")] |
| 363 | 111 | | public int? Size { get; set; } |
| | 112 | |
|
| | 113 | | /// <summary> |
| | 114 | | /// The list of OData $orderby expressions by which to sort the |
| | 115 | | /// results. Each expression can be either a field name or a call to |
| | 116 | | /// either the geo.distance() or the search.score() functions. Each |
| | 117 | | /// expression can be followed by asc to indicate ascending, or desc to |
| | 118 | | /// indicate descending. The default is ascending order. Ties will be |
| | 119 | | /// broken by the match scores of documents. If no $orderby is |
| | 120 | | /// specified, the default sort order is descending by document match |
| | 121 | | /// score. There can be at most 32 $orderby clauses. |
| | 122 | | /// </summary> |
| 570 | 123 | | public IList<string> OrderBy { get; internal set; } = new List<string>(); |
| | 124 | |
|
| | 125 | | #pragma warning disable CA1822 // Only (unused but required) setters are static |
| | 126 | | /// <summary> |
| | 127 | | /// Join OrderBy so it can be sent as a comma separated string. |
| | 128 | | /// </summary> |
| | 129 | | [CodeGenMember("orderby")] |
| | 130 | | internal string OrderByRaw |
| | 131 | | { |
| 190 | 132 | | get => OrderBy.CommaJoin(); |
| 42 | 133 | | set => OrderBy = SearchExtensions.CommaSplit(value); |
| | 134 | | } |
| | 135 | | #pragma warning restore CA1822 |
| | 136 | |
|
| | 137 | | /// <summary> |
| | 138 | | /// A value that specifies whether to fetch the total count of results |
| | 139 | | /// as the <see cref="Models.SearchResults{T}.TotalCount"/> property. |
| | 140 | | /// The default value is false. Setting this value to true may have a |
| | 141 | | /// performance impact. Note that the count returned is an |
| | 142 | | /// approximation. |
| | 143 | | /// </summary> |
| | 144 | | [CodeGenMember("IncludeTotalResultCount")] |
| 309 | 145 | | public bool? IncludeTotalCount { get; set; } |
| | 146 | |
|
| | 147 | | /// <summary> |
| | 148 | | /// The list of facet expressions to apply to the search query. Each |
| | 149 | | /// facet expression contains a field name, optionally followed by a |
| | 150 | | /// comma-separated list of name:value pairs. |
| | 151 | | /// </summary> |
| | 152 | | [CodeGenMember("facets")] |
| 603 | 153 | | public IList<string> Facets { get; internal set; } = new List<string>(); |
| | 154 | |
|
| | 155 | | /// <summary> |
| | 156 | | /// The list of parameter values to be used in scoring functions (for |
| | 157 | | /// example, referencePointParameter) using the format name-values. For |
| | 158 | | /// example, if the scoring profile defines a function with a parameter |
| | 159 | | /// called 'mylocation' the parameter string would be |
| | 160 | | /// "mylocation--122.2,44.8" (without the quotes). |
| | 161 | | /// </summary> |
| | 162 | | [CodeGenMember("scoringParameters")] |
| 595 | 163 | | public IList<string> ScoringParameters { get; internal set; } = new List<string>(); |
| | 164 | |
|
| | 165 | | /// <summary> |
| | 166 | | /// Shallow copy one SearchOptions instance to another. |
| | 167 | | /// </summary> |
| | 168 | | /// <param name="source">The source options.</param> |
| | 169 | | /// <param name="destination">The destination options.</param> |
| | 170 | | private static void Copy(SearchOptions source, SearchOptions destination) |
| | 171 | | { |
| | 172 | | Debug.Assert(source != null); |
| | 173 | | Debug.Assert(destination != null); |
| | 174 | |
|
| 74 | 175 | | destination.SearchText = source.SearchText; |
| 74 | 176 | | destination.Filter = source.Filter; |
| 74 | 177 | | destination.HighlightFields = source.HighlightFields; |
| 74 | 178 | | destination.SearchFields = source.SearchFields; |
| 74 | 179 | | destination.Select = source.Select; |
| 74 | 180 | | destination.Size = source.Size; |
| 74 | 181 | | destination.OrderBy = source.OrderBy; |
| 74 | 182 | | destination.IncludeTotalCount = source.IncludeTotalCount; |
| 74 | 183 | | destination.Facets = source.Facets; |
| 74 | 184 | | destination.ScoringParameters = source.ScoringParameters; |
| 74 | 185 | | destination.HighlightPostTag = source.HighlightPostTag; |
| 74 | 186 | | destination.HighlightPreTag = source.HighlightPreTag; |
| 74 | 187 | | destination.MinimumCoverage = source.MinimumCoverage; |
| 74 | 188 | | destination.QueryType = source.QueryType; |
| 74 | 189 | | destination.ScoringProfile = source.ScoringProfile; |
| 74 | 190 | | destination.SearchMode = source.SearchMode; |
| 74 | 191 | | destination.Skip = source.Skip; |
| 74 | 192 | | } |
| | 193 | |
|
| | 194 | | /// <summary> |
| | 195 | | /// Creates a shallow copy of the SearchOptions. |
| | 196 | | /// </summary> |
| | 197 | | /// <returns>The cloned SearchOptions.</returns> |
| | 198 | | internal SearchOptions Clone() |
| | 199 | | { |
| 60 | 200 | | SearchOptions clone = new SearchOptions(); |
| 60 | 201 | | Copy(this, clone); |
| 60 | 202 | | return clone; |
| | 203 | | } |
| | 204 | | } |
| | 205 | | } |