public void IsSuffix(CompareInfo compareInfo, string source, string value, CompareOptions options, bool expected, int expectedMatchLength)
        {
            if (options == CompareOptions.None)
            {
                Assert.Equal(expected, compareInfo.IsSuffix(source, value));
            }
            Assert.Equal(expected, compareInfo.IsSuffix(source, value, options));

            if ((compareInfo == s_invariantCompare) && ((options == CompareOptions.None) || (options == CompareOptions.IgnoreCase)))
            {
                StringComparison stringComparison = (options == CompareOptions.IgnoreCase) ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture;
                Assert.Equal(expected, source.EndsWith(value, stringComparison));
                Assert.Equal(expected, source.AsSpan().EndsWith(value.AsSpan(), stringComparison));
            }

            // Now test the span version - use BoundedMemory to detect buffer overruns

            using BoundedMemory <char> sourceBoundedMemory = BoundedMemory.AllocateFromExistingData <char>(source);
            sourceBoundedMemory.MakeReadonly();

            using BoundedMemory <char> valueBoundedMemory = BoundedMemory.AllocateFromExistingData <char>(value);
            valueBoundedMemory.MakeReadonly();

            Assert.Equal(expected, compareInfo.IsSuffix(sourceBoundedMemory.Span, valueBoundedMemory.Span, options));
            Assert.Equal(expected, compareInfo.IsSuffix(sourceBoundedMemory.Span, valueBoundedMemory.Span, options, out int actualMatchLength));
            Assert.Equal(expectedMatchLength, actualMatchLength);
        }
 public void IsSuffix(CompareInfo compareInfo, string source, string value, CompareOptions options, bool expected)
 {
     if (options == CompareOptions.None)
     {
         Assert.Equal(expected, compareInfo.IsSuffix(source, value));
     }
     Assert.Equal(expected, compareInfo.IsSuffix(source, value, options));
 }
Beispiel #3
0
 public void IsSuffix(CompareInfo compareInfo, string source, string value, CompareOptions options, bool expected)
 {
     if (options == CompareOptions.None)
     {
         Assert.Equal(expected, compareInfo.IsSuffix(source, value));
     }
     Assert.Equal(expected, compareInfo.IsSuffix(source, value, options));
 }
Beispiel #4
0
    public static void IsSuffixBadCompareOptions()
    {
        CompareInfo ci = CultureInfo.InvariantCulture.CompareInfo;

        Assert.Throws <ArgumentException>(() => ci.IsSuffix("aaa", "a", CompareOptions.Ordinal | CompareOptions.IgnoreWidth));
        Assert.Throws <ArgumentException>(() => ci.IsSuffix("aaa", "a", CompareOptions.OrdinalIgnoreCase | CompareOptions.IgnoreWidth));
        Assert.Throws <ArgumentException>(() => ci.IsSuffix("aaa", "a", CompareOptions.StringSort));
        Assert.Throws <ArgumentException>(() => ci.IsSuffix("aaa", "a", (CompareOptions)(-1)));
    }
