From d6321cf62249dee5ebb05c250be5e27bd8c7e6a8 Mon Sep 17 00:00:00 2001 From: Heath Stewart Date: Wed, 3 Jun 2020 02:33:01 -0700 Subject: [PATCH 1/2] Remove FieldBuilder Resolves #12460 --- .../src/Indexes/FieldBuilder.cs | 49 ----------- .../src/Indexes/ISearchFieldAttribute.cs | 20 ----- .../src/Indexes/SearchableFieldAttribute.cs | 87 ------------------- .../src/Indexes/SimpleFieldAttribute.cs | 78 ----------------- .../tests/FieldBuilderTests.cs | 21 ----- .../tests/SearchableFieldAttributeTests.cs | 72 --------------- .../tests/SimpleFieldAttributeTests.cs | 45 ---------- 7 files changed, 372 deletions(-) delete mode 100644 sdk/search/Azure.Search.Documents/src/Indexes/FieldBuilder.cs delete mode 100644 sdk/search/Azure.Search.Documents/src/Indexes/ISearchFieldAttribute.cs delete mode 100644 sdk/search/Azure.Search.Documents/src/Indexes/SearchableFieldAttribute.cs delete mode 100644 sdk/search/Azure.Search.Documents/src/Indexes/SimpleFieldAttribute.cs delete mode 100644 sdk/search/Azure.Search.Documents/tests/FieldBuilderTests.cs delete mode 100644 sdk/search/Azure.Search.Documents/tests/SearchableFieldAttributeTests.cs delete mode 100644 sdk/search/Azure.Search.Documents/tests/SimpleFieldAttributeTests.cs diff --git a/sdk/search/Azure.Search.Documents/src/Indexes/FieldBuilder.cs b/sdk/search/Azure.Search.Documents/src/Indexes/FieldBuilder.cs deleted file mode 100644 index 2de44d09ee526..0000000000000 --- a/sdk/search/Azure.Search.Documents/src/Indexes/FieldBuilder.cs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using System.Text.Json.Serialization; -using Azure.Core; -using Azure.Search.Documents.Indexes.Models; - -namespace Azure.Search.Documents.Indexes -{ - /// - /// Builds a list of given a model type for use in a . - /// - /// - /// - public static class FieldBuilder - { - /// - /// Builds a list of given a model type for use in a . - /// By default, all public properties and fields of that model type will generate a ; - /// however, you can ignore them using or . - /// You can further customize the generated using the - /// and attributes. - /// - /// The type of model from which to build fields. - /// A list of from model type . - public static IList Build() => Build(typeof(T)); - - /// - /// Builds a list of given a model for use in a . - /// By default, all public properties and fields of that model type will generate a ; - /// however, you can ignore them using or . - /// You can further customize the generated using the - /// and attributes. - /// - /// The type of model from which to build fields. - /// A list of from model . - /// is null. - public static IList Build(Type type) - { - Argument.AssertNotNull(type, nameof(type)); - - throw new NotImplementedException(); - } - - // TODO: Add overloads taking a JsonNamingPolicy or whatever on which we standardize later. - } -} diff --git a/sdk/search/Azure.Search.Documents/src/Indexes/ISearchFieldAttribute.cs b/sdk/search/Azure.Search.Documents/src/Indexes/ISearchFieldAttribute.cs deleted file mode 100644 index 158bc54882b56..0000000000000 --- a/sdk/search/Azure.Search.Documents/src/Indexes/ISearchFieldAttribute.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Azure.Search.Documents.Indexes.Models; - -namespace Azure.Search.Documents.Indexes -{ - /// - /// Represents an attribute that creates a . - /// - internal interface ISearchFieldAttribute - { - /// - /// Creates a from the implementing attribute. - /// - /// The name of the attributed field or property. - /// A created from the implementing attribute. - SearchField CreateField(string name); - } -} diff --git a/sdk/search/Azure.Search.Documents/src/Indexes/SearchableFieldAttribute.cs b/sdk/search/Azure.Search.Documents/src/Indexes/SearchableFieldAttribute.cs deleted file mode 100644 index 3c1a1dcfb1ef4..0000000000000 --- a/sdk/search/Azure.Search.Documents/src/Indexes/SearchableFieldAttribute.cs +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Azure.Search.Documents.Indexes.Models; - -namespace Azure.Search.Documents.Indexes -{ - /// - /// Attributes a simple field using a primitive type or a collection of a primitive type. - /// - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] - public class SearchableFieldAttribute : SimpleFieldAttribute, ISearchFieldAttribute - { - /// - /// Gets the data type of the field. - /// - /// Whether the field is a collection of strings. - public SearchableFieldAttribute(bool collection = false) : base(SearchFieldDataType.String, collection) - { - } - - /// - /// Gets or sets the name of the language analyzer. This property cannot be set when either or are set. - /// Once the analyzer is chosen, it cannot be changed for the field in the index. - /// - /// String values from , or the name of a custom analyzer previously uploaded. - public string AnalyzerName { get; set; } - - /// - /// Gets or sets the name of the language analyzer for searching. This property must be set together with , and cannot be set when is set. - /// This property cannot be set to the name of a language analyzer; use the property instead if you need a language analyzer. - /// Once the analyzer is chosen, it cannot be changed for the field in the index. - /// - /// String values from , or the name of a custom analyzer previously uploaded. - public string SearchAnalyzerName { get; set; } - - /// - /// Gets or sets the name of the language analyzer for indexing. This property must be set together with , and cannot be set when is set. - /// This property cannot be set to the name of a language analyzer; use the property instead if you need a language analyzer. - /// Once the analyzer is chosen, it cannot be changed for the field in the index. - /// - /// String values from , or the name of a custom analyzer previously uploaded. - public string IndexAnalyzerName { get; set; } - - /// - /// Gets or sets a list of names of synonym maps to associate with this field. - /// Currently, only one synonym map per field is supported. - /// - /// - /// Assigning a synonym map to a field ensures that query terms targeting that field are expanded at query-time using the rules in the synonym map. - /// This attribute can be changed on existing fields. - /// - public string[] SynonymMapNames { get; set; } - - /// - SearchField ISearchFieldAttribute.CreateField(string name) - { - SearchableField field = new SearchableField(name, Type.IsCollection) - { - IsKey = IsKey, - IsHidden = IsHidden, - IsFilterable = IsFilterable, - IsFacetable = IsFacetable, - IsSortable = IsSortable, - SynonymMapNames = SynonymMapNames, - }; - - if (AnalyzerName != null) - { - field.AnalyzerName = AnalyzerName; - } - - if (SearchAnalyzerName != null) - { - field.SearchAnalyzerName = SearchAnalyzerName; - } - - if (IndexAnalyzerName != null) - { - field.IndexAnalyzerName = IndexAnalyzerName; - } - - return field; - } - } -} diff --git a/sdk/search/Azure.Search.Documents/src/Indexes/SimpleFieldAttribute.cs b/sdk/search/Azure.Search.Documents/src/Indexes/SimpleFieldAttribute.cs deleted file mode 100644 index e16da8415d29c..0000000000000 --- a/sdk/search/Azure.Search.Documents/src/Indexes/SimpleFieldAttribute.cs +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Azure.Search.Documents.Indexes.Models; - -namespace Azure.Search.Documents.Indexes -{ - /// - /// Attributes a simple field using a primitive type or a collection of a primitive type. - /// - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] - public class SimpleFieldAttribute : Attribute, ISearchFieldAttribute - { - /// - /// Gets the data type of the field. - /// - /// The field data type. - /// Whether the field is a collection of . - public SimpleFieldAttribute(SearchFieldDataType type, bool collection = false) - { - Type = collection ? SearchFieldDataType.Collection(type) : type; - } - - /// - /// Gets the field data type. - /// - public SearchFieldDataType Type { get; } - - /// - /// Gets or sets whether the field is the key field. The default is false. - /// A must have exactly one key field of type . - /// - public bool IsKey { get; set; } - - /// - /// Gets or sets whether the field is returned in search results. The default is false. - /// A key field where is true must have this property set to false. - /// - public bool IsHidden { get; set; } - - /// - /// Gets or sets a value indicating whether the field can be referenced in $filter queries. The default is false. - /// - /// - /// Filterable differs from searchable in how strings are handled. Fields of type or "Collection(DataType.String)" that are filterable do not undergo word-breaking, so comparisons are for exact matches only. - /// For example, if you set such a field f to "sunny day", $filter=f eq 'sunny' will find no matches, but $filter=f eq 'sunny day' will. - /// - public bool IsFilterable { get; set; } - - /// - /// Gets or sets a value indicating whether the field can be retrieved in facet queries. The default is false. - /// - /// - /// Facets are used in presentation of search results that include hit counts by categories. - /// For example, in a search for digital cameras, facets might include branch, megapixels, price, etc. - /// - public bool IsFacetable { get; set; } - - /// - /// Gets or sets a value indicating whether to enable the field can be referenced in $orderby expressions. The default is false. - /// - /// - /// By default Azure Cognitive Search sorts results by score, but in many experiences users may want to sort by fields in the documents. - /// - public bool IsSortable { get; set; } - - /// - SearchField ISearchFieldAttribute.CreateField(string name) => new SimpleField(name, Type) - { - IsKey = IsKey, - IsHidden = IsHidden, - IsFilterable = IsFilterable, - IsFacetable = IsFacetable, - IsSortable = IsSortable, - }; - } -} diff --git a/sdk/search/Azure.Search.Documents/tests/FieldBuilderTests.cs b/sdk/search/Azure.Search.Documents/tests/FieldBuilderTests.cs deleted file mode 100644 index 75412c3e276a8..0000000000000 --- a/sdk/search/Azure.Search.Documents/tests/FieldBuilderTests.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using Azure.Search.Documents.Indexes; -using NUnit.Framework; - -namespace Azure.Search.Documents.Tests -{ - public class FieldBuilderTests - { - [Test] - public void BuildThrowsTypeNull() - { - ArgumentNullException ex = Assert.Throws(() => FieldBuilder.Build(null)); - Assert.AreEqual("type", ex.ParamName); - } - - // TODO: Add more tests when FieldBuilder is implemented thoroughly. - } -} diff --git a/sdk/search/Azure.Search.Documents/tests/SearchableFieldAttributeTests.cs b/sdk/search/Azure.Search.Documents/tests/SearchableFieldAttributeTests.cs deleted file mode 100644 index fa3987e97f975..0000000000000 --- a/sdk/search/Azure.Search.Documents/tests/SearchableFieldAttributeTests.cs +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System.Linq; -using Azure.Search.Documents.Indexes; -using Azure.Search.Documents.Indexes.Models; -using NUnit.Framework; - -namespace Azure.Search.Documents.Tests -{ - public class SearchableFieldAttributeTests - { - [Test] - public void CreatesEquivalentField( - [Values] bool collection, - [Values] bool key, - [Values] bool hidden, - [Values] bool filterable, - [Values] bool facetable, - [Values] bool sortable, - [Values(null, "AnalyzerName")] string analyzerName, - [Values(null, "SearchAnalyzerName")] string searchAnalyzerName, - [Values(null, "IndexAnalyzerName")] string indexAnalyzerName, - [Values(null, new[] { "synonynMapName" })] string[] synonymMapNames) - { - SearchableFieldAttribute sut = new SearchableFieldAttribute(collection) - { - IsKey = key, - IsHidden = hidden, - IsFilterable = filterable, - IsFacetable = facetable, - IsSortable = sortable, - }; - - if (analyzerName != null) - { - sut.AnalyzerName = analyzerName; - } - - if (searchAnalyzerName != null) - { - sut.SearchAnalyzerName = searchAnalyzerName; - } - - if (indexAnalyzerName != null) - { - sut.IndexAnalyzerName = indexAnalyzerName; - } - - if (synonymMapNames != null) - { - sut.SynonymMapNames = synonymMapNames; - } - - SearchFieldDataType actualType = collection ? SearchFieldDataType.Collection(SearchFieldDataType.String) : SearchFieldDataType.String; - Assert.AreEqual(actualType, sut.Type); - - SearchField field = ((ISearchFieldAttribute)sut).CreateField("test"); - Assert.AreEqual("test", field.Name); - Assert.AreEqual(actualType, field.Type); - Assert.AreEqual(key, field.IsKey); - Assert.AreEqual(hidden, field.IsHidden); - Assert.AreEqual(filterable, field.IsFilterable); - Assert.AreEqual(facetable, field.IsFacetable); - Assert.AreEqual(sortable, field.IsSortable); - Assert.AreEqual(analyzerName, field.AnalyzerName?.ToString()); - Assert.AreEqual(searchAnalyzerName, field.SearchAnalyzerName?.ToString()); - Assert.AreEqual(indexAnalyzerName, field.IndexAnalyzerName?.ToString()); - Assert.AreEqual(synonymMapNames ?? Enumerable.Empty(), field.SynonymMapNames); - } - } -} diff --git a/sdk/search/Azure.Search.Documents/tests/SimpleFieldAttributeTests.cs b/sdk/search/Azure.Search.Documents/tests/SimpleFieldAttributeTests.cs deleted file mode 100644 index f925f1de6b741..0000000000000 --- a/sdk/search/Azure.Search.Documents/tests/SimpleFieldAttributeTests.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Azure.Core.TestFramework; -using Azure.Search.Documents.Indexes; -using Azure.Search.Documents.Indexes.Models; -using NUnit.Framework; - -namespace Azure.Search.Documents.Tests -{ - public class SimpleFieldAttributeTests - { - [Test] - public void CreatesEquivalentField( - [EnumValues] SearchFieldDataType type, - [Values] bool collection, - [Values] bool key, - [Values] bool hidden, - [Values] bool filterable, - [Values] bool facetable, - [Values] bool sortable) - { - SimpleFieldAttribute sut = new SimpleFieldAttribute(type, collection) - { - IsKey = key, - IsHidden = hidden, - IsFilterable = filterable, - IsFacetable = facetable, - IsSortable = sortable, - }; - - SearchFieldDataType actualType = collection ? SearchFieldDataType.Collection(type) : type; - Assert.AreEqual(actualType, sut.Type); - - SearchField field = ((ISearchFieldAttribute)sut).CreateField("test"); - Assert.AreEqual("test", field.Name); - Assert.AreEqual(actualType, field.Type); - Assert.AreEqual(key, field.IsKey); - Assert.AreEqual(hidden, field.IsHidden); - Assert.AreEqual(filterable, field.IsFilterable); - Assert.AreEqual(facetable, field.IsFacetable); - Assert.AreEqual(sortable, field.IsSortable); - } - } -} From 126911b7d84329d2200fedf17aca387198cbae3f Mon Sep 17 00:00:00 2001 From: Heath Stewart Date: Wed, 3 Jun 2020 11:03:38 -0700 Subject: [PATCH 2/2] Update public APIs --- .../Azure.Search.Documents.netstandard2.0.cs | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/sdk/search/Azure.Search.Documents/api/Azure.Search.Documents.netstandard2.0.cs b/sdk/search/Azure.Search.Documents/api/Azure.Search.Documents.netstandard2.0.cs index 9d59f9e16d7fe..6fd9a6cb48f3b 100644 --- a/sdk/search/Azure.Search.Documents/api/Azure.Search.Documents.netstandard2.0.cs +++ b/sdk/search/Azure.Search.Documents/api/Azure.Search.Documents.netstandard2.0.cs @@ -102,20 +102,6 @@ public SuggestOptions() { } } namespace Azure.Search.Documents.Indexes { - public static partial class FieldBuilder - { - public static System.Collections.Generic.IList Build(System.Type type) { throw null; } - public static System.Collections.Generic.IList Build() { throw null; } - } - [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false, Inherited=true)] - public partial class SearchableFieldAttribute : Azure.Search.Documents.Indexes.SimpleFieldAttribute - { - public SearchableFieldAttribute(bool collection = false) : base (default(Azure.Search.Documents.Indexes.Models.SearchFieldDataType), default(bool)) { } - public string AnalyzerName { get { throw null; } set { } } - public string IndexAnalyzerName { get { throw null; } set { } } - public string SearchAnalyzerName { get { throw null; } set { } } - public string[] SynonymMapNames { get { throw null; } set { } } - } public partial class SearchIndexClient { protected SearchIndexClient() { } @@ -215,17 +201,6 @@ public SearchIndexerClient(System.Uri endpoint, Azure.AzureKeyCredential credent public virtual Azure.Response RunIndexer(string indexerName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task RunIndexerAsync(string indexerName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } - [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false, Inherited=true)] - public partial class SimpleFieldAttribute : System.Attribute - { - public SimpleFieldAttribute(Azure.Search.Documents.Indexes.Models.SearchFieldDataType type, bool collection = false) { } - public bool IsFacetable { get { throw null; } set { } } - public bool IsFilterable { get { throw null; } set { } } - public bool IsHidden { get { throw null; } set { } } - public bool IsKey { get { throw null; } set { } } - public bool IsSortable { get { throw null; } set { } } - public Azure.Search.Documents.Indexes.Models.SearchFieldDataType Type { get { throw null; } } - } } namespace Azure.Search.Documents.Indexes.Models {