コード例 #1
0
 public void TestBuild()
 {
     string LF = Environment.NewLine;
     string input = "oneword" + LF + "twoword" + LF + "threeword";
     PlainTextDictionary ptd = new PlainTextDictionary(new StringReader(input));
     Store.Directory ramDir = NewDirectory();
     SpellChecker spellChecker = new SpellChecker(ramDir);
     spellChecker.IndexDictionary(ptd, NewIndexWriterConfig(TEST_VERSION_CURRENT, null), false);
     string[] similar = spellChecker.SuggestSimilar("treeword", 2);
     assertEquals(2, similar.Length);
     assertEquals(similar[0], "threeword");
     assertEquals(similar[1], "oneword");
     spellChecker.Dispose();
     ramDir.Dispose();
 }
コード例 #2
0
 public void TestSpellchecker()
 {
     Directory dir = NewDirectory();
     SpellChecker sc = new SpellChecker(dir);
     indexReader = DirectoryReader.Open(store);
     sc.IndexDictionary(new LuceneDictionary(indexReader, "contents"), NewIndexWriterConfig(TEST_VERSION_CURRENT, null), false);
     string[] suggestions = sc.SuggestSimilar("Tam", 1);
     assertEquals(1, suggestions.Length);
     assertEquals("Tom", suggestions[0]);
     suggestions = sc.SuggestSimilar("Jarry", 1);
     assertEquals(1, suggestions.Length);
     assertEquals("Jerry", suggestions[0]);
     indexReader.Dispose();
     sc.Dispose();
     dir.Dispose();
 }
コード例 #3
0
 private void Addwords(IndexReader r, SpellChecker sc, string field)
 {
     long time = Environment.TickCount;
     sc.IndexDictionary(new LuceneDictionary(r, field), NewIndexWriterConfig(TEST_VERSION_CURRENT, null), false);
     time = Environment.TickCount - time;
     //System.out.println("time to build " + field + ": " + time);
 }