Ejemplo n.º 1
0
            // ========================================================================================

            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);
            }
Ejemplo n.º 2
0
            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);
            }