-index_bits = {}
-def get_index(session):
- """Returns (index, speller).
-
- Creates an index if one does not exist.
+# Dictionary of extra keys to file types of objects under, e.g. Pokémon can
+# also be looked up purely by number
+extra_keys = {
+ tables.Move: [
+ lambda row: u"move %d" % row.id,
+ ],
+ tables.Pokemon: [
+ lambda row: unicode(row.id),
+ ],
+}
+
+def open_index(directory=None, session=None, recreate=False):
+ """Opens the whoosh index stored in the named directory and returns (index,
+ speller). If the index doesn't already exist, it will be created.
+
+ `directory`
+ Directory containing the index. Defaults to a location within the
+ `pokedex` egg directory.
+
+ `session`
+ If the index needs to be created, this database session will be used.
+ Defaults to an attempt to connect to the default SQLite database
+ installed by `pokedex setup`.
+
+ `recreate`
+ If set to True, the whoosh index will be created even if it already
+ exists.