'Opens the whoosh index stored in the named directory.  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`
Used for creating the index and retrieving objects.  Defaults to an
attempt to connect to the default SQLite database installed by
`pokedex setup`.'

def __init__(self, directory=None, session=None):

    if (directory is None):
        directory = get_default_index_dir()
    self.directory = directory
    if session:
        self.session = session
    else:
        self.session = connect()
    if ((not os.path.exists(directory)) or (not os.listdir(directory))):
        self.index = UninitializedIndex()
        return
    try:
        self.index = whoosh.index.open_dir(directory, indexname='MAIN')
    except whoosh.index.EmptyIndexError:
        raise IOError('The    index    directory    already    contains    files.        Please    use    a    dedicated    directory    for    the    lookup    index.')
