Exemple #1
0
        private static InMemoryIndex GetInitialIndex()
        {
            var index = new InMemoryIndex();

            index.Load(new StringReader(DefaultIndex.Index));

            return(index);
        }
Exemple #2
0
        private static InMemoryIndex GetInitialIndex()
        {
            var index = new InMemoryIndex();

            index.Load(new StringReader(SenseNetServicesIndex.Index));

            return(index);
        }
Exemple #3
0
        public InMemoryIndex Clone()
        {
            using (var op = SnTrace.Index.StartOperation("Clone index."))
            {
                var index = new InMemoryIndex
                {
                    IndexData = IndexData.ToDictionary(
                        x => x.Key,
                        x => x.Value.ToDictionary(
                            y => y.Key,
                            y => y.Value.ToList())),
                    StoredData = StoredData
                                 .Select(x => new Tuple <int, List <IndexField> >(x.Item1, x.Item2.Select(Clone).ToList()))
                                 .ToList()
                };

                op.Successful = true;
                return(index);
            }
        }
            // ========================================================================================

            public override SnQueryPredicate VisitSimplePredicate(SimplePredicate simplePredicate)
            {
                var result = new List <int>();

                var value = InMemoryIndex.IndexValueToString(simplePredicate.Value);

                if (_index.IndexData.TryGetValue(simplePredicate.FieldName, out var fieldValues))
                {
                    if (!value.Contains("*"))
                    {
                        if (fieldValues.TryGetValue(value, out var versionIds))
                        {
                            result.AddRange(versionIds);
                        }
                    }
                    else
                    {
                        result.AddRange(GetVersionIdsByWildcard(fieldValues, value));
                    }
                }
                _hitStack.Push(result);
                return(simplePredicate);
            }
 public InMemorySearchEngine(InMemoryIndex index)
 {
     Index           = index;
     _indexingEngine = new InMemoryIndexingEngine(this);
     _queryEngine    = new InMemoryQueryEngine(this);
 }
            public override SnQueryPredicate VisitRangePredicate(RangePredicate range)
            {
                var result = new List <int>();

                if (_index.IndexData.TryGetValue(range.FieldName, out var fieldValues))
                {
                    var min = InMemoryIndex.IndexValueToString(range.Min);
                    var max = InMemoryIndex.IndexValueToString(range.Max);
                    IEnumerable <KeyValuePair <string, List <int> > > expression;

                    // play permutation of min, max and exclusiveness
                    if (min != null && max != null)
                    {
                        if (!range.MinExclusive && !range.MaxExclusive)
                        {
                            expression = fieldValues.Where(x => (string.Compare(x.Key, min, StringComparison.Ordinal) >= 0) &&
                                                           (string.Compare(x.Key, max, StringComparison.Ordinal) <= 0));
                        }
                        else if (!range.MinExclusive && range.MaxExclusive)
                        {
                            expression = fieldValues.Where(x => (string.Compare(x.Key, min, StringComparison.Ordinal) >= 0) &&
                                                           (string.Compare(x.Key, max, StringComparison.Ordinal) < 0));
                        }
                        else if (range.MinExclusive && !range.MaxExclusive)
                        {
                            expression = fieldValues.Where(x => (string.Compare(x.Key, min, StringComparison.Ordinal) > 0) &&
                                                           (string.Compare(x.Key, max, StringComparison.Ordinal) <= 0));
                        }
                        else
                        {
                            expression = fieldValues.Where(x => (string.Compare(x.Key, min, StringComparison.Ordinal) > 0) &&
                                                           (string.Compare(x.Key, max, StringComparison.Ordinal) < 0));
                        }
                    }
                    else if (min != null)
                    {
                        expression = !range.MinExclusive
                            ? fieldValues.Where(x => string.Compare(x.Key, min, StringComparison.Ordinal) >= 0)
                            : fieldValues.Where(x => string.Compare(x.Key, min, StringComparison.Ordinal) > 0);
                    }
                    else
                    {
                        expression = !range.MaxExclusive
                            ? fieldValues.Where(x => string.Compare(x.Key, max, StringComparison.Ordinal) <= 0)
                            : fieldValues.Where(x => string.Compare(x.Key, max, StringComparison.Ordinal) < 0);
                    }

                    var lists = expression.Select(x => x.Value).ToArray();

                    // aggregate
                    var aggregation = new int[0].AsEnumerable();
                    foreach (var item in lists)
                    {
                        aggregation = aggregation.Union(item);
                    }
                    result = aggregation.Distinct().ToList();
                }

                _hitStack.Push(result);

                return(range);
            }
 public SnQueryInterpreter(InMemoryIndex index)
 {
     _index = index;
 }