Beispiel #5
0
        public void IsSuffix(CompareInfo compareInfo, string source, string value, CompareOptions options, bool expected)
        {
            if (options == CompareOptions.None)
            {
                Assert.Equal(expected, compareInfo.IsSuffix(source, value));
            }
            Assert.Equal(expected, compareInfo.IsSuffix(source, value, options));

            if ((compareInfo == s_invariantCompare) && ((options == CompareOptions.None) || (options == CompareOptions.IgnoreCase)))
            {
                StringComparison stringComparison = (options == CompareOptions.IgnoreCase) ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture;
                Assert.Equal(expected, source.EndsWith(value, stringComparison));
                Assert.Equal(expected, source.AsSpan().EndsWith(value.AsSpan(), stringComparison));
            }
        }
        public void Test(CultureInfo culture, string str1, string str2, bool expected, CompareOptions options)
        {
            CompareInfo ci = culture.CompareInfo;
            bool        i  = ci.IsSuffix(str1, str2, options);

            Assert.Equal(expected, i);
        }
    public bool Test(CultureInfo culture, string str1, string str2, bool expected, CompareOptions options, string id)
    {
        if (!id.Contains("s") || !Utilities.IsVistaOrLater)         //Due Windows 7 bug 130925
        {
            expected = GlobLocHelper.OSIsSuffix(culture, str1, str2, options);
        }
        CompareInfo ci     = culture.CompareInfo;
        bool        result = true;

        if (str1 == null || str2 == null || (str1.Length < 100 && str2.Length < 100))
        {
            TestFramework.BeginScenario(id + ": Comparing " + ((str1 == null) ? "null" : str1) + " / " + ((str2 == null) ? "null" : str2) + "; options: " + options + "; culture: " + ci.Name);
        }
        else
        {
            TestFramework.BeginScenario(id + ": Comparing LongStr (" + str1.Length + ") / LongStr(" + str2.Length + "); options: " + options + "; culture: " + ci.Name);
        }
        try
        {
            bool i = ci.IsSuffix(str1, str2, options);
            if (i != expected)
            {
                result = false;
                TestFramework.LogError("001", "Error in " + id + ", unexpected comparison result. Actual: " + i + ", Expected: " + expected);
            }
        }
        catch (Exception exc)
        {
            result = false;
            TestFramework.LogError("003", "Unexpected exception in " + id + ", excpetion: " + exc.ToString());
        }
        return(result);
    }
    public bool TestOrd(CultureInfo culture, string str1, string str2, bool expected, CompareOptions options, string id)
    {
        CompareInfo ci     = culture.CompareInfo;
        bool        result = true;

        if (str1 == null || str2 == null || (str1.Length < 100 && str2.Length < 100))
        {
            TestFramework.BeginScenario(id + ": Comparing " + ((str1 == null) ? "null" : str1) + " / " + ((str2 == null) ? "null" : str2) + "; options: " + options + "; culture: " + ci.Name);
        }
        else
        {
            TestFramework.BeginScenario(id + ": Comparing LongStr (" + str1.Length + ") / LongStr(" + str2.Length + "); options: " + options + "; culture: " + ci.Name);
        }
        try
        {
            bool i = ci.IsSuffix(str1, str2, options);
            if (i != expected)
            {
                result = false;
                TestFramework.LogError("001", "Error in " + id + ", unexpected comparison result. Actual: " + i + ", Expected: " + expected);
            }
        }
        catch (Exception exc)
        {
            result = false;
            TestFramework.LogError("003", "Unexpected exception in " + id + ", excpetion: " + exc.ToString());
        }
        return(result);
    }
        private static bool ValidResourceFileName(String inFile)
        {
            if (inFile == null)
            {
                return(false);
            }

            CompareInfo comp = CultureInfo.InvariantCulture.CompareInfo;

            if (comp.IsSuffix(inFile, ".resx", CompareOptions.IgnoreCase) ||
                comp.IsSuffix(inFile, ".txt", CompareOptions.IgnoreCase) ||
                comp.IsSuffix(inFile, ".restext", CompareOptions.IgnoreCase) ||
                comp.IsSuffix(inFile, ".resources", CompareOptions.IgnoreCase))
            {
                return(true);
            }
            return(false);
        }
Beispiel #10
0
    public static void Main()
    {
        // Defines the strings to compare.
        String myStr1 = "calle";
        String myStr2 = "llegar";
        String myXfix = "lle";

        // Uses the CompareInfo property of the InvariantCulture.
        CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

        // Determines whether myXfix is a prefix of "calle" and "llegar".
        Console.WriteLine("IsPrefix( {0}, {1} ) : {2}", myStr1, myXfix, myComp.IsPrefix(myStr1, myXfix));
        Console.WriteLine("IsPrefix( {0}, {1} ) : {2}", myStr2, myXfix, myComp.IsPrefix(myStr2, myXfix));

        // Determines whether myXfix is a suffix of "calle" and "llegar".
        Console.WriteLine("IsSuffix( {0}, {1} ) : {2}", myStr1, myXfix, myComp.IsSuffix(myStr1, myXfix));
        Console.WriteLine("IsSuffix( {0}, {1} ) : {2}", myStr2, myXfix, myComp.IsSuffix(myStr2, myXfix));
    }
Beispiel #11
0
        private bool CheckPath(string path)
        {
            CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo;

            if (compareInfo.IsPrefix(path, "/", CompareOptions.Ordinal))
            {
                return(path == this.currentXmlPath);
            }
            return(compareInfo.IsSuffix(this.currentXmlPath, path, CompareOptions.Ordinal));
        }
        public void TestExc <T>(CultureInfo culture, string str1, string str2, CompareOptions options)
            where T : Exception
        {
            CompareInfo ci = culture.CompareInfo;

            Assert.Throws <T>(() =>
            {
                bool i = ci.IsSuffix(str1, str2, options);
            });
        }
