Beispiel #1
0
        private void CheckTermsOrder(IndexReader r, ISet <string> allTerms, bool isTop)
        {
            TermsEnum terms = MultiFields.GetFields(r).GetTerms("f").GetEnumerator();

            BytesRef last = new BytesRef();

            ISet <string> seenTerms = new JCG.HashSet <string>();

            while (terms.MoveNext())
            {
                BytesRef term = terms.Term;

                Assert.IsTrue(last.CompareTo(term) < 0);
                last.CopyBytes(term);

                string s = term.Utf8ToString();
                Assert.IsTrue(allTerms.Contains(s), "term " + TermDesc(s) + " was not added to index (count=" + allTerms.Count + ")");
                seenTerms.Add(s);
            }

            if (isTop)
            {
                Assert.IsTrue(allTerms.SetEquals(seenTerms));
            }

            // Test seeking:
            IEnumerator <string> it = seenTerms.GetEnumerator();

            while (it.MoveNext())
            {
                BytesRef tr = new BytesRef(it.Current);
                Assert.AreEqual(TermsEnum.SeekStatus.FOUND, terms.SeekCeil(tr), "seek failed for term=" + TermDesc(tr.Utf8ToString()));
            }
        }
Beispiel #2
0
        // we have a segment, in NFD. Find all the strings that are canonically equivalent to it.
        private string[] GetEquivalents(string segment)
        {
            ISet <string> result       = new JCG.HashSet <string>();
            ISet <string> basic        = GetEquivalents2(segment);
            ISet <string> permutations = new JCG.HashSet <string>();

            // now get all the permutations
            // add only the ones that are canonically equivalent
            // TODO: optimize by not permuting any class zero.
            using (IEnumerator <string> it = basic.GetEnumerator())
            {
                while (it.MoveNext())
                {
                    string item = it.Current;
                    permutations.Clear();
#pragma warning disable 612, 618
                    Permute(item, SKIP_ZEROS, permutations);
#pragma warning restore 612, 618
                    using (IEnumerator <string> it2 = permutations.GetEnumerator())
                    {
                        while (it2.MoveNext())
                        {
                            string possible = it2.Current;

                            /*
                             *              String attempt = Normalizer.normalize(possible, Normalizer.DECOMP, 0);
                             *              if (attempt.equals(segment)) {
                             */
                            if (Normalizer.Compare(possible, segment, 0) == 0)
                            {
                                if (PROGRESS)
                                {
                                    Console.Out.WriteLine("Adding Permutation: " + Utility.Hex(possible));
                                }
                                result.Add(possible);
                            }
                            else
                            {
                                if (PROGRESS)
                                {
                                    Console.Out.WriteLine("-Skipping Permutation: " + Utility.Hex(possible));
                                }
                            }
                        }
                    }
                }
            }

            // convert into a String[] to clean up storage
            string[] finalResult = new string[result.Count];
            result.CopyTo(finalResult, 0);
            return(finalResult);
        }
        private static ISet <string> DifFiles(string[] files1, string[] files2)
        {
            ISet <string> set1  = new JCG.HashSet <string>();
            ISet <string> set2  = new JCG.HashSet <string>();
            ISet <string> extra = new JCG.HashSet <string>();

            for (int x = 0; x < files1.Length; x++)
            {
                set1.Add(files1[x]);
            }
            for (int x = 0; x < files2.Length; x++)
            {
                set2.Add(files2[x]);
            }
            IEnumerator <string> i1 = set1.GetEnumerator();

            while (i1.MoveNext())
            {
                string o = i1.Current;
                if (!set2.Contains(o))
                {
                    extra.Add(o);
                }
            }
            IEnumerator <string> i2 = set2.GetEnumerator();

            while (i2.MoveNext())
            {
                string o = i2.Current;
                if (!set1.Contains(o))
                {
                    extra.Add(o);
                }
            }
            return(extra);
        }
 public IEnumerator <Type> GetEnumerator()
 {
     return(types.GetEnumerator());
 }