0

I have this simple Lucene code:

Directory dir = FSDirectory.open(Paths.get("C:/temp/Lucene"));
Analyzer analyzer = new StandardAnalyzer();
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
writer = new IndexWriter(dir, iwc);

How can I use Exodus Directory in Java instead of the FSDirectory?

Fireburn
  • 981
  • 6
  • 20

1 Answers1

2

ExodusDirectory should be used atop of ContextualEnvironment:

ContextualEnvironment env = Environments.newContextualInstance(..);
ExodusDirectory dir = new ExodusDirectory(env, VfsConfig.DEFAULT, StoreConfig.WITHOUT_DUPLICATES_WITH_PREFIXING, new ExodusDirectoryConfig());
Analyzer analyzer = new StandardAnalyzer();
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
writer = env.computeInTransaction(txn -> {
            try {
                return new IndexWriter(dir, iwc);
            } catch (IOException e) {
                return null;
            }
        });

Configuration parameters of ExodusDirectory can tuned, but StoreConfig.WITHOUT_DUPLICATES_WITH_PREFIXING is preferable for using.

Vyacheslav Lukianov
  • 1,913
  • 8
  • 12
  • Are you suggesting that the lucene index operations do not need to be done in a transaction? Or that it needs another transaction at a later time for read and/or write? – Vin Jan 01 '21 at 07:19
  • Method `computeInTransaction` does create a transaction and executes an action in it. Any write operation requires a R/W transaction. Searching in the index can be performed in a read-only transaction. – Vyacheslav Lukianov Jan 02 '21 at 12:45