+ # Attempt to open or create the index
+ directory_exists = os.path.exists(directory)
+ if directory_exists and not recreate:
+ # Already exists; should be an index!
+ try:
+ index = whoosh.index.open_dir(directory, indexname='pokedex')
+ speller = whoosh.index.open_dir(directory, indexname='spelling')
+ return index, speller
+ except whoosh.index.EmptyIndexError as e:
+ # Apparently not a real index. Fall out of the if and create it
+ pass
+
+ if not directory_exists:
+ os.mkdir(directory)
+
+
+ # Create index