Beispiel #13
0
        public override object Eval(object row, object context)
        {
            object lValue = base.Left.Eval(row, context);

            if (!DataStorageHelper.IsObjectNull(lValue))
            {
                if (!(lValue is string || lValue is SqlString))
                {
                    throw InvalidExpressionException.TypeMismatchInBinop(Operator.Like, lValue.GetType(), typeof(string));
                }

                object rValue = base.Right.Eval(row, context);
                if (DataStorageHelper.IsObjectNull(rValue))
                {
                    return(DBNull.Value);
                }

                if (!(rValue is string || rValue is SqlString))
                {
                    throw InvalidExpressionException.TypeMismatchInBinop(Operator.Like, typeof(string), rValue.GetType());
                }

                string text    = lValue.ToString();
                string pattern = this.AnalizePattern(rValue.ToString());

                char[] trimChars = new char[] { ' ', '\u3000' };
                text = text.TrimEnd(trimChars);

                CompareInfo compareInfo = base.Culture.CompareInfo;
                switch (this.kind)
                {
                case match_left:
                    return(0 == compareInfo.IndexOf(text, pattern, this.compareFlags));

                case match_right:
                {
                    string text4 = pattern.TrimEnd(trimChars);
                    return(compareInfo.IsSuffix(text, text4, this.compareFlags));
                }

                case match_middle:
                    return(0 <= compareInfo.IndexOf(text, pattern, this.compareFlags));

                case match_exact:
                    return(0 == compareInfo.Compare(text, pattern, this.compareFlags));

                case match_all:
                    return(true);
                }
            }

            return(DBNull.Value);
        }
Beispiel #14
0
        public void IsSuffix(string culture, string source, string suffix, CompareOptions options)
        {
            CompareInfo compareInfo = CultureInfo.GetCultureInfo(culture).CompareInfo;

            foreach (var iteration in Benchmark.Iterations)
            {
                using (iteration.StartMeasurement())
                {
                    compareInfo.IsSuffix(source, suffix, options);
                }
            }
        }
Beispiel #15
0
        bool CheckPath(string path)
        {
            CompareInfo ci = CultureInfo.InvariantCulture.CompareInfo;

            if (ci.IsPrefix(path, "/", CompareOptions.Ordinal))
            {
                return(path == currentXmlPath);
            }
            else
            {
                return(ci.IsSuffix(currentXmlPath, path, CompareOptions.Ordinal));
            }
        }
Beispiel #16
0
    public static void Main()
    {
        // Defines the strings to compare.
        String myStr1 = "calle";
        String myStr2 = "llegar";
        String myXfix = "LLE";

        // Uses the CompareInfo property of the InvariantCulture.
        CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

        Console.WriteLine("IsSuffix \"{0}\", \"{1}\"", myStr1, myXfix);
        Console.WriteLine("   With no CompareOptions            : {0}", myComp.IsSuffix(myStr1, myXfix));
        Console.WriteLine("   With None                         : {0}", myComp.IsSuffix(myStr1, myXfix, CompareOptions.None));
        Console.WriteLine("   With Ordinal                      : {0}", myComp.IsSuffix(myStr1, myXfix, CompareOptions.Ordinal));
        Console.WriteLine("   With IgnoreCase                   : {0}", myComp.IsSuffix(myStr1, myXfix, CompareOptions.IgnoreCase));

        Console.WriteLine("IsPrefix \"{0}\", \"{1}\"", myStr2, myXfix);
        Console.WriteLine("   With no CompareOptions            : {0}", myComp.IsPrefix(myStr2, myXfix));
        Console.WriteLine("   With None                         : {0}", myComp.IsPrefix(myStr2, myXfix, CompareOptions.None));
        Console.WriteLine("   With Ordinal                      : {0}", myComp.IsPrefix(myStr2, myXfix, CompareOptions.Ordinal));
        Console.WriteLine("   With IgnoreCase                   : {0}", myComp.IsPrefix(myStr2, myXfix, CompareOptions.IgnoreCase));
    }
        public void IsSuffix_Invalid()
        {
            // Source is null
            Assert.Throws <ArgumentNullException>(() => s_invariantCompare.IsSuffix(null, ""));
            Assert.Throws <ArgumentNullException>(() => s_invariantCompare.IsSuffix(null, "", CompareOptions.None));

            // Prefix is null
            Assert.Throws <ArgumentNullException>(() => s_invariantCompare.IsSuffix("", null));
            Assert.Throws <ArgumentNullException>(() => s_invariantCompare.IsSuffix("", null, CompareOptions.None));

            // Source and prefix are null
            Assert.Throws <ArgumentNullException>(() => s_invariantCompare.IsSuffix(null, null));
            Assert.Throws <ArgumentNullException>(() => s_invariantCompare.IsSuffix(null, null, CompareOptions.None));

            // Options are invalid
            Assert.Throws <ArgumentException>(() => s_invariantCompare.IsSuffix("Test's", "Tests", CompareOptions.StringSort));
            Assert.Throws <ArgumentException>(() => s_invariantCompare.IsSuffix("Test's", "Tests", (CompareOptions)(-1)));
            Assert.Throws <ArgumentException>(() => s_invariantCompare.IsSuffix("Test's", "Tests", (CompareOptions)0x11111111));
        }
