Don't suggest a word as similar for itself. Thanks to Michael Harhen for the fix.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@373185 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Daniel Naber 2006-01-28 17:22:04 +00:00
parent 75ee463870
commit 9db7eaa951
2 changed files with 13 additions and 5 deletions

View File

@ -172,7 +172,7 @@ public class SpellChecker {
sugword.string=hits.doc(i).get(F_WORD); // get orig word)
if (sugword.string==word) {
if (sugword.string.equals(word)) {
continue; // don't suggest a word for itself, that would be silly
}

View File

@ -22,7 +22,7 @@ import org.apache.lucene.store.Directory;
*/
public class TestSpellChecker extends TestCase {
private SpellChecker spellChecker;
Directory userindex, spellindex;
private Directory userindex, spellindex;
protected void setUp() throws Exception {
super.setUp();
@ -61,18 +61,27 @@ public class TestSpellChecker extends TestCase {
// test small word
String[] similar = spellChecker.suggestSimilar("fvie", 2);
assertEquals(1, similar.length);
assertEquals(similar[0], "five");
similar = spellChecker.suggestSimilar("five", 2);
assertEquals(1, similar.length);
assertEquals(similar[0], "nine"); // don't suggest a word for itself
similar = spellChecker.suggestSimilar("fiv", 2);
assertEquals(1, similar.length);
assertEquals(similar[0], "five");
similar = spellChecker.suggestSimilar("ive", 2);
assertEquals(1, similar.length);
assertEquals(similar[0], "five");
similar = spellChecker.suggestSimilar("fives", 2);
assertEquals(1, similar.length);
assertEquals(similar[0], "five");
similar = spellChecker.suggestSimilar("fie", 2);
assertEquals(1, similar.length);
assertEquals(similar[0], "five");
similar = spellChecker.suggestSimilar("fi", 2);
@ -88,7 +97,6 @@ public class TestSpellChecker extends TestCase {
e.printStackTrace();
fail();
}
}
@ -96,14 +104,14 @@ public class TestSpellChecker extends TestCase {
long time = System.currentTimeMillis();
spellChecker.indexDictionary(new LuceneDictionary(r, field));
time = System.currentTimeMillis() - time;
System.out.println("time to build " + field + ": " + time);
//System.out.println("time to build " + field + ": " + time);
}
private int numdoc() throws IOException {
IndexReader rs = IndexReader.open(spellindex);
int num = rs.numDocs();
assertTrue(num != 0);
System.out.println("num docs: " + num);
//System.out.println("num docs: " + num);
rs.close();
return num;
}