-
- # Can't use speller.add_field because it tries to intuit a frequency, and
- # names are in an ID field, which seems to be immune to frequency.
- # Not hard to add everything ourselves, though
- reader = index.doc_reader()
- speller.add_words([ _['spelling_name'] for _ in reader ])
- reader.close()
+ # WARNING: HERE BE DRAGONS
+ # whoosh.spelling refuses to index things that don't look like words.
+ # Unfortunately, this doesn't work so well for Pokémon (Mr. Mime,
+ # Porygon-Z, etc.), and attempts to work around it lead to further
+ # complications.
+ # The below is copied from SpellChecker.add_scored_words without the check
+ # for isalpha(). XXX get whoosh patched to make this unnecessary!
+ writer = whoosh.writing.IndexWriter(speller.index())
+ for word in speller_entries:
+ fields = {"word": word, "score": 1}
+ for size in xrange(speller.mingram, speller.maxgram + 1):
+ nga = whoosh.analysis.NgramAnalyzer(size)
+ gramlist = [t.text for t in nga(word)]
+ if len(gramlist) > 0:
+ fields["start%s" % size] = gramlist[0]
+ fields["end%s" % size] = gramlist[-1]
+ fields["gram%s" % size] = " ".join(gramlist)
+ writer.add_document(**fields)
+ writer.commit()
+ # end copy-pasta