Reputation: 245
When I run my program, I index the documents each time I run the program in eclipse. However, I want to just index once. Perhaps by deleting the index after each use, but I don't know how to go about doing that.
Upvotes: 0
Views: 1086
Reputation: 33351
Set your IndexWriter to OpenMode.CREATE
. It's probably set to OpenMode.CREATE_OR_APPEND
now. Setting it to CREATE will cause the existing index at the specified directory to be overwritten when you open the indexwriter, to make way for the new one.
Like:
IndexWriterConfig config = new IndexWriterConfig(version, analyzer);
config.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
//etc.....
IndexWriter writer = new IndexWriter(directory, config);
Upvotes: 1