From 858de86e0f7abf2bfc091032c9ba6f9a6bd35609 Mon Sep 17 00:00:00 2001 From: Johannes Baiter Date: Mon, 15 Jan 2024 09:44:43 +0100 Subject: [PATCH] Fix compatibility with Solr 9.4 and Lucene 9.8 --- integration-tests/run.sh | 2 +- pom.xml | 4 +- .../reader/LegacyBaseCompositeReader.java | 42 +++++++++++++++++-- .../dbmdz/solrocr/util/HighlightTimeout.java | 1 - 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/integration-tests/run.sh b/integration-tests/run.sh index 71fce4c4..5bf4e342 100755 --- a/integration-tests/run.sh +++ b/integration-tests/run.sh @@ -4,7 +4,7 @@ SOLR_HOST="${SOLR_HOST:-localhost}" SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" SOLR7_VERSIONS="7.7 7.6 7.5" SOLR8_VERSIONS="8.11 8.10 8.9 8.8 8.7 8.6 8.5 8.4 8.3 8.2 8.1 8.0" -SOLR9_VERSIONS="9.2 9.1 9.0" +SOLR9_VERSIONS="9.4 9.3 9.2 9.1 9.0" SOLR78_PLUGIN_PATH=/tmp/solrocr-solr78 wait_for_solr() { diff --git a/pom.xml b/pom.xml index 17940ea4..1b329dcb 100644 --- a/pom.xml +++ b/pom.xml @@ -56,8 +56,8 @@ 5.10.1 5.8.0 2.0.2 - 9.2.1 - 9.4.2 + 9.4.0 + 9.8.0 2.9.1 3.1.0 diff --git a/src/main/java/com/github/dbmdz/solrocr/reader/LegacyBaseCompositeReader.java b/src/main/java/com/github/dbmdz/solrocr/reader/LegacyBaseCompositeReader.java index aed38822..70b2e7c3 100644 --- a/src/main/java/com/github/dbmdz/solrocr/reader/LegacyBaseCompositeReader.java +++ b/src/main/java/com/github/dbmdz/solrocr/reader/LegacyBaseCompositeReader.java @@ -27,7 +27,9 @@ import org.apache.lucene.index.MultiReader; import org.apache.lucene.index.ReaderUtil; import org.apache.lucene.index.StoredFieldVisitor; +import org.apache.lucene.index.StoredFields; import org.apache.lucene.index.Term; +import org.apache.lucene.index.TermVectors; /** * Base class for implementing {@link CompositeReader}s based on an array of sub-readers. The @@ -48,8 +50,8 @@ * synchronization, you should not synchronize on the IndexReader instance; use * your own (non-Lucene) objects instead. * - *

NOTE: This is a backport from Lucene 8.8 since the API changed with v8.9, but we still - * want to support earlier versions. + *

NOTE: This is a backport from Lucene 9.8 since the API changed with v8.9 and 9.8, but + * we still want to support earlier versions. * * @see MultiReader * @lucene.internal @@ -74,7 +76,7 @@ public abstract class LegacyBaseCompositeReader extends C * methods. Please note: This array is not cloned and not protected for * modification, the subclass is responsible to do this. */ - protected LegacyBaseCompositeReader(R[] subReaders) throws IOException { + protected LegacyBaseCompositeReader(R[] subReaders) { this.subReaders = subReaders; this.subReadersList = Collections.unmodifiableList(Arrays.asList(subReaders)); starts = new int[subReaders.length + 1]; // build starts array @@ -97,6 +99,40 @@ public final Fields getTermVectors(int docID) throws IOException { return subReaders[i].getTermVectors(docID - starts[i]); // dispatch to subreader } + @Override + public final TermVectors termVectors() throws IOException { + ensureOpen(); + TermVectors[] subVectors = new TermVectors[subReaders.length]; + return new TermVectors() { + @Override + public Fields get(int docID) throws IOException { + final int i = readerIndex(docID); // find subreader num + // dispatch to subreader, reusing if possible + if (subVectors[i] == null) { + subVectors[i] = subReaders[i].termVectors(); + } + return subVectors[i].get(docID - starts[i]); + } + }; + } + + @Override + public final StoredFields storedFields() throws IOException { + ensureOpen(); + StoredFields[] subFields = new StoredFields[subReaders.length]; + return new StoredFields() { + @Override + public void document(int docID, StoredFieldVisitor visitor) throws IOException { + final int i = readerIndex(docID); // find subreader num + // dispatch to subreader, reusing if possible + if (subFields[i] == null) { + subFields[i] = subReaders[i].storedFields(); + } + subFields[i].document(docID - starts[i], visitor); + } + }; + } + @Override public final int numDocs() { // Don't call ensureOpen() here (it could affect performance) diff --git a/src/main/java/com/github/dbmdz/solrocr/util/HighlightTimeout.java b/src/main/java/com/github/dbmdz/solrocr/util/HighlightTimeout.java index a9af4c0a..e251f7c0 100644 --- a/src/main/java/com/github/dbmdz/solrocr/util/HighlightTimeout.java +++ b/src/main/java/com/github/dbmdz/solrocr/util/HighlightTimeout.java @@ -36,7 +36,6 @@ public boolean shouldExit() { return timeoutAt - System.nanoTime() < 0L; } - @Override public boolean isTimeoutEnabled() { return get() != null; }