- name = row.name.lower()
- spelling_name = re.sub('[^a-z]', '', name)
- writer.add_document(name=name,
- spelling_name=spelling_name,
- table=cls.__tablename__,
- row_id=row.id)
+ # XXX need to give forme_name a dummy value because I can't search
+ # for explicitly empty fields. boo.
+ row_key = dict(table=unicode(cls.__tablename__),
+ row_id=unicode(row.id),
+ forme_name=u'XXX')
+
+ # If this is a form, mark it as such
+ if getattr(row, 'forme_base_pokemon_id', None):
+ row_key['forme_name'] = row.forme_name
+
+ 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))
+