示例#1
0
        public void TestComparer()
        {
            using Directory compIdx = NewDirectory();
            SpellChecker compareSP = new SpellCheckerMock(compIdx, new LevensteinDistance(), new SuggestWordFrequencyComparer());

            try
            {
                using IndexReader r = DirectoryReader.Open(userindex);
                Addwords(r, compareSP, "field3");

                string[] similar = compareSP.SuggestSimilar("fvie", 2, r, "field3",
                                                            SuggestMode.SUGGEST_WHEN_NOT_IN_INDEX);
                assertTrue(similar.Length == 2);
                //five and fvei have the same score, but different frequencies.
                assertEquals("fvei", similar[0]);
                assertEquals("five", similar[1]);
            }
            finally
            {
                if (!compareSP.IsDisposed)
                {
                    compareSP.Dispose();
                }
            }
        }
示例#2
0
        public void TestBogusField()
        {
            using (Directory compIdx = NewDirectory())
            {
                SpellChecker compareSP = new SpellCheckerMock(compIdx, new LevensteinDistance(), new SuggestWordFrequencyComparer());
                try
                {
                    using (IndexReader r = DirectoryReader.Open(userindex))
                    {
                        Addwords(r, compareSP, "field3");

                        string[] similar = compareSP.SuggestSimilar("fvie", 2, r,
                                                                    "bogusFieldBogusField", SuggestMode.SUGGEST_WHEN_NOT_IN_INDEX);
                        assertEquals(0, similar.Length);
                    }
                }
                finally
                {
                    if (!compareSP.IsDisposed)
                    {
                        compareSP.Dispose();
                    }
                }
            }
        }
        public void TestComparator()
        {
            using (Directory compIdx = NewDirectory())
            {
                SpellChecker compareSP = new SpellCheckerMock(compIdx, new LevensteinDistance(), new SuggestWordFrequencyComparator());
                try
                {
                    using (IndexReader r = DirectoryReader.Open(userindex))
                    {

                        Addwords(r, compareSP, "field3");

                        string[] similar = compareSP.SuggestSimilar("fvie", 2, r, "field3",
                            SuggestMode.SUGGEST_WHEN_NOT_IN_INDEX);
                        assertTrue(similar.Length == 2);
                        //five and fvei have the same score, but different frequencies.
                        assertEquals("fvei", similar[0]);
                        assertEquals("five", similar[1]);
                    }
                }
                finally
                {
                    if (!compareSP.IsDisposed)
                        compareSP.Dispose();
                }
            }
        }
        public void TestBogusField()
        {
            using (Directory compIdx = NewDirectory())
            {
                SpellChecker compareSP = new SpellCheckerMock(compIdx, new LevensteinDistance(), new SuggestWordFrequencyComparator());
                try
                {
                    using (IndexReader r = DirectoryReader.Open(userindex))
                    {

                        Addwords(r, compareSP, "field3");

                        string[] similar = compareSP.SuggestSimilar("fvie", 2, r,
                            "bogusFieldBogusField", SuggestMode.SUGGEST_WHEN_NOT_IN_INDEX);
                        assertEquals(0, similar.Length);
                    }
                }
                finally
                {
                    if (!compareSP.IsDisposed)
                        compareSP.Dispose();
                }
            }
        }