Skip to content

Commit

Permalink
Define public APIs for FieldBuilder
Browse files Browse the repository at this point in the history
Define the public APIs for Azure#11166
  • Loading branch information
heaths committed May 27, 2020
1 parent 2b99025 commit fdc0528
Show file tree
Hide file tree
Showing 20 changed files with 496 additions and 36 deletions.
1 change: 1 addition & 0 deletions sdk/search/Azure.Search.Documents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ Let's start by importing our namespaces.
```C# Snippet:Azure_Search_Tests_Samples_Readme_Namespace
using Azure;
using Azure.Search.Documents;
using Azure.Search.Documents.Indexes;
```

We'll then create a `SearchClient` to access our hotels search index.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,59 @@ public static partial class SearchFilter
public static string Create(System.FormattableString filter) { throw null; }
public static string Create(System.FormattableString filter, System.IFormatProvider formatProvider) { throw null; }
}
public partial class SearchOptions
{
public SearchOptions() { }
public SearchOptions(string continuationToken) { }
public System.Collections.Generic.IList<string> Facets { get { throw null; } }
public string Filter { get { throw null; } set { } }
public System.Collections.Generic.IList<string> HighlightFields { get { throw null; } }
public string HighlightPostTag { get { throw null; } set { } }
public string HighlightPreTag { get { throw null; } set { } }
public bool? IncludeTotalCount { get { throw null; } set { } }
public double? MinimumCoverage { get { throw null; } set { } }
public System.Collections.Generic.IList<string> OrderBy { get { throw null; } }
public Azure.Search.Documents.Models.SearchQueryType? QueryType { get { throw null; } set { } }
public System.Collections.Generic.IList<string> ScoringParameters { get { throw null; } }
public string ScoringProfile { get { throw null; } set { } }
public System.Collections.Generic.IList<string> SearchFields { get { throw null; } }
public Azure.Search.Documents.Models.SearchMode? SearchMode { get { throw null; } set { } }
public System.Collections.Generic.IList<string> Select { get { throw null; } }
public int? Size { get { throw null; } set { } }
public int? Skip { get { throw null; } set { } }
}
public partial class SuggestOptions
{
public SuggestOptions() { }
public string Filter { get { throw null; } set { } }
public string HighlightPostTag { get { throw null; } set { } }
public string HighlightPreTag { get { throw null; } set { } }
public double? MinimumCoverage { get { throw null; } set { } }
public System.Collections.Generic.IList<string> OrderBy { get { throw null; } }
public System.Collections.Generic.IList<string> SearchFields { get { throw null; } }
public System.Collections.Generic.IList<string> Select { get { throw null; } }
public int? Size { get { throw null; } set { } }
public bool? UseFuzzyMatching { get { throw null; } set { } }
}
}
namespace Azure.Search.Documents.Indexes
{
public static partial class FieldBuilder
{
public static System.Collections.Generic.IList<Azure.Search.Documents.Indexes.Models.SearchField> Build(System.Type type) { throw null; }
public static System.Collections.Generic.IList<Azure.Search.Documents.Indexes.Models.SearchField> Build(System.Type type, System.Text.Json.JsonNamingPolicy namingPolicy) { throw null; }
public static System.Collections.Generic.IList<Azure.Search.Documents.Indexes.Models.SearchField> Build<T>() { throw null; }
public static System.Collections.Generic.IList<Azure.Search.Documents.Indexes.Models.SearchField> Build<T>(System.Text.Json.JsonNamingPolicy namingPolicy) { 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 Azure.Search.Documents.Indexes.Models.LexicalAnalyzerName? AnalyzerName { get { throw null; } set { } }
public Azure.Search.Documents.Indexes.Models.LexicalAnalyzerName? IndexAnalyzerName { get { throw null; } set { } }
public Azure.Search.Documents.Indexes.Models.LexicalAnalyzerName? SearchAnalyzerName { get { throw null; } set { } }
public string[] SynonymMapNames { get { throw null; } set { } }
}
public partial class SearchIndexClient
{
protected SearchIndexClient() { }
Expand Down Expand Up @@ -164,39 +217,16 @@ 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<Azure.Response> RunIndexerAsync(string indexerName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
}
public partial class SearchOptions
{
public SearchOptions() { }
public SearchOptions(string continuationToken) { }
public System.Collections.Generic.IList<string> Facets { get { throw null; } }
public string Filter { get { throw null; } set { } }
public System.Collections.Generic.IList<string> HighlightFields { get { throw null; } }
public string HighlightPostTag { get { throw null; } set { } }
public string HighlightPreTag { get { throw null; } set { } }
public bool? IncludeTotalCount { get { throw null; } set { } }
public double? MinimumCoverage { get { throw null; } set { } }
public System.Collections.Generic.IList<string> OrderBy { get { throw null; } }
public Azure.Search.Documents.Models.SearchQueryType? QueryType { get { throw null; } set { } }
public System.Collections.Generic.IList<string> ScoringParameters { get { throw null; } }
public string ScoringProfile { get { throw null; } set { } }
public System.Collections.Generic.IList<string> SearchFields { get { throw null; } }
public Azure.Search.Documents.Models.SearchMode? SearchMode { get { throw null; } set { } }
public System.Collections.Generic.IList<string> Select { get { throw null; } }
public int? Size { get { throw null; } set { } }
public int? Skip { get { throw null; } set { } }
}
public partial class SuggestOptions
[System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false, Inherited=true)]
public partial class SimpleFieldAttribute : System.Attribute
{
public SuggestOptions() { }
public string Filter { get { throw null; } set { } }
public string HighlightPostTag { get { throw null; } set { } }
public string HighlightPreTag { get { throw null; } set { } }
public double? MinimumCoverage { get { throw null; } set { } }
public System.Collections.Generic.IList<string> OrderBy { get { throw null; } }
public System.Collections.Generic.IList<string> SearchFields { get { throw null; } }
public System.Collections.Generic.IList<string> Select { get { throw null; } }
public int? Size { get { throw null; } set { } }
public bool? UseFuzzyMatching { get { throw null; } set { } }
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Import the namespaces
```C# Snippet:Azure_Search_Tests_Samples_Namespaces
using Azure.Search.Documents;
using Azure.Search.Documents.Indexes;
using Azure.Search.Documents.Indexes.Models;
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Import the namespaces
```C# Snippet:Azure_Search_Tests_Samples_Namespaces
using Azure.Search.Documents;
using Azure.Search.Documents.Indexes;
using Azure.Search.Documents.Indexes.Models;
```

Expand Down
91 changes: 91 additions & 0 deletions sdk/search/Azure.Search.Documents/src/Indexes/FieldBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using Azure.Core;
using Azure.Search.Documents.Indexes.Models;

namespace Azure.Search.Documents.Indexes
{
/// <summary>
/// Builds a list of <see cref="SearchField"/> given a model type for use in a <see cref="SearchIndex"/>.
/// <seealso cref="SimpleFieldAttribute"/>
/// <seealso cref="SearchableFieldAttribute"/>
/// </summary>
public static class FieldBuilder
{
private static readonly DefaultNamingPolicy s_defaultNamingPolicy = new DefaultNamingPolicy();

/// <summary>
/// Builds a list of <see cref="SearchField"/> given a model type <typeparamref name="T"/> for use in a <see cref="SearchIndex"/>.
/// By default, all public properties and fields of that model type will generate a <see cref="SearchField"/>;
/// however, you can ignore them using <see cref="JsonIgnoreAttribute"/> or <see cref="NonSerializedAttribute"/>.
/// You can further customize the generated <see cref="SearchField"/> using the
/// <see cref="SimpleFieldAttribute"/> and <see cref="SearchableFieldAttribute"/> attributes.
/// </summary>
/// <typeparam name="T">The type of model from which to build fields.</typeparam>
/// <returns>A list of <see cref="SearchField"/> from model type <typeparamref name="T"/>.</returns>
public static IList<SearchField> Build<T>() => Build(typeof(T), s_defaultNamingPolicy);

/// <summary>
/// Builds a list of <see cref="SearchField"/> given a model type <typeparamref name="T"/> for use in a <see cref="SearchIndex"/>.
/// By default, all public properties and fields of that model type will generate a <see cref="SearchField"/>;
/// however, you can ignore them using <see cref="JsonIgnoreAttribute"/> or <see cref="NonSerializedAttribute"/>.
/// You can further customize the generated <see cref="SearchField"/> using the
/// <see cref="SimpleFieldAttribute"/> and <see cref="SearchableFieldAttribute"/> attributes.
/// </summary>
/// <typeparam name="T">The type of model from which to build fields.</typeparam>
/// <param name="namingPolicy">
/// The <see cref="JsonNamingPolicy"/> to use for converting property names if not already attributed with <see cref="JsonPropertyNameAttribute"/>.
/// </param>
/// <returns>A list of <see cref="SearchField"/> from model type <typeparamref name="T"/>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="namingPolicy"/> is null.</exception>
public static IList<SearchField> Build<T>(JsonNamingPolicy namingPolicy) => Build(typeof(T), namingPolicy);

/// <summary>
/// Builds a list of <see cref="SearchField"/> given a model <paramref name="type"/> for use in a <see cref="SearchIndex"/>.
/// By default, all public properties and fields of that model type will generate a <see cref="SearchField"/>;
/// however, you can ignore them using <see cref="JsonIgnoreAttribute"/> or <see cref="NonSerializedAttribute"/>.
/// You can further customize the generated <see cref="SearchField"/> using the
/// <see cref="SimpleFieldAttribute"/> and <see cref="SearchableFieldAttribute"/> attributes.
/// </summary>
/// <param name="type">The type of model from which to build fields.</param>
/// <returns>A list of <see cref="SearchField"/> from model <paramref name="type"/>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="type"/> is null.</exception>
public static IList<SearchField> Build(Type type) => Build(type, s_defaultNamingPolicy);

/// <summary>
/// Builds a list of <see cref="SearchField"/> given a model <paramref name="type"/> for use in a <see cref="SearchIndex"/>.
/// By default, all public properties and fields of that model type will generate a <see cref="SearchField"/>;
/// however, you can ignore them using <see cref="JsonIgnoreAttribute"/> or <see cref="NonSerializedAttribute"/>.
/// You can further customize the generated <see cref="SearchField"/> using the
/// <see cref="SimpleFieldAttribute"/> and <see cref="SearchableFieldAttribute"/> attributes.
/// </summary>
/// <param name="type">The type of model from which to build fields.</param>
/// <param name="namingPolicy">
/// The <see cref="JsonNamingPolicy"/> to use for converting property names if not already attributed with <see cref="JsonPropertyNameAttribute"/>.
/// </param>
/// <returns>A list of <see cref="SearchField"/> from model <paramref name="type"/>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="type"/> or <paramref name="namingPolicy"/> is null.</exception>
public static IList<SearchField> Build(Type type, JsonNamingPolicy namingPolicy)
{
Argument.AssertNotNull(type, nameof(type));
Argument.AssertNotNull(namingPolicy, nameof(namingPolicy));

throw new NotImplementedException();
}

private class DefaultNamingPolicy : JsonNamingPolicy
{
/// <summary>
/// Returns the <paramref name="name"/> as is.
/// </summary>
/// <param name="name">The property name to convert.</param>
/// <returns>The <paramref name="name"/> as is.</returns>
public override string ConvertName(string name) => name;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.Search.Documents.Indexes.Models;

namespace Azure.Search.Documents.Indexes
{
/// <summary>
/// Represents an attribute that creates a <see cref="SearchField"/>.
/// </summary>
internal interface ISearchFieldAttribute
{
/// <summary>
/// Creates a <see cref="SearchField"/> from the implementing attribute.
/// </summary>
/// <param name="name">The name of the attributed field or property.</param>
/// <returns>A <see cref="SearchField"/> created from the implementing attribute.</returns>
SearchField CreateField(string name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace Azure.Search.Documents.Indexes.Models
/// </summary>
public class SearchableField : SimpleField
{
private readonly List<string> _synonymMapNames;

/// <summary>
/// Initializes a new instance of the <see cref="SearchableField"/> class.
/// </summary>
Expand All @@ -21,6 +23,7 @@ public class SearchableField : SimpleField
public SearchableField(string name, bool collection = false) : base(name, collection ? SearchFieldDataType.Collection(SearchFieldDataType.String) : SearchFieldDataType.String)
{
// NOTE: Types other than string may be searchable one day. Could add an overload in the future.
_synonymMapNames = new List<string>();
}

/// <summary>
Expand Down Expand Up @@ -51,7 +54,19 @@ public SearchableField(string name, bool collection = false) : base(name, collec
/// 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.
/// </remarks>
public IList<string> SynonymMapNames { get; } = new List<string>();
public IList<string> SynonymMapNames
{
get => _synonymMapNames;
internal set
{
_synonymMapNames.Clear();

if (value != null)
{
_synonymMapNames.AddRange(value);
}
}
}

/// <inheritdoc/>
private protected override void Save(SearchField field)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Azure.Core.Pipeline;
using Azure.Search.Documents.Indexes.Models;

namespace Azure.Search.Documents
namespace Azure.Search.Documents.Indexes
{
/// <summary>
/// Azure Cognitive Search client that can be used to manage indexes on a Search service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using System.Linq;
using Azure.Search.Documents.Indexes.Models;

namespace Azure.Search.Documents
namespace Azure.Search.Documents.Indexes
{
/// <summary>
/// Azure Cognitive Search client that can be used to manage and query
Expand Down
Loading

0 comments on commit fdc0528

Please sign in to comment.