Esempio n. 1
0
        public void TestBuildIndexByBatch()
        {
            WordsHintBuilder.AddWords(new[] { "AAAA", "Bbbb", "DDDDD" });
            WordsHintBuilder.BuildIndexByBatch(Config, true, true, true, null, true);

            var docs = LucenePool.Search(Config.LuceneIndexForHint, new MatchAllDocsQuery(), 1000);

            Assert.AreEqual(3, docs.Length);
            CollectionAssert.AreEquivalent(new[] { "AAAA", "Bbbb", "DDDDD" }, docs.Select(u => u.Get(nameof(CodeWord.Word))));
            CollectionAssert.AreEquivalent(new[] { "aaaa", "bbbb", "ddddd" }, docs.Select(u => u.Get(nameof(CodeWord.WordLower))));
            Assert.AreEqual(0, WordsHintBuilder.Words.Count);
        }
Esempio n. 2
0
        public void TestUpdateWordsAndUpdateIndex()
        {
            WordsHintBuilder.AddWords(new[] { "AAAA", "Bbbbb", "DDDDD" });
            WordsHintBuilder.BuildIndexByBatch(Config, true, true, true, null, true);

            var docs = LucenePool.Search(Config.LuceneIndexForHint, new MatchAllDocsQuery(), 1000);

            Assert.AreEqual(3, docs.Length);

            WordsHintBuilder.UpdateWordsHint(Config, new[] { "AAAA", "Bbbbb", "EEEEE", "ABC", "VeryLongWord".PadRight(200, 'L') }, null);
            docs = LucenePool.Search(Config.LuceneIndexForHint, new MatchAllDocsQuery(), 1000);
            Assert.AreEqual(4, docs.Length, "Skip duplicate and length must larger than 3 and less than 200");
            CollectionAssert.AreEquivalent(new[] { "AAAA", "Bbbbb", "DDDDD", "EEEEE" }, docs.Select(u => u.Get(nameof(CodeWord.Word))));
            CollectionAssert.AreEquivalent(new[] { "aaaa", "bbbbb", "ddddd", "eeeee" }, docs.Select(u => u.Get(nameof(CodeWord.WordLower))));
        }
Esempio n. 3
0
        public void TestBuildIndexByBatch_NotFirstInit()
        {
            WordsHintBuilder.AddWords(new[] { "AAAA", "Bbbb", "DDDDD" });
            WordsHintBuilder.BuildIndexByBatch(Config, true, true, true, null, true);

            var docs = LucenePool.Search(Config.LuceneIndexForHint, new MatchAllDocsQuery(), 1000);

            Assert.AreEqual(3, docs.Length);
            CollectionAssert.AreEquivalent(new[] { "AAAA", "Bbbb", "DDDDD" }, docs.Select(u => u.Get(nameof(CodeWord.Word))));

            WordsHintBuilder.AddWords(new[] { "AAAA" });
            WordsHintBuilder.BuildIndexByBatch(Config, true, true, true, null, false);
            docs = LucenePool.Search(Config.LuceneIndexForHint, new MatchAllDocsQuery(), 1000);
            Assert.AreEqual(3, docs.Length, "When is not first init, do update documents");
        }
Esempio n. 4
0
 public void TestAddWords()
 {
     WordsHintBuilder.AddWords(new[] { "AAAA", "BBBB", "Ddddd", "AAAA", "EEE", "VeryLongWord".PadRight(200, 'L') });
     Assert.AreEqual(3, WordsHintBuilder.Words.Count, "Length must larger than 3 and less than 200 and duplicates is skipped");
     CollectionAssert.AreEquivalent(new[] { "AAAA", "BBBB", "Ddddd" }, WordsHintBuilder.Words);
 }