Beispiel #18
0
        public static bool EndsWithCultureIgnoreCaseHelper(ReadOnlySpan <char> span, ReadOnlySpan <char> value, CompareInfo compareInfo)
        {
            Debug.Assert(value.Length != 0);

            if (GlobalizationMode.Invariant)
            {
                return(EndsWithOrdinalIgnoreCaseHelper(span, value));
            }
            if (span.Length == 0)
            {
                return(false);
            }
            return(compareInfo.IsSuffix(span, value, CompareOptions.IgnoreCase));
        }
Beispiel #19
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()));
        }
Beispiel #20
0
        public override object Eval(object row, object context)
        {
            object obj1 = this.Left.Eval(row, context);

            if (!DataStorageHelper.IsObjectNull(obj1))
            {
                if (!(obj1 is string) && !(obj1 is SqlString))
                {
                    Guid guid = obj1 as Guid;
                }
                object obj2 = this.Right.Eval(row, context);
                if (DataStorageHelper.IsObjectNull(obj2))
                {
                    return((object)DBNull.Value);
                }
                if (!(obj2 is string) && !(obj2 is SqlString) && !(obj1 is Guid))
                {
                    throw InvalidExpressionException.TypeMismatchInBinop(Operator.Like, typeof(string), obj2.GetType());
                }
                string str     = obj1.ToString();
                string string2 = this.AnalizePattern(obj2.ToString());
                char[] chArray = new char[2] {
                    ' ', ' '
                };
                CompareInfo compareInfo = this.Culture.CompareInfo;
                switch (this.kind)
                {
                case 1:
                    return((object)(0 == compareInfo.IndexOf(str, string2, this.compareFlags)));

                case 2:
                    string suffix = string2.TrimEnd(chArray);
                    return((object)compareInfo.IsSuffix(str, suffix, this.compareFlags));

                case 3:
                    return((object)(0 <= compareInfo.IndexOf(str, string2, this.compareFlags)));

                case 4:
                    return((object)(0 == compareInfo.Compare(str, string2, this.compareFlags)));

                case 5:
                    return((object)true);
                }
            }
            return((object)DBNull.Value);
        }
Beispiel #21
0
        public static SortOptions?GetSortOption(this IndexDefinition self, string name, IndexQuery query)
        {
            SortOptions value;

            if (InvariantCompare.IsSuffix(name, _Range, CompareOptions.None))
            {
                string nameWithoutRange = name.Substring(0, name.Length - _Range.Length);
                if (self.SortOptions.TryGetValue(nameWithoutRange, out value))
                {
                    return(value);
                }

                if (self.SortOptions.TryGetValue(Constants.AllFields, out value))
                {
                    return(value);
                }

                if (query != null && query.SortHints != null && query.SortHints.TryGetValue(_SortHint + nameWithoutRange, out value))
                {
                    return(value);
                }
            }

            if (self.SortOptions.TryGetValue(name, out value))
            {
                return(value);
            }

            if (self.SortOptions.TryGetValue(Constants.AllFields, out value))
            {
                return(value);
            }

            if (query == null || query.SortHints == null)
            {
                return(value);
            }

            if (!query.SortHints.TryGetValue(_SortHint + name, out value))
            {
                return(SortOptions.None);
            }

            return(value);
        }
