- row_key = dict(table=cls.__tablename__, row_id=row.id)
-
- # Spelling index only indexes strings of letters, alas, so we
- # reduce every name to this to make the index work. However, exact
- # matches are not returned, so e.g. 'nidoran' would neither match
- # exactly nor fuzzy-match. Solution: add the spelling-munged name
- # as a regular index row too.
- name = row.name.lower()
- writer.add_document(name=name, **row_key)
+ row_key = dict(table=cls.__tablename__, row_id=unicode(row.id))
+
+ name = row.name
+ writer.add_document(name=name.lower(),
+ display_name=name,
+ **row_key)
+ speller_entries.append((name.lower(), 1))
+
+ # Pokemon also get other languages
+ for foreign_name in getattr(row, 'foreign_names', []):
+ moonspeak = foreign_name.name
+ if name == moonspeak:
+ # Don't add the English name again as a different language;
+ # no point and it makes spell results confusing
+ continue
+
+ writer.add_document(name=moonspeak.lower(),
+ language=foreign_name.language.name,
+ display_name=moonspeak,
+ **row_key)
+ speller_entries.append((moonspeak.lower(), 3))
+
+ # Add Roomaji too
+ if foreign_name.language.name == 'Japanese':
+ roomaji = romanize(foreign_name.name)
+ writer.add_document(name=roomaji.lower(),
+ language='Roomaji',
+ display_name=roomaji,
+ **row_key)
+ speller_entries.append((roomaji.lower(), 8))