< Summary

Class:Azure.Search.Documents.Indexes.Models.SearchIndex
Assembly:Azure.Search.Documents
File(s):C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\Models\SearchIndex.cs
C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\Models\SearchIndex.Serialization.cs
C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Indexes\Models\SearchIndex.cs
Covered lines:172
Uncovered lines:27
Coverable lines:199
Total lines:524
Line coverage:86.4% (172 of 199)
Covered branches:75
Total branches:92
Branch coverage:81.5% (75 of 92)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
get_DefaultScoringProfile()-100%100%
get_CorsOptions()-100%100%
get_EncryptionKey()-100%100%
get_Similarity()-100%100%
Azure.Core.IUtf8JsonSerializable.Write(...)-75.38%75%
DeserializeSearchIndex(...)-87.5%89.13%
.ctor(...)-100%100%
.ctor(...)-100%100%
get_Name()-100%100%
get_Analyzers()-100%100%
get_CharFilters()-100%100%
get_Fields()-100%100%
set_Fields(...)-100%100%
get_ScoringProfiles()-100%100%
get_Suggesters()-100%100%
get_TokenFilters()-100%100%
get_Tokenizers()-100%100%
get_ETag()-100%100%
set_ETag(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\Models\SearchIndex.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4// <auto-generated/>
 5
 6#nullable disable
 7
 8using System;
 9using System.Collections.Generic;
 10using System.Linq;
 11using Azure.Core;
 12
 13namespace Azure.Search.Documents.Indexes.Models
 14{
 15    /// <summary> Represents a search index definition, which describes the fields and search behavior of an index. </su
 16    public partial class SearchIndex
 17    {
 18
 19        /// <summary> Initializes a new instance of SearchIndex. </summary>
 20        /// <param name="name"> The name of the index. </param>
 21        /// <param name="fields"> The fields of the index. </param>
 22        /// <param name="scoringProfiles"> The scoring profiles for the index. </param>
 23        /// <param name="defaultScoringProfile"> The name of the scoring profile to use if none is specified in the quer
 24        /// <param name="corsOptions"> Options to control Cross-Origin Resource Sharing (CORS) for the index. </param>
 25        /// <param name="suggesters"> The suggesters for the index. </param>
 26        /// <param name="analyzers"> The analyzers for the index. </param>
 27        /// <param name="tokenizers"> The tokenizers for the index. </param>
 28        /// <param name="tokenFilters"> The token filters for the index. </param>
 29        /// <param name="charFilters"> The character filters for the index. </param>
 30        /// <param name="encryptionKey"> A description of an encryption key that you create in Azure Key Vault. This key
 31        /// <param name="similarity"> The type of similarity algorithm to be used when scoring and ranking the documents
 32        /// <param name="Etag"> The ETag of the index. </param>
 1933        internal SearchIndex(string name, IList<SearchField> fields, IList<ScoringProfile> scoringProfiles, string defau
 34        {
 1935            Name = name;
 1936            Fields = fields;
 1937            ScoringProfiles = scoringProfiles;
 1938            DefaultScoringProfile = defaultScoringProfile;
 1939            CorsOptions = corsOptions;
 1940            Suggesters = suggesters;
 1941            Analyzers = analyzers;
 1942            Tokenizers = tokenizers;
 1943            TokenFilters = tokenFilters;
 1944            CharFilters = charFilters;
 1945            EncryptionKey = encryptionKey;
 1946            Similarity = similarity;
 1947            _etag = Etag;
 1948        }
 49        /// <summary> The name of the scoring profile to use if none is specified in the query. If this property is not 
 2950        public string DefaultScoringProfile { get; set; }
 51        /// <summary> Options to control Cross-Origin Resource Sharing (CORS) for the index. </summary>
 2952        public CorsOptions CorsOptions { get; set; }
 53        /// <summary> A description of an encryption key that you create in Azure Key Vault. This key is used to provide
 2954        public SearchResourceEncryptionKey EncryptionKey { get; set; }
 55        /// <summary> The type of similarity algorithm to be used when scoring and ranking the documents matching a sear
 3156        public SimilarityAlgorithm Similarity { get; set; }
 57    }
 58}

C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\Models\SearchIndex.Serialization.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4// <auto-generated/>
 5
 6#nullable disable
 7
 8using System.Collections.Generic;
 9using System.Text.Json;
 10using Azure.Core;
 11
 12namespace Azure.Search.Documents.Indexes.Models
 13{
 14    public partial class SearchIndex : IUtf8JsonSerializable
 15    {
 16        void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 17        {
 1018            writer.WriteStartObject();
 1019            writer.WritePropertyName("name");
 1020            writer.WriteStringValue(Name);
 1021            writer.WritePropertyName("fields");
 1022            writer.WriteStartArray();
 21623            foreach (var item in Fields)
 24            {
 9825                writer.WriteObjectValue(item);
 26            }
 1027            writer.WriteEndArray();
 1028            if (Optional.IsCollectionDefined(ScoringProfiles))
 29            {
 630                writer.WritePropertyName("scoringProfiles");
 631                writer.WriteStartArray();
 2432                foreach (var item in ScoringProfiles)
 33                {
 634                    writer.WriteObjectValue(item);
 35                }
 636                writer.WriteEndArray();
 37            }
 1038            if (Optional.IsDefined(DefaultScoringProfile))
 39            {
 040                writer.WritePropertyName("defaultScoringProfile");
 041                writer.WriteStringValue(DefaultScoringProfile);
 42            }
 1043            if (Optional.IsDefined(CorsOptions))
 44            {
 045                if (CorsOptions != null)
 46                {
 047                    writer.WritePropertyName("corsOptions");
 048                    writer.WriteObjectValue(CorsOptions);
 49                }
 50                else
 51                {
 052                    writer.WriteNull("corsOptions");
 53                }
 54            }
 1055            if (Optional.IsCollectionDefined(Suggesters))
 56            {
 957                writer.WritePropertyName("suggesters");
 958                writer.WriteStartArray();
 3659                foreach (var item in Suggesters)
 60                {
 961                    writer.WriteObjectValue(item);
 62                }
 963                writer.WriteEndArray();
 64            }
 1065            if (Optional.IsCollectionDefined(Analyzers))
 66            {
 267                writer.WritePropertyName("analyzers");
 268                writer.WriteStartArray();
 869                foreach (var item in Analyzers)
 70                {
 271                    writer.WriteObjectValue(item);
 72                }
 273                writer.WriteEndArray();
 74            }
 1075            if (Optional.IsCollectionDefined(Tokenizers))
 76            {
 277                writer.WritePropertyName("tokenizers");
 278                writer.WriteStartArray();
 079                foreach (var item in Tokenizers)
 80                {
 081                    writer.WriteObjectValue(item);
 82                }
 283                writer.WriteEndArray();
 84            }
 1085            if (Optional.IsCollectionDefined(TokenFilters))
 86            {
 287                writer.WritePropertyName("tokenFilters");
 288                writer.WriteStartArray();
 089                foreach (var item in TokenFilters)
 90                {
 091                    writer.WriteObjectValue(item);
 92                }
 293                writer.WriteEndArray();
 94            }
 1095            if (Optional.IsCollectionDefined(CharFilters))
 96            {
 297                writer.WritePropertyName("charFilters");
 298                writer.WriteStartArray();
 099                foreach (var item in CharFilters)
 100                {
 0101                    writer.WriteObjectValue(item);
 102                }
 2103                writer.WriteEndArray();
 104            }
 10105            if (Optional.IsDefined(EncryptionKey))
 106            {
 0107                if (EncryptionKey != null)
 108                {
 0109                    writer.WritePropertyName("encryptionKey");
 0110                    writer.WriteObjectValue(EncryptionKey);
 111                }
 112                else
 113                {
 0114                    writer.WriteNull("encryptionKey");
 115                }
 116            }
 10117            if (Optional.IsDefined(Similarity))
 118            {
 2119                writer.WritePropertyName("similarity");
 2120                writer.WriteObjectValue(Similarity);
 121            }
 10122            if (Optional.IsDefined(_etag))
 123            {
 2124                writer.WritePropertyName("@odata.etag");
 2125                writer.WriteStringValue(_etag);
 126            }
 10127            writer.WriteEndObject();
 10128        }
 129
 130        internal static SearchIndex DeserializeSearchIndex(JsonElement element)
 131        {
 16132            string name = default;
 16133            IList<SearchField> fields = default;
 16134            Optional<IList<ScoringProfile>> scoringProfiles = default;
 16135            Optional<string> defaultScoringProfile = default;
 16136            Optional<CorsOptions> corsOptions = default;
 16137            Optional<IList<SearchSuggester>> suggesters = default;
 16138            Optional<IList<LexicalAnalyzer>> analyzers = default;
 16139            Optional<IList<LexicalTokenizer>> tokenizers = default;
 16140            Optional<IList<TokenFilter>> tokenFilters = default;
 16141            Optional<IList<CharFilter>> charFilters = default;
 16142            Optional<SearchResourceEncryptionKey> encryptionKey = default;
 16143            Optional<SimilarityAlgorithm> similarity = default;
 16144            Optional<string> odataEtag = default;
 472145            foreach (var property in element.EnumerateObject())
 146            {
 220147                if (property.NameEquals("name"))
 148                {
 16149                    name = property.Value.GetString();
 16150                    continue;
 151                }
 204152                if (property.NameEquals("fields"))
 153                {
 16154                    List<SearchField> array = new List<SearchField>();
 352155                    foreach (var item in property.Value.EnumerateArray())
 156                    {
 160157                        array.Add(SearchField.DeserializeSearchField(item));
 158                    }
 16159                    fields = array;
 16160                    continue;
 161                }
 188162                if (property.NameEquals("scoringProfiles"))
 163                {
 16164                    List<ScoringProfile> array = new List<ScoringProfile>();
 52165                    foreach (var item in property.Value.EnumerateArray())
 166                    {
 10167                        array.Add(ScoringProfile.DeserializeScoringProfile(item));
 168                    }
 16169                    scoringProfiles = array;
 16170                    continue;
 171                }
 172172                if (property.NameEquals("defaultScoringProfile"))
 173                {
 16174                    defaultScoringProfile = property.Value.GetString();
 16175                    continue;
 176                }
 156177                if (property.NameEquals("corsOptions"))
 178                {
 16179                    if (property.Value.ValueKind == JsonValueKind.Null)
 180                    {
 16181                        corsOptions = null;
 16182                        continue;
 183                    }
 0184                    corsOptions = CorsOptions.DeserializeCorsOptions(property.Value);
 0185                    continue;
 186                }
 140187                if (property.NameEquals("suggesters"))
 188                {
 16189                    List<SearchSuggester> array = new List<SearchSuggester>();
 62190                    foreach (var item in property.Value.EnumerateArray())
 191                    {
 15192                        array.Add(SearchSuggester.DeserializeSearchSuggester(item));
 193                    }
 16194                    suggesters = array;
 16195                    continue;
 196                }
 124197                if (property.NameEquals("analyzers"))
 198                {
 16199                    List<LexicalAnalyzer> array = new List<LexicalAnalyzer>();
 36200                    foreach (var item in property.Value.EnumerateArray())
 201                    {
 2202                        array.Add(LexicalAnalyzer.DeserializeLexicalAnalyzer(item));
 203                    }
 16204                    analyzers = array;
 16205                    continue;
 206                }
 108207                if (property.NameEquals("tokenizers"))
 208                {
 16209                    List<LexicalTokenizer> array = new List<LexicalTokenizer>();
 0210                    foreach (var item in property.Value.EnumerateArray())
 211                    {
 0212                        array.Add(LexicalTokenizer.DeserializeLexicalTokenizer(item));
 213                    }
 16214                    tokenizers = array;
 16215                    continue;
 216                }
 92217                if (property.NameEquals("tokenFilters"))
 218                {
 16219                    List<TokenFilter> array = new List<TokenFilter>();
 0220                    foreach (var item in property.Value.EnumerateArray())
 221                    {
 0222                        array.Add(TokenFilter.DeserializeTokenFilter(item));
 223                    }
 16224                    tokenFilters = array;
 16225                    continue;
 226                }
 76227                if (property.NameEquals("charFilters"))
 228                {
 16229                    List<CharFilter> array = new List<CharFilter>();
 0230                    foreach (var item in property.Value.EnumerateArray())
 231                    {
 0232                        array.Add(CharFilter.DeserializeCharFilter(item));
 233                    }
 16234                    charFilters = array;
 16235                    continue;
 236                }
 60237                if (property.NameEquals("encryptionKey"))
 238                {
 16239                    if (property.Value.ValueKind == JsonValueKind.Null)
 240                    {
 16241                        encryptionKey = null;
 16242                        continue;
 243                    }
 0244                    encryptionKey = SearchResourceEncryptionKey.DeserializeSearchResourceEncryptionKey(property.Value);
 0245                    continue;
 246                }
 44247                if (property.NameEquals("similarity"))
 248                {
 16249                    similarity = SimilarityAlgorithm.DeserializeSimilarityAlgorithm(property.Value);
 16250                    continue;
 251                }
 28252                if (property.NameEquals("@odata.etag"))
 253                {
 16254                    odataEtag = property.Value.GetString();
 255                    continue;
 256                }
 257            }
 16258            return new SearchIndex(name, fields, Optional.ToList(scoringProfiles), defaultScoringProfile.Value, corsOpti
 259        }
 260    }
 261}

C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Indexes\Models\SearchIndex.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Linq;
 7using Azure.Core;
 8
 9namespace Azure.Search.Documents.Indexes.Models
 10{
 11    public partial class SearchIndex
 12    {
 13        private IList<SearchField> _fields;
 14
 15        [CodeGenMember("etag")]
 16        private string _etag;
 17
 18        /// <summary>
 19        /// Initializes a new instance of the <see cref="SearchIndex"/> class.
 20        /// </summary>
 21        /// <param name="name">The name of the index.</param>
 22        /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception>
 23        /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception>
 924        public SearchIndex(string name)
 25        {
 926            Argument.AssertNotNullOrEmpty(name, nameof(name));
 27
 928            Name = name;
 29
 930            Analyzers = new ChangeTrackingList<LexicalAnalyzer>();
 931            CharFilters = new ChangeTrackingList<CharFilter>();
 932            Fields = new List<SearchField>();
 933            ScoringProfiles = new ChangeTrackingList<ScoringProfile>();
 934            Suggesters = new ChangeTrackingList<SearchSuggester>();
 935            TokenFilters = new ChangeTrackingList<TokenFilter>();
 936            Tokenizers = new ChangeTrackingList<LexicalTokenizer>();
 937        }
 38
 39        /// <summary>
 40        /// Initializes a new instance of the <see cref="SearchIndex"/> class.
 41        /// </summary>
 42        /// <param name="name">The name of the index.</param>
 43        /// <param name="fields">Fields to add to the index.</param>
 44        /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception>
 45        /// <exception cref="ArgumentNullException"><paramref name="name"/> or <paramref name="fields"/> is null.</excep
 146        public SearchIndex(string name, IEnumerable<SearchField> fields)
 47        {
 148            Argument.AssertNotNullOrEmpty(name, nameof(name));
 149            Argument.AssertNotNull(fields, nameof(fields));
 50
 151            Name = name;
 52
 153            Analyzers = new ChangeTrackingList<LexicalAnalyzer>();
 154            CharFilters = new ChangeTrackingList<CharFilter>();
 155            Fields = fields.ToList();
 156            ScoringProfiles = new ChangeTrackingList<ScoringProfile>();
 157            Suggesters = new ChangeTrackingList<SearchSuggester>();
 158            TokenFilters = new ChangeTrackingList<TokenFilter>();
 159            Tokenizers = new ChangeTrackingList<LexicalTokenizer>();
 160        }
 61
 62        /// <summary>
 63        /// Gets the name of the index.
 64        /// </summary>
 65        [CodeGenMember("name")]
 3066        public string Name { get; }
 67
 68        /// <summary>
 69        /// Gets the analyzers for the index.
 70        /// </summary>
 2271        public IList<LexicalAnalyzer> Analyzers { get; }
 72
 73        /// <summary>
 74        /// Gets the character filters for the index.
 75        /// </summary>
 1276        public IList<CharFilter> CharFilters { get; }
 77
 78#if EXPERIMENTAL_FIELDBUILDER
 79        /// <summary>
 80        /// Gets or sets the fields in the index.
 81        /// Use <see cref="FieldBuilder"/> to define fields based on a model class,
 82        /// or <see cref="SimpleField"/>, <see cref="SearchableField"/>, and <see cref="ComplexField"/> to manually defi
 83        /// Index fields have many constraints that are not validated with <see cref="SearchField"/> until the index is 
 84        /// </summary>
 85        /// <example>
 86        /// You can create fields from a model class using <see cref="FieldBuilder"/>:
 87        /// <code snippet="Snippet:Azure_Search_Tests_Samples_Readme_CreateIndex_New_SearchIndex">
 88        /// SearchIndex index = new SearchIndex(&quot;hotels&quot;)
 89        /// {
 90        ///     Fields = new FieldBuilder().Build(typeof(Hotel)),
 91        ///     Suggesters =
 92        ///     {
 93        ///         // Suggest query terms from the hotelName field.
 94        ///         new SearchSuggester(&quot;sg&quot;, &quot;hotelName&quot;)
 95        ///     }
 96        /// };
 97        /// </code>
 98        /// For this reason, <see cref="Fields"/> is settable. In scenarios when the model is not known or cannot be mod
 99        /// also create fields manually using helper classes:
 100        /// <code snippet="Snippet:Azure_Search_Tests_Samples_Readme_CreateManualIndex_New_SearchIndex">
 101        /// SearchIndex index = new SearchIndex(&quot;hotels&quot;)
 102        /// {
 103        ///     Fields =
 104        ///     {
 105        ///         new SimpleField(&quot;hotelId&quot;, SearchFieldDataType.String) { IsKey = true, IsFilterable = true
 106        ///         new SearchableField(&quot;hotelName&quot;) { IsFilterable = true, IsSortable = true },
 107        ///         new SearchableField(&quot;description&quot;) { AnalyzerName = LexicalAnalyzerName.EnLucene },
 108        ///         new SearchableField(&quot;tags&quot;, collection: true) { IsFilterable = true, IsFacetable = true },
 109        ///         new ComplexField(&quot;address&quot;)
 110        ///         {
 111        ///             Fields =
 112        ///             {
 113        ///                 new SearchableField(&quot;streetAddress&quot;),
 114        ///                 new SearchableField(&quot;city&quot;) { IsFilterable = true, IsSortable = true, IsFacetable 
 115        ///                 new SearchableField(&quot;stateProvince&quot;) { IsFilterable = true, IsSortable = true, IsF
 116        ///                 new SearchableField(&quot;country&quot;) { IsFilterable = true, IsSortable = true, IsFacetab
 117        ///                 new SearchableField(&quot;postalCode&quot;) { IsFilterable = true, IsSortable = true, IsFace
 118        ///             }
 119        ///         }
 120        ///     },
 121        ///     Suggesters =
 122        ///     {
 123        ///         // Suggest query terms from the hotelName field.
 124        ///         new SearchSuggester(&quot;sg&quot;, &quot;hotelName&quot;)
 125        ///     }
 126        /// };
 127        /// </code>
 128        /// </example>
 129#else
 130        /// <summary>
 131        /// Gets or sets the fields in the index.
 132        /// Use <see cref="SimpleField"/>, <see cref="SearchableField"/>, and <see cref="ComplexField"/> to manually def
 133        /// Index fields have many constraints that are not validated with <see cref="SearchField"/> until the index is 
 134        /// </summary>
 135        /// <example>
 136        /// You can create fields manually using helper classes:
 137        /// <code snippet="Snippet:Azure_Search_Tests_Samples_Readme_CreateManualIndex_New_SearchIndex">
 138        /// SearchIndex index = new SearchIndex(&quot;hotels&quot;)
 139        /// {
 140        ///     Fields =
 141        ///     {
 142        ///         new SimpleField(&quot;hotelId&quot;, SearchFieldDataType.String) { IsKey = true, IsFilterable = true
 143        ///         new SearchableField(&quot;hotelName&quot;) { IsFilterable = true, IsSortable = true },
 144        ///         new SearchableField(&quot;description&quot;) { AnalyzerName = LexicalAnalyzerName.EnLucene },
 145        ///         new SearchableField(&quot;tags&quot;, collection: true) { IsFilterable = true, IsFacetable = true },
 146        ///         new ComplexField(&quot;address&quot;)
 147        ///         {
 148        ///             Fields =
 149        ///             {
 150        ///                 new SearchableField(&quot;streetAddress&quot;),
 151        ///                 new SearchableField(&quot;city&quot;) { IsFilterable = true, IsSortable = true, IsFacetable 
 152        ///                 new SearchableField(&quot;stateProvince&quot;) { IsFilterable = true, IsSortable = true, IsF
 153        ///                 new SearchableField(&quot;country&quot;) { IsFilterable = true, IsSortable = true, IsFacetab
 154        ///                 new SearchableField(&quot;postalCode&quot;) { IsFilterable = true, IsSortable = true, IsFace
 155        ///             }
 156        ///         }
 157        ///     },
 158        ///     Suggesters =
 159        ///     {
 160        ///         // Suggest query terms from the hotelName field.
 161        ///         new SearchSuggester(&quot;sg&quot;, &quot;hotelName&quot;)
 162        ///     }
 163        /// };
 164        /// </code>
 165        /// </example>
 166#endif
 167        public IList<SearchField> Fields
 168        {
 87169            get => _fields;
 170            set
 171            {
 33172                _fields = value ?? throw new ArgumentNullException(nameof(value), $"{nameof(Fields)} cannot be null. To 
 32173            }
 174        }
 175
 176        /// <summary>
 177        /// Gets the scoring profiles for the index.
 178        /// </summary>
 36179        public IList<ScoringProfile> ScoringProfiles { get; }
 180
 181        /// <summary>
 182        /// Gets the suggesters for the index.
 183        /// </summary>
 42184        public IList<SearchSuggester> Suggesters { get; }
 185
 186        /// <summary>
 187        /// Gets the token filters for the index.
 188        /// </summary>
 12189        public IList<TokenFilter> TokenFilters { get; }
 190
 191        /// <summary>
 192        /// Gets the tokenizers for the index.
 193        /// </summary>
 12194        public IList<LexicalTokenizer> Tokenizers { get; }
 195
 196        /// <summary>
 197        /// The <see cref="Azure.ETag"/> of the <see cref="SearchIndex"/>.
 198        /// </summary>
 199        public ETag? ETag
 200        {
 5201            get => _etag is null ? (ETag?)null : new ETag(_etag);
 0202            set => _etag = value?.ToString();
 203        }
 204    }
 205}