Beispiel #22
0
    public static void IsSuffixArgumentNullException()
    {
        CompareInfo ci = CultureInfo.InvariantCulture.CompareInfo;

        Assert.Throws <ArgumentNullException>(() => ci.IsSuffix(null, ""));
        Assert.Throws <ArgumentNullException>(() => ci.IsSuffix(null, "", CompareOptions.Ordinal));

        Assert.Throws <ArgumentNullException>(() => ci.IsSuffix("", null));
        Assert.Throws <ArgumentNullException>(() => ci.IsSuffix("", null, CompareOptions.Ordinal));

        Assert.Throws <ArgumentNullException>(() => ci.IsSuffix(null, null));
        Assert.Throws <ArgumentNullException>(() => ci.IsSuffix(null, null, CompareOptions.Ordinal));
    }
Beispiel #23
0
        void CheckBaseName()
        {
            if (BaseNameField.Length <= 10)
            {
                return;
            }

            CompareInfo c = CultureInfo.InvariantCulture.CompareInfo;

            if (!c.IsSuffix(BaseNameField, ".resources", CompareOptions.IgnoreCase))
            {
                return;
            }

            if (MainAssembly != null)
            {
                string resourceFileName = GetResourceFileName(
                    CultureInfo.InvariantCulture);
                Stream s = GetManifestResourceStreamNoCase(
                    MainAssembly, resourceFileName);
                if (s != null)
                {
                    return;
                }
            }
            else
            {
                string resourceFile = GetResourceFilePath(
                    CultureInfo.InvariantCulture);
                if (File.Exists(resourceFile))
                {
                    return;
                }
            }

            throw new ArgumentException("ResourceManager base"
                                        + " name should not end in .resources. It"
                                        + " should be similar to MyResources,"
                                        + " which the ResourceManager can convert"
                                        + " into MyResources.<culture>.resources;"
                                        + " for example, MyResources.en-US.resources.");
        }
    public bool TestExc(CultureInfo culture, string str1, string str2, Type expected, CompareOptions options, string id)
    {
        CompareInfo ci     = culture.CompareInfo;
        bool        result = true;

        TestFramework.BeginScenario(id + ": Comparing " + str1 + " / " + str2 + "; options: " + options + "; culture: " + ci.Name);
        try
        {
            bool i = ci.IsSuffix(str1, str2, options);
            result = false;
            TestFramework.LogError("004", "Error in " + id + ", expected exception did not occur. Comparison result: " + i);
        }
        catch (Exception exc)
        {
            if (!exc.GetType().Equals(expected))
            {
                result = false;
                TestFramework.LogError("005", "Unexpected exception in " + id + ", excpetion: " + exc.ToString());
            }
        }
        return(result);
    }
Beispiel #25
0
        public void IsSuffix_Invalid()
        {
            // Source is null
            AssertExtensions.Throws <ArgumentNullException>("source", () => s_invariantCompare.IsSuffix(null, ""));
            AssertExtensions.Throws <ArgumentNullException>("source", () => s_invariantCompare.IsSuffix(null, "", CompareOptions.None));

            // Prefix is null
            AssertExtensions.Throws <ArgumentNullException>("suffix", () => s_invariantCompare.IsSuffix("", null));
            AssertExtensions.Throws <ArgumentNullException>("suffix", () => s_invariantCompare.IsSuffix("", null, CompareOptions.None));

            // Source and prefix are null
            AssertExtensions.Throws <ArgumentNullException>("source", () => s_invariantCompare.IsSuffix(null, null));
            AssertExtensions.Throws <ArgumentNullException>("source", () => s_invariantCompare.IsSuffix(null, null, CompareOptions.None));

            // Options are invalid
            AssertExtensions.Throws <ArgumentException>("options", () => s_invariantCompare.IsSuffix("Test's", "Tests", CompareOptions.StringSort));
            AssertExtensions.Throws <ArgumentException>("options", () => s_invariantCompare.IsSuffix("Test's", "Tests", CompareOptions.Ordinal | CompareOptions.IgnoreWidth));
            AssertExtensions.Throws <ArgumentException>("options", () => s_invariantCompare.IsSuffix("Test's", "Tests", CompareOptions.OrdinalIgnoreCase | CompareOptions.IgnoreWidth));
            AssertExtensions.Throws <ArgumentException>("options", () => s_invariantCompare.IsSuffix("Test's", "Tests", (CompareOptions)(-1)));
            AssertExtensions.Throws <ArgumentException>("options", () => s_invariantCompare.IsSuffix("Test's", "Tests", (CompareOptions)0x11111111));
        }
