If I understand you right, you have a dilemma in finding a good way to
handle when to create and when to reuse a directory.

I use a simple scheme. If the index directory already exist, I assume
it has a valid index. Otherwise a new index is created. If I want to
rebuild the index, I simply delete the directory from shell. Here is
my code sniplet:


def initDirectory(pathname=None):
    """ pathname - index directory. Create new index if directory
        does not exist. '' or None for RAMDirectory (for testing).
    """
    if not pathname:
        directory = PyLucene.RAMDirectory()
        # initialize the new directory
        writer = PyLucene.IndexWriter(directory,
PyLucene.StandardAnalyzer(), True)
        writer.close()

    elif not os.path.exists(pathname):
        directory = PyLucene.FSDirectory.getDirectory(pathname, True)
        # initialize the new directory
        writer = PyLucene.IndexWriter(directory,
PyLucene.StandardAnalyzer(), True)
        writer.close()

    else:
        directory = PyLucene.FSDirectory.getDirectory(pathname, False)

    return directory
_______________________________________________
pylucene-dev mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev

Reply via email to