public override void SetUp()
        {
            base.SetUp();

            this.analyzer            = new ICUCollationKeyAnalyzer(TEST_VERSION_CURRENT, collator);
            this.firstRangeBeginning = new BytesRef
                                           (collator.GetCollationKey(FirstRangeBeginningOriginal).ToByteArray());
            this.firstRangeEnd = new BytesRef
                                     (collator.GetCollationKey(FirstRangeEndOriginal).ToByteArray());
            this.secondRangeBeginning = new BytesRef
                                            (collator.GetCollationKey(SecondRangeBeginningOriginal).ToByteArray());
            this.secondRangeEnd = new BytesRef
                                      (collator.GetCollationKey(SecondRangeEndOriginal).ToByteArray());
        }
示例#2
0
        public override void SetUp()
        {
            base.SetUp();

            this.analyzer            = new TestAnalyzer(collator);
            this.firstRangeBeginning = new BytesRef(EncodeCollationKey
                                                        (collator.GetCollationKey(FirstRangeBeginningOriginal).ToByteArray()));
            this.firstRangeEnd = new BytesRef(EncodeCollationKey
                                                  (collator.GetCollationKey(FirstRangeEndOriginal).ToByteArray()));
            this.secondRangeBeginning = new BytesRef(EncodeCollationKey
                                                         (collator.GetCollationKey(SecondRangeBeginningOriginal).ToByteArray()));
            this.secondRangeEnd = new BytesRef(EncodeCollationKey
                                                   (collator.GetCollationKey(SecondRangeEndOriginal).ToByteArray()));
        }
示例#3
0
        /// @tests java.text.CollationKey#toByteArray()
        // FIXME This test fails on Harmony ClassLibrary
        public void Failing_test_toByteArray()
        {
            // Test for method byte [] java.text.CollationKey.toByteArray()
            Collator collator = ILOG.J2CsMapping.Text.Collator.GetInstance();

            collator.SetStrength(ILOG.J2CsMapping.Text.Collator.PRIMARY);
            CollationKey key1 = collator.GetCollationKey("abc");

            byte[] bytes = key1.ToByteArray();
            NUnit.Framework.Assert.IsTrue(bytes.Length >= 3, "Not enough bytes");

            try {
                collator = new RuleBasedCollator("= 1 , 2 ; 3 , 4 < 5 ; 6 , 7");
            } catch (ParseException e) {
                NUnit.Framework.Assert.Fail("ParseException");
                return;
            }
            bytes = collator.GetCollationKey("1234567").ToByteArray();

            /*
             * CollationElementIterator it =
             * ((RuleBasedCollator)collator).getCollationElementIterator("1234567");
             * int order; while ((order = it.next()) !=
             * CollationElementIterator.NULLORDER) {
             * System.out.println(Integer.toHexString(order)); } for (int i=0;
             * i<bytes.length; i+=2) {
             * System.out.print(Integer.toHexString(bytes[i]) +
             * Integer.toHexString(bytes[i+1]) + " "); } System.out.println();
             */
            byte[] result = new byte[] { 0, 2, 0, 2, 0, 2, 0, 0, 0, 3, 0, 3, 0, 1,
                                         0, 2, 0, 2, 0, 0, 0, 4, 0, 4, 0, 1, 0, 1, 0, 2 };
            // Failed in java too : NUnit.Framework.Assert.IsTrue(ILOG.J2CsMapping.Collections.Arrays.Equals(bytes,result),"Wrong bytes");
        }
示例#4
0
        public void TestRanges()
        {
            Directory         dir      = NewDirectory();
            RandomIndexWriter iw       = new RandomIndexWriter(Random(), dir, Similarity, TimeZone);
            Document          doc      = new Document();
            Field             field    = NewField("field", "", StringField.TYPE_STORED);
            Collator          collator = Collator.GetInstance(CultureInfo.CurrentCulture); // uses -Dtests.locale

            if (Random().nextBoolean())
            {
                collator.Strength = CollationStrength.Primary;
            }
            ICUCollationDocValuesField collationField = new ICUCollationDocValuesField("collated", collator);

            doc.Add(field);
            doc.Add(collationField);

            int numDocs = AtLeast(500);

            for (int i = 0; i < numDocs; i++)
            {
                String value = TestUtil.RandomSimpleString(Random());
                field.SetStringValue(value);
                collationField.SetStringValue(value);
                iw.AddDocument(doc);
            }

            IndexReader ir = iw.Reader;

            iw.Dispose();
            IndexSearcher @is = NewSearcher(ir);

            int numChecks = AtLeast(100);

            for (int i = 0; i < numChecks; i++)
            {
                String   start    = TestUtil.RandomSimpleString(Random());
                String   end      = TestUtil.RandomSimpleString(Random());
                BytesRef lowerVal = new BytesRef(collator.GetCollationKey(start).ToByteArray());
                BytesRef upperVal = new BytesRef(collator.GetCollationKey(end).ToByteArray());
                Query    query    = new ConstantScoreQuery(FieldCacheRangeFilter.NewBytesRefRange("collated", lowerVal, upperVal, true, true));
                DoTestRanges(@is, start, end, query, collator);
            }

            ir.Dispose();
            dir.Dispose();
        }
示例#5
0
        public void TestJB581()
        {
            String   source = "THISISATEST.";
            String   target = "Thisisatest.";
            Collator coll   = null;

            try
            {
                coll = Collator.GetInstance(new CultureInfo("en") /*Locale.ENGLISH*/);
            }
            catch (Exception e)
            {
                Errln("ERROR: Failed to create the collator for : en_US\n");
                return;
            }

            int result = coll.Compare(source, target);

            // result is 1, secondary differences only for ignorable space characters
            if (result != 1)
            {
                Errln("Comparing two strings with only secondary differences in C failed.\n");
                return;
            }

            // To compare them with just primary differences
            coll.Strength = (Collator.PRIMARY);
            result        = coll.Compare(source, target);
            // result is 0
            if (result != 0)
            {
                Errln("Comparing two strings with no differences in C failed.\n");
                return;
            }

            // Now, do the same comparison with keys
            CollationKey sourceKeyOut, targetKeyOut;

            sourceKeyOut = coll.GetCollationKey(source);
            targetKeyOut = coll.GetCollationKey(target);
            result       = sourceKeyOut.CompareTo(targetKeyOut);
            if (result != 0)
            {
                Errln("Comparing two strings with sort keys in C failed.\n");
                return;
            }
        }
示例#6
0
        private void DoTestVariant(Collator collation, String source, String target, int result)
        {
            int          compareResult = collation.Compare(source, target);
            CollationKey srckey, tgtkey;

            srckey = collation.GetCollationKey(source);
            tgtkey = collation.GetCollationKey(target);
            int keyResult = srckey.CompareTo(tgtkey);

            if (compareResult != result)
            {
                Errln("String comparison failed in variant test\n");
            }
            if (keyResult != result)
            {
                Errln("Collation key comparison failed in variant test\n");
            }
        }
示例#7
0
 public override bool IncrementToken()
 {
     if (input.IncrementToken())
     {
         var collationKey  = collator.GetCollationKey(termAtt.ToString()).toByteArray();
         int encodedLength = IndexableBinaryStringTools.getEncodedLength(collationKey, 0, collationKey.Length);
         termAtt.resizeBuffer(encodedLength);
         termAtt.Length = encodedLength;
         IndexableBinaryStringTools.encode(collationKey, 0, collationKey.Length, termAtt.buffer(), 0, encodedLength);
         return(true);
     }
     else
     {
         return(false);
     }
 }