apache / lucene

Apache Lucene open-source search software
https://lucene.apache.org/
Apache License 2.0
2.49k stars 987 forks source link

SpellChecker : SpellChecker.indexDictionary : Javadoc incorrect [LUCENE-4487] #5553

Open asfimport opened 11 years ago

asfimport commented 11 years ago

example code in javadoc seems to be incorrect

code changes from #4631

means the javadoc

  SpellChecker spellchecker = new SpellChecker(spellIndexDirectory);
  // To index a field of a user index:
  spellchecker.indexDictionary(new LuceneDictionary(my_lucene_reader, a_field));
  // To index a file containing words:
  spellchecker.indexDictionary(new PlainTextDictionary(new File("myfile.txt")));
  String[] suggestions = spellchecker.suggestSimilar("misspelt", 5);

is incorrect i think something like this is better maybe

  SpellChecker spellchecker = new SpellChecker(spellIndexDirectory);
  // To index a field of a user index:
  spellchecker.indexDictionary(new LuceneDictionary(my_lucene_reader, a_field), new IndexWriterConfig(Version.LUCENE_CURRENT, null), false);
  // To index a file containing words:
  spellchecker.indexDictionary(new PlainTextDictionary(new File("myfile.txt")), new IndexWriterConfig(Version.LUCENE_CURRENT, null), false);
  String[] suggestions = spellchecker.suggestSimilar("misspelt", 5);

I'd possibly add something about creating a spellIndexDirectory too, not clear

  Directory spellIndexDirectory = FSDirectory.open("/dev/tmp/SOME_WORKING_DIR");
  SpellChecker spellchecker = new SpellChecker(spellIndexDirectory);
  // To index a field of a user index:
  spellchecker.indexDictionary(new LuceneDictionary(my_lucene_reader, a_field), new IndexWriterConfig(Version.LUCENE_CURRENT, null), false);
  // To index a file containing words:
  spellchecker.indexDictionary(new PlainTextDictionary(new File("myfile.txt")), new IndexWriterConfig(Version.LUCENE_CURRENT, null), false);
  String[] suggestions = spellchecker.suggestSimilar("misspelt", 5);

would of sent a patch but not familiar with how to get access to the apache git repo todo a pull/push

cheers

Ant


Migrated from LUCENE-4487 by Anthony Mckale Linked issues:

asfimport commented 11 years ago

Simon Willnauer (@s1monw) (migrated from JIRA)

this makes lots of sense! can you upload a patch for this?

simon

asfimport commented 11 years ago

Anthony Mckale (migrated from JIRA)

was trying to check out http://svn.apache.org/repos/asf/lucene/dev/trunk but having some corporate firewall issues today, will have a some time tomorrow to chuck a patch over about lunchish time

cheers

Ant