Exemple #1
0
        // 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;
        }
        // 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;

            Fields          = new List <SearchField>();
            SynonymMapNames = new List <string>();
        }
Exemple #4
0
 internal SearchField(string name, SearchFieldDataType type, bool?isKey, bool?isRetrievable, bool?isSearchable, bool?isFilterable, bool?isSortable, bool?isFacetable, LexicalAnalyzerName?analyzerName, LexicalAnalyzerName?searchAnalyzerName, LexicalAnalyzerName?indexAnalyzerName, IList <string> synonymMapNames, IList <SearchField> fields)
 {
     Name               = name;
     Type               = type;
     IsKey              = isKey;
     IsRetrievable      = isRetrievable;
     IsSearchable       = isSearchable;
     IsFilterable       = isFilterable;
     IsSortable         = isSortable;
     IsFacetable        = isFacetable;
     AnalyzerName       = analyzerName;
     SearchAnalyzerName = searchAnalyzerName;
     IndexAnalyzerName  = indexAnalyzerName;
     SynonymMapNames    = synonymMapNames ?? new List <string>();
     Fields             = fields ?? new List <SearchField>();
 }
 /// <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;
            Optional <bool>                 key            = default;
            Optional <bool>                 retrievable    = default;
            Optional <bool>                 searchable     = default;
            Optional <bool>                 filterable     = default;
            Optional <bool>                 sortable       = default;
            Optional <bool>                 facetable      = default;
            Optional <LexicalAnalyzerName?> analyzer       = default;
            Optional <LexicalAnalyzerName?> searchAnalyzer = default;
            Optional <LexicalAnalyzerName?> indexAnalyzer  = default;
            Optional <IList <string> >      synonymMaps    = default;
            Optional <IList <SearchField> > fields         = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("name"))
                {
                    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)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    key = property.Value.GetBoolean();
                    continue;
                }
                if (property.NameEquals("retrievable"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    retrievable = property.Value.GetBoolean();
                    continue;
                }
                if (property.NameEquals("searchable"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    searchable = property.Value.GetBoolean();
                    continue;
                }
                if (property.NameEquals("filterable"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    filterable = property.Value.GetBoolean();
                    continue;
                }
                if (property.NameEquals("sortable"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    sortable = property.Value.GetBoolean();
                    continue;
                }
                if (property.NameEquals("facetable"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    facetable = property.Value.GetBoolean();
                    continue;
                }
                if (property.NameEquals("analyzer"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        analyzer = null;
                        continue;
                    }
                    analyzer = new LexicalAnalyzerName(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("searchAnalyzer"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        searchAnalyzer = null;
                        continue;
                    }
                    searchAnalyzer = new LexicalAnalyzerName(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("indexAnalyzer"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        indexAnalyzer = null;
                        continue;
                    }
                    indexAnalyzer = new LexicalAnalyzerName(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("synonymMaps"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <string> array = new List <string>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(item.GetString());
                    }
                    synonymMaps = array;
                    continue;
                }
                if (property.NameEquals("fields"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <SearchField> array = new List <SearchField>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DeserializeSearchField(item));
                    }
                    fields = array;
                    continue;
                }
            }
            return(new SearchField(name, type, Optional.ToNullable(key), Optional.ToNullable(retrievable), Optional.ToNullable(searchable), Optional.ToNullable(filterable), Optional.ToNullable(sortable), Optional.ToNullable(facetable), Optional.ToNullable(analyzer), Optional.ToNullable(searchAnalyzer), Optional.ToNullable(indexAnalyzer), Optional.ToList(synonymMaps), Optional.ToList(fields)));
        }
Exemple #7
0
 /// <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, ")"));
        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"))
                {
                    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>
 /// 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)
 {
 }
 /// <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="ComplexField"/> 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>
 /// <remarks>
 /// This is used internally by FieldBuilder to avoid detecting if the type is a collection just
 /// to return the same type we started with.
 /// </remarks>
 internal ComplexField(string name, SearchFieldDataType type) : base(name, type)
 {
 }