// TODO: Replace constructor and read-only properties when https://github.com/Azure/autorest.csharp/issues/554 is fixed. /// <summary> /// Initializes a new instance of the <see cref="SearchField"/> class. /// </summary> /// <param name="name">The name of the field, which must be unique within the index or parent field.</param> /// <param name="type">The data type of the field.</param> /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> public SearchField(string name, SearchFieldDataType type) { Argument.AssertNotNullOrEmpty(name, nameof(name)); Name = name; Type = type; }
/// <summary> /// Initializes a new instance of the <see cref="SearchFieldTemplate"/> class. /// </summary> /// <param name="name">The name of the field, which must be unique within the index or parent field.</param> /// <param name="type">The data type of the field.</param> /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> private protected SearchFieldTemplate(string name, SearchFieldDataType type) { Argument.AssertNotNullOrEmpty(name, nameof(name)); Name = name; Type = type; }
internal SearchField(string name, SearchFieldDataType type, bool?isKey, bool?isRetrievable, bool?isSearchable, bool?isFilterable, bool?isSortable, bool?isFacetable, LexicalAnalyzerName?analyzer, LexicalAnalyzerName?searchAnalyzer, LexicalAnalyzerName?indexAnalyzer, IList <string> synonymMaps, IList <SearchField> fields) { Name = name; Type = type; IsKey = isKey; IsRetrievable = isRetrievable; IsSearchable = isSearchable; IsFilterable = isFilterable; IsSortable = isSortable; IsFacetable = isFacetable; Analyzer = analyzer; SearchAnalyzer = searchAnalyzer; IndexAnalyzer = indexAnalyzer; SynonymMaps = synonymMaps; Fields = fields; }
/// <summary> /// Initializes a new instance of the <see cref="ComplexField"/> class. /// </summary> /// <param name="name">The name of the field, which must be unique within the index or parent field.</param> /// <param name="collection">Whether the field is a collection of strings.</param> /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> public ComplexField(string name, bool collection = false) : base(name, collection ? SearchFieldDataType.Collection(SearchFieldDataType.Complex) : SearchFieldDataType.Complex) { }
internal static SearchField DeserializeSearchField(JsonElement element) { string name = default; SearchFieldDataType type = default; bool?key = default; bool?retrievable = default; bool?searchable = default; bool?filterable = default; bool?sortable = default; bool?facetable = default; LexicalAnalyzerName?analyzer = default; LexicalAnalyzerName?searchAnalyzer = default; LexicalAnalyzerName?indexAnalyzer = default; IList <string> synonymMaps = default; IList <SearchField> fields = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("name")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = new SearchFieldDataType(property.Value.GetString()); continue; } if (property.NameEquals("key")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } key = property.Value.GetBoolean(); continue; } if (property.NameEquals("retrievable")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } retrievable = property.Value.GetBoolean(); continue; } if (property.NameEquals("searchable")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } searchable = property.Value.GetBoolean(); continue; } if (property.NameEquals("filterable")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } filterable = property.Value.GetBoolean(); continue; } if (property.NameEquals("sortable")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } sortable = property.Value.GetBoolean(); continue; } if (property.NameEquals("facetable")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } facetable = property.Value.GetBoolean(); continue; } if (property.NameEquals("analyzer")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } analyzer = new LexicalAnalyzerName(property.Value.GetString()); continue; } if (property.NameEquals("searchAnalyzer")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } searchAnalyzer = new LexicalAnalyzerName(property.Value.GetString()); continue; } if (property.NameEquals("indexAnalyzer")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } indexAnalyzer = new LexicalAnalyzerName(property.Value.GetString()); continue; } if (property.NameEquals("synonymMaps")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } List <string> array = new List <string>(); foreach (var item in property.Value.EnumerateArray()) { if (item.ValueKind == JsonValueKind.Null) { array.Add(null); } else { array.Add(item.GetString()); } } synonymMaps = array; continue; } if (property.NameEquals("fields")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } List <SearchField> array = new List <SearchField>(); foreach (var item in property.Value.EnumerateArray()) { if (item.ValueKind == JsonValueKind.Null) { array.Add(null); } else { array.Add(DeserializeSearchField(item)); } } fields = array; continue; } } return(new SearchField(name, type, key, retrievable, searchable, filterable, sortable, facetable, analyzer, searchAnalyzer, indexAnalyzer, synonymMaps, fields)); }
/// <summary> /// Gets a <see cref="SearchFieldDataType"/> representing a collection of <paramref name="type"/>. /// </summary> /// <param name="type">The type of collection.</param> /// <returns>A <see cref="SearchFieldDataType"/> representing a collection of <paramref name="type"/>.</returns> public static SearchFieldDataType Collection(SearchFieldDataType type) => type.IsCollection ? type : new SearchFieldDataType(string.Concat(CollectionPrefix, type._value, ")"));
/// <summary> /// Initializes a new instance of the <see cref="SearchableField"/> class. /// </summary> /// <param name="name">The name of the field, which must be unique within the index or parent field.</param> /// <param name="collection">Whether the field is a collection of strings.</param> /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> 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. }
/// <summary> /// Initializes a new instance of the <see cref="SimpleField"/> class. /// </summary> /// <param name="name">The name of the field, which must be unique within the index or parent field.</param> /// <param name="type">The data type of the field.</param> /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> public SimpleField(string name, SearchFieldDataType type) : base(name, type) { }