private static void EnsureValidQuery(IndexQueryServerSide query, DynamicQueryMapping map)
 {
     foreach (var field in map.MapFields)
     {
         query.Query = query.Query.Replace(field.Name, IndexField.ReplaceInvalidCharactersInFieldName(field.Name));
     }
 }
Beispiel #2
0
        public LuceneIndexPersistence(Index index)
        {
            _index = index;

            var fields = index.Definition.MapFields.Values.ToList();

            switch (_index.Type)
            {
            case IndexType.AutoMap:
                _converter = new LuceneDocumentConverter(fields, reduceOutput: false);
                break;

            case IndexType.AutoMapReduce:
                var autoMapReduceIndexDefinition = (AutoMapReduceIndexDefinition)_index.Definition;
                fields.AddRange(autoMapReduceIndexDefinition.GroupByFields.Values);

                _converter = new LuceneDocumentConverter(fields, reduceOutput: true);
                break;

            case IndexType.MapReduce:
            case IndexType.Map:
                _converter = new AnonymousLuceneDocumentConverter(fields, reduceOutput: _index.Type.IsMapReduce());
                break;

            case IndexType.Faulty:
                _converter = null;
                break;

            default:
                throw new NotSupportedException(_index.Type.ToString());
            }

            _fields = fields.ToDictionary(x => IndexField.ReplaceInvalidCharactersInFieldName(x.Name), x => (object)null);
            _indexSearcherHolder = new IndexSearcherHolder(() => new IndexSearcher(_directory, true), _index._indexStorage.DocumentDatabase);
        }
Beispiel #3
0
        public bool ContainsField(string field)
        {
            if (field == Constants.Indexing.Fields.DocumentIdFieldName)
            {
                return(_index.Type.IsMap());
            }

            if (field.EndsWith(Constants.Indexing.Fields.RangeFieldSuffix))
            {
                field = field.Substring(0, field.Length - 6);
            }

            field = IndexField.ReplaceInvalidCharactersInFieldName(field);

            return(_fields.ContainsKey(field));
        }
Beispiel #4
0
        private static Sort GetSort(SortedField[] sortedFields)
        {
            if (sortedFields == null || sortedFields.Length == 0)
            {
                return(null);
            }

            return(new Sort(sortedFields.Select(x =>
            {
                var sortOptions = SortOptions.String;

                if (x.Field == Constants.Indexing.Fields.IndexFieldScoreName)
                {
                    return SortField.FIELD_SCORE;
                }

                if (InvariantCompare.IsPrefix(x.Field, Constants.Indexing.Fields.AlphaNumericFieldName, CompareOptions.None))
                {
                    var customFieldName = SortFieldHelper.ExtractName(x.Field);
                    if (customFieldName.IsNullOrWhiteSpace())
                    {
                        throw new InvalidOperationException("Alphanumeric sort: cannot figure out what field to sort on!");
                    }

                    var anSort = new AlphaNumericComparatorSource();
                    return new SortField(customFieldName, anSort, x.Descending);
                }

                if (InvariantCompare.IsPrefix(x.Field, Constants.Indexing.Fields.RandomFieldName, CompareOptions.None))
                {
                    var customFieldName = SortFieldHelper.ExtractName(x.Field);
                    if (customFieldName.IsNullOrWhiteSpace()) // truly random
                    {
                        return new RandomSortField(Guid.NewGuid().ToString());
                    }

                    return new RandomSortField(customFieldName);
                }

                if (InvariantCompare.IsSuffix(x.Field, Constants.Indexing.Fields.RangeFieldSuffix, CompareOptions.None))
                {
                    sortOptions = SortOptions.NumericDouble; // TODO arek - it seems to be working fine with long values as well however needs to be verified
                }

                return new SortField(IndexField.ReplaceInvalidCharactersInFieldName(x.Field), (int)sortOptions, x.Descending);
            }).ToArray()));
        }
        private string CreateFieldName(string name)
        {
            var result = IndexField.ReplaceInvalidCharactersInFieldName(name);

            return(result);
        }