79230114

Date: 2024-11-27 11:47:17
Score: 0.5
Natty:
Report link

If it is only reading, it should be possible, assuming you have the lucene-backwards-codecs in your classpath.

Directory directory = FSDirectory.open(Paths.get(INDEX_PATH));
IndexCommit commit = DirectoryReader.listCommits(directory).getLast();
DirectoryReader reader = DirectoryReader.open(commit, 0, null);

The 0 is the minimum major version to check against. It is better to know which version of Lucene made the index and use that, but 0 is a catch-all.

If things have changed too much, there isn't a guarantee that you can read the index. Lucene only officially supports N-1 codecs, but this method is specifically for this case. Annoyingly, there isn't an IndexWriter equivalent to lazily reading in the very old and writing in the new.

https://lucene.apache.org/core/10_0_0/core/org/apache/lucene/index/DirectoryReader.html#listCommits(org.apache.lucene.store.Directory)

https://lucene.apache.org/core/10_0_0/core/org/apache/lucene/index/DirectoryReader.html#open(org.apache.lucene.index.IndexCommit,int,java.util.Comparator)

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: parnmatt