|
31 | 31 |
|
32 | 32 | package org.opensearch.common.lucene;
|
33 | 33 |
|
| 34 | +import org.apache.lucene.document.LatLonPoint; |
| 35 | +import org.apache.lucene.index.IndexCommit; |
34 | 36 | import org.apache.lucene.index.IndexFormatTooOldException;
|
| 37 | +import org.apache.lucene.index.StandardDirectoryReader; |
35 | 38 | import org.apache.lucene.tests.analysis.MockAnalyzer;
|
36 | 39 | import org.apache.lucene.analysis.core.KeywordAnalyzer;
|
37 | 40 | import org.apache.lucene.document.Document;
|
|
76 | 79 | import org.apache.lucene.util.Bits;
|
77 | 80 | import org.apache.lucene.util.BytesRef;
|
78 | 81 | import org.opensearch.LegacyESVersion;
|
| 82 | +import org.opensearch.Version; |
79 | 83 | import org.opensearch.common.collect.Tuple;
|
80 | 84 | import org.opensearch.common.io.stream.NamedWriteableRegistry;
|
81 | 85 | import org.opensearch.core.internal.io.IOUtils;
|
@@ -372,15 +376,34 @@ public void testNumDocs() throws IOException {
|
372 | 376 | dir.close();
|
373 | 377 | }
|
374 | 378 |
|
375 |
| - public void testReadAnySegmentInfos() throws IOException { |
| 379 | + /** |
| 380 | + * Tests whether old segments are readable and queryable based on the data documented |
| 381 | + * in the README <a href="file:../../../../../resources/indices/bwc/testIndex-6.3.0.md">here</a>. |
| 382 | + * |
| 383 | + * @throws IOException |
| 384 | + */ |
| 385 | + public void testReadSegmentInfosExtendedCompatibility() throws IOException { |
376 | 386 | final String pathToTestIndex = "/indices/bwc/testIndex-6.3.0.zip";
|
| 387 | + final Version minVersion = LegacyESVersion.fromId(6000099); |
377 | 388 | Path tmp = createTempDir();
|
378 | 389 | TestUtil.unzip(getClass().getResourceAsStream(pathToTestIndex), tmp);
|
379 | 390 | MockDirectoryWrapper dir = newMockFSDirectory(tmp);
|
380 | 391 | // The standard API will throw an exception
|
381 | 392 | expectThrows(IndexFormatTooOldException.class, () -> Lucene.readSegmentInfos(dir));
|
382 |
| - SegmentInfos si = Lucene.readSegmentInfosExtendedCompatbility(dir, LegacyESVersion.fromId(6000099)); |
| 393 | + SegmentInfos si = Lucene.readSegmentInfosExtendedCompatibility(dir, minVersion); |
383 | 394 | assertEquals(1, Lucene.getNumDocs(si));
|
| 395 | + IndexCommit indexCommit = Lucene.getIndexCommit(si, dir); |
| 396 | + // uses the "expert" Lucene API |
| 397 | + StandardDirectoryReader reader = (StandardDirectoryReader) DirectoryReader.open( |
| 398 | + indexCommit, |
| 399 | + minVersion.minimumIndexCompatibilityVersion().luceneVersion.major, |
| 400 | + null |
| 401 | + ); |
| 402 | + IndexSearcher searcher = newSearcher(reader); |
| 403 | + // radius too small, should get no results |
| 404 | + assertFalse(Lucene.exists(searcher, LatLonPoint.newDistanceQuery("testLocation", 48.57532, -112.87695, 2))); |
| 405 | + assertTrue(Lucene.exists(searcher, LatLonPoint.newDistanceQuery("testLocation", 48.57532, -112.87695, 20000))); |
| 406 | + reader.close(); |
384 | 407 | dir.close();
|
385 | 408 | }
|
386 | 409 |
|
|
0 commit comments