Пример #1
0
        public static IndexField Create(string name, IndexFieldOptions options, IndexFieldOptions allFields)
        {
            var field = new IndexField
            {
                Name     = name,
                Analyzer = options.Analyzer ?? allFields?.Analyzer
            };

            if (options.Indexing.HasValue)
            {
                field.Indexing = options.Indexing.Value;
            }
            else if (string.IsNullOrWhiteSpace(field.Analyzer) == false)
            {
                field.Indexing = FieldIndexing.Search;
            }
            else if (allFields?.Indexing != null)
            {
                field.Indexing = allFields.Indexing.Value;
            }

            if (options.Storage.HasValue)
            {
                field.Storage = options.Storage.Value;
            }
            else if (allFields?.Storage != null)
            {
                field.Storage = allFields.Storage.Value;
            }

            if (options.TermVector.HasValue)
            {
                field.TermVector = options.TermVector.Value;
            }
            else if (allFields?.TermVector != null)
            {
                field.TermVector = allFields.TermVector.Value;
            }

            if (options.Suggestions.HasValue)
            {
                field.HasSuggestions = options.Suggestions.Value;
            }
            else if (allFields?.Suggestions != null)
            {
                field.HasSuggestions = allFields.Suggestions.Value;
            }

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

            return(field);
        }
Пример #2
0
 protected bool Equals(IndexField other)
 {
     return(string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase) &&
            string.Equals(Analyzer, other.Analyzer, StringComparison.OrdinalIgnoreCase) &&
            SortOption == other.SortOption &&
            Highlighted == other.Highlighted &&
            MapReduceOperation == other.MapReduceOperation &&
            Storage == other.Storage &&
            Indexing == other.Indexing &&
            TermVector == other.TermVector);
 }
Пример #3
0
        public static string FindMapReduceIndexName(string[] collections, IReadOnlyCollection <IndexField> fields,
                                                    IReadOnlyCollection <IndexField> groupBy)
        {
            if (groupBy == null)
            {
                throw new ArgumentNullException(nameof(groupBy));
            }

            var reducedByFields = string.Join("And", groupBy.Select(x => IndexField.ReplaceInvalidCharactersInFieldName(x.Name)).OrderBy(x => x));

            return($"{FindName(collections, fields)}ReducedBy{reducedByFields}");
        }
Пример #4
0
        public static IndexField Create(string name, IndexFieldOptions options, IndexFieldOptions allFields)
        {
            var field = new IndexField();

            field.Name     = name;
            field.Analyzer = options.Analyzer ?? allFields?.Analyzer;

            if (options.Indexing.HasValue)
            {
                field.Indexing = options.Indexing.Value;
            }
            else if (string.IsNullOrWhiteSpace(field.Analyzer) == false)
            {
                field.Indexing = FieldIndexing.Analyzed;
            }

            if (options.Sort.HasValue)
            {
                field.SortOption = options.Sort.Value;
            }
            else if (allFields?.Sort != null)
            {
                field.SortOption = allFields.Sort.Value;
            }

            if (options.Storage.HasValue)
            {
                field.Storage = options.Storage.Value;
            }
            else if (allFields?.Storage != null)
            {
                field.Storage = allFields.Storage.Value;
            }

            if (options.TermVector.HasValue)
            {
                field.TermVector = options.TermVector.Value;
            }
            else if (allFields?.TermVector != null)
            {
                field.TermVector = allFields.TermVector.Value;
            }

            // options.Suggestions // TODO [ppekrol]
            // options.Spatial // TODO [ppekrol]

            return(field);
        }
Пример #5
0
        private static string FindName(string[] collections, IReadOnlyCollection <IndexField> fields)
        {
            foreach (var collection in collections.Where(string.IsNullOrEmpty))
            {
                throw new ArgumentNullException(nameof(collection));
            }

            if (fields == null)
            {
                throw new ArgumentNullException(nameof(fields));
            }

            var joinedCollections = string.Join("And", collections.Select(x => x == Constants.Indexing.AllDocumentsCollection ? "AllDocs" : x));

            if (fields.Count == 0)
            {
                return($"Auto/{joinedCollections}");
            }

            var combinedFields = string.Join("And", fields.Select(x => IndexField.ReplaceInvalidCharactersInFieldName(x.Name)).OrderBy(x => x));

            var sortOptions = fields.Where(x => x.SortOption != null).Select(x => IndexField.ReplaceInvalidCharactersInFieldName(x.Name)).ToArray();

            if (sortOptions.Length > 0)
            {
                combinedFields = $"{combinedFields}SortBy{string.Join(string.Empty, sortOptions.OrderBy(x => x))}";
            }

            var highlighted = fields.Where(x => x.Highlighted).Select(x => IndexField.ReplaceInvalidCharactersInFieldName(x.Name)).ToArray();

            if (highlighted.Length > 0)
            {
                combinedFields = $"{combinedFields}Highlight{string.Join(string.Empty, highlighted.OrderBy(x => x))}";
            }

            string formattableString = $"Auto/{joinedCollections}/By{combinedFields}";

            if (formattableString.Length > 256)
            {
                var shorterString = formattableString.Substring(0, 256) + "..." +
                                    Hashing.XXHash64.Calculate(formattableString, Encoding.UTF8);
                return(shorterString);
            }
            return(formattableString);
        }
Пример #6
0
        protected static IndexField[] ReadMapFields(BlittableJsonReaderObject reader)
        {
            BlittableJsonReaderArray jsonArray;

            if (reader.TryGet(nameof(MapFields), out jsonArray) == false)
            {
                throw new InvalidOperationException("No persisted lock mode");
            }

            var fields = new IndexField[jsonArray.Length];

            for (var i = 0; i < jsonArray.Length; i++)
            {
                var json = jsonArray.GetByIndex <BlittableJsonReaderObject>(i);

                string name;
                json.TryGet(nameof(IndexField.Name), out name);

                bool highlighted;
                json.TryGet(nameof(IndexField.Highlighted), out highlighted);

                int sortOptionAsInt;
                json.TryGet(nameof(IndexField.SortOption), out sortOptionAsInt);

                var field = new IndexField
                {
                    Name        = name,
                    Highlighted = highlighted,
                    Storage     = FieldStorage.No,
                    SortOption  = (SortOptions?)sortOptionAsInt,
                    Indexing    = FieldIndexing.Default
                };

                fields[i] = field;
            }

            return(fields);
        }