Beispiel #26
0
 internal static bool EndsWith(string source, string suffix)
 {
     return(InvariantCompareInfo.IsSuffix(source, suffix, (CompareOptions)1073741824));
 }
Beispiel #27
0
    public static void IsSuffix(string localeName, string source, string suffix, bool expectedResult, CompareOptions options)
    {
        CompareInfo ci = CompareInfo.GetCompareInfo(localeName);

        Assert.Equal(expectedResult, ci.IsSuffix(source, suffix, options));
    }
Beispiel #28
0
 public static bool EndsWithIgnoreCase(ref string source, string suffix)
 {
     return(__CompareInfo.IsSuffix(source, suffix, CompareOptions.IgnoreCase));
 }
Beispiel #29
0
        public static DynamicQueryMapping Create(string entityName, IndexQueryServerSide query)
        {
            var result = new DynamicQueryMapping
            {
                ForCollection = entityName,
            };

            IEnumerable <DynamicQueryMappingItem> dynamicMapFields;

            string[] numericFields;

            if (query.DynamicMapReduceFields == null)
            {
                // auto map query

                var fields = SimpleQueryParser.GetFieldsForDynamicQuery(query); // TODO arek - not sure if we really need a Tuple<string, string> here

                if (query.SortedFields != null)
                {
                    foreach (var sortedField in query.SortedFields)
                    {
                        var field = sortedField.Field;

                        if (field == Constants.Indexing.Fields.IndexFieldScoreName)
                        {
                            continue;
                        }

                        if (field.StartsWith(Constants.Indexing.Fields.RandomFieldName) ||
                            field.StartsWith(Constants.Indexing.Fields.CustomSortFieldName))
                        {
                            continue;
                        }

                        if (InvariantCompare.IsPrefix(field, Constants.Indexing.Fields.AlphaNumericFieldName, CompareOptions.None))
                        {
                            field = SortFieldHelper.ExtractName(field);
                        }

                        if (InvariantCompare.IsSuffix(field, Constants.Indexing.Fields.RangeFieldSuffix, CompareOptions.None))
                        {
                            field = field.Substring(0, field.Length - Constants.Indexing.Fields.RangeFieldSuffix.Length);
                        }

                        fields.Add(Tuple.Create(SimpleQueryParser.TranslateField(field), field));
                    }
                }

                dynamicMapFields = fields.Select(x => new DynamicQueryMappingItem(x.Item1.EndsWith(Constants.Indexing.Fields.RangeFieldSuffix) ? x.Item1.Substring(0, x.Item1.Length - Constants.Indexing.Fields.RangeFieldSuffix.Length) : x.Item1, FieldMapReduceOperation.None));

                numericFields = fields.Where(x => x.Item1.EndsWith(Constants.Indexing.Fields.RangeFieldSuffix)).Select(x => x.Item1).Distinct().ToArray();
            }
            else
            {
                // dynamic map-reduce query

                result.IsMapReduce = true;

                dynamicMapFields = query.DynamicMapReduceFields.Where(x => x.IsGroupBy == false).Select(x => new DynamicQueryMappingItem(x.Name, x.OperationType));

                result.GroupByFields = query.DynamicMapReduceFields.Where(x => x.IsGroupBy).Select(x => x.Name).ToArray();

                numericFields = null;
            }

            result.MapFields = dynamicMapFields
                               .Where(x => x.Name != Constants.Indexing.Fields.DocumentIdFieldName)
                               .OrderByDescending(x => x.Name.Length)
                               .ToArray();

            result.SortDescriptors = GetSortInfo(query.SortedFields, numericFields);

            result.HighlightedFields = query.HighlightedFields.EmptyIfNull().Select(x => x.Field).ToArray();

            return(result);
        }
Beispiel #30
0
 internal static bool EndsWith(string source, string suffix)
 {
     return(InvariantCompareInfo.IsSuffix(source, suffix, CompareOptions.Ordinal));
 }
Beispiel #31
0
 void AssertIsSuffix(string message, bool expected, string source,
                     string target)
 {
     Assert.IsTrue(message, expected == invariant.IsSuffix(
                       source, target));
 }