Example #1
0
        public static AutoIndexField Create(string name, AutoIndexDefinition.AutoIndexFieldOptions options)
        {
            var field = new AutoIndexField
            {
                Name          = name,
                HasQuotedName = options.IsNameQuoted
            };

            if (options.Indexing.HasValue)
            {
                field.Indexing = options.Indexing.Value;
            }

            if (options.Storage.HasValue)
            {
                field.Storage = options.Storage.Value;
            }

            if (options.Spatial != null)
            {
                field.Spatial = new AutoSpatialOptions(options.Spatial);
            }

            if (options.Suggestions.HasValue)
            {
                field.HasSuggestions = options.Suggestions.Value;
            }

            field.Aggregation          = options.Aggregation;
            field.GroupByArrayBehavior = options.GroupByArrayBehavior;

            return(field);
        }
Example #2
0
 protected bool Equals(AutoIndexField other)
 {
     return(string.Equals(Name, other.Name, StringComparison.Ordinal) &&
            Storage == other.Storage &&
            Indexing == other.Indexing &&
            Aggregation == other.Aggregation);
 }
Example #3
0
        public static AutoIndexField Create(string name, AutoIndexDefinition.AutoIndexFieldOptions options)
        {
            var field = new AutoIndexField
            {
                Name          = name,
                HasQuotedName = options.IsNameQuoted
            };

            if (options.Indexing.HasValue)
            {
                field.Indexing = options.Indexing.Value;
            }

            if (options.Storage.HasValue)
            {
                field.Storage = options.Storage.Value;
            }

            if (options.Spatial != null)
            {
                field.Spatial = new AutoSpatialOptions(options.Spatial);
            }

            return(field);
        }
Example #4
0
        private static string GetName(AutoIndexField x)
        {
            var name = x.Name;

            if (x.HasQuotedName)
            {
                name = $"'{name}'";
            }

            if (x.GroupByArrayBehavior == GroupByArrayBehavior.ByContent)
            {
                name = AutoIndexField.GetGroupByArrayContentAutoIndexFieldName(name).ToUpperFirstLetter();
            }

            if (x.Indexing == AutoFieldIndexing.Default || x.Indexing == AutoFieldIndexing.No)
            {
                if (x.Spatial != null)
                {
                    return(name
                           .Replace(",", "|")
                           .Replace(" ", string.Empty)
                           .ToUpperFirstLetter());
                }

                if (x.HasSuggestions)
                {
                    return(AutoIndexField.GetSuggestionsAutoIndexFieldName(name).ToUpperFirstLetter());
                }

                return(name);
            }

            var functions = new List <string>();

            if (x.Indexing.HasFlag(AutoFieldIndexing.Search))
            {
                functions.Add(AutoIndexField.GetSearchAutoIndexFieldName(name).ToUpperFirstLetter());
            }

            if (x.Indexing.HasFlag(AutoFieldIndexing.Highlighting))
            {
                functions.Add(AutoIndexField.GetHighlightingAutoIndexFieldName(name).ToUpperFirstLetter());
            }

            if (x.Indexing.HasFlag(AutoFieldIndexing.Exact))
            {
                functions.Add(AutoIndexField.GetExactAutoIndexFieldName(name).ToUpperFirstLetter());
            }

            if (x.HasSuggestions)
            {
                functions.Add(AutoIndexField.GetSuggestionsAutoIndexFieldName(name).ToUpperFirstLetter());
            }

            return(string.Join("And", functions));
        }
Example #5
0
        public static AutoIndexField Create(string name, AutoIndexDefinition.AutoIndexFieldOptions options)
        {
            var field = new AutoIndexField
            {
                Name = name
            };

            if (options.Indexing.HasValue)
            {
                field.Indexing = options.Indexing.Value;
            }

            if (options.Storage.HasValue)
            {
                field.Storage = options.Storage.Value;
            }

            return(field);
        }
Example #6
0
        private static string GetName(AutoIndexField x)
        {
            if (x.Indexing == AutoFieldIndexing.Default || x.Indexing == AutoFieldIndexing.No)
            {
                return(x.Name);
            }

            var functions = new List <string>();

            if (x.Indexing.HasFlag(AutoFieldIndexing.Search))
            {
                functions.Add(AutoIndexField.GetSearchAutoIndexFieldName(x.Name).ToUpperFirstLetter());
            }

            if (x.Indexing.HasFlag(AutoFieldIndexing.Exact))
            {
                functions.Add(AutoIndexField.GetExactAutoIndexFieldName(x.Name).ToUpperFirstLetter());
            }

            return(string.Join("And", functions));
        }
Example #7
0
        private static AutoIndexDefinitionBase CreateAutoDefinition(AutoIndexDefinition definition)
        {
            var mapFields = definition
                            .MapFields
                            .Select(x =>
            {
                var field         = AutoIndexField.Create(x.Key, x.Value);
                field.Aggregation = x.Value.Aggregation;

                Debug.Assert(x.Value.GroupByArrayBehavior == GroupByArrayBehavior.NotApplicable);

                return(field);
            })
                            .ToArray();

            if (definition.Type == IndexType.AutoMap)
            {
                var result = new AutoMapIndexDefinition(definition.Collection, mapFields);

                if (definition.LockMode.HasValue)
                {
                    result.LockMode = definition.LockMode.Value;
                }

                if (definition.Priority.HasValue)
                {
                    result.Priority = definition.Priority.Value;
                }

                return(result);
            }

            if (definition.Type == IndexType.AutoMapReduce)
            {
                var groupByFields = definition
                                    .GroupByFields
                                    .Select(x =>
                {
                    var field                  = AutoIndexField.Create(x.Key, x.Value);
                    field.Aggregation          = x.Value.Aggregation;
                    field.GroupByArrayBehavior = x.Value.GroupByArrayBehavior;

                    return(field);
                })
                                    .ToArray();

                var result = new AutoMapReduceIndexDefinition(definition.Collection, mapFields, groupByFields);
                if (definition.LockMode.HasValue)
                {
                    result.LockMode = definition.LockMode.Value;
                }

                if (definition.Priority.HasValue)
                {
                    result.Priority = definition.Priority.Value;
                }

                return(result);
            }

            throw new NotSupportedException("Cannot create auto-index from " + definition.Type);
        }