diff --git a/pom.xml b/pom.xml index 0194170d826..594b118bb88 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ 5.1.0 - 5.1.0-snapshot-1660560 + 5.1.0-snapshot-1662607 auto true onerror @@ -56,7 +56,7 @@ lucene-snapshots Lucene Snapshots - https://download.elasticsearch.org/lucenesnapshots/1660560 + https://download.elasticsearch.org/lucenesnapshots/1662607 diff --git a/src/main/java/org/apache/lucene/search/postingshighlight/XPostingsHighlighter.java b/src/main/java/org/apache/lucene/search/postingshighlight/XPostingsHighlighter.java index 78af23446d2..988f707cefc 100644 --- a/src/main/java/org/apache/lucene/search/postingshighlight/XPostingsHighlighter.java +++ b/src/main/java/org/apache/lucene/search/postingshighlight/XPostingsHighlighter.java @@ -61,7 +61,14 @@ public class XPostingsHighlighter { // unnecessary. /** for rewriting: we don't want slow processing from MTQs */ - private static final IndexReader EMPTY_INDEXREADER = new MultiReader(); + private static final IndexReader EMPTY_INDEXREADER; + static { + try { + EMPTY_INDEXREADER = new MultiReader(); + } catch (IOException bogus) { + throw new RuntimeException(bogus); + } + } /** Default maximum content size to process. Typically snippets * closer to the beginning of the document better summarize its content */ diff --git a/src/main/java/org/elasticsearch/common/lucene/Lucene.java b/src/main/java/org/elasticsearch/common/lucene/Lucene.java index 7c7eb9e3ff0..4b4c3cd8b89 100644 --- a/src/main/java/org/elasticsearch/common/lucene/Lucene.java +++ b/src/main/java/org/elasticsearch/common/lucene/Lucene.java @@ -705,22 +705,6 @@ public class Lucene { public int nextDoc() throws IOException { throw new ElasticsearchIllegalStateException(message); } - @Override - public int nextPosition() throws IOException { - throw new ElasticsearchIllegalStateException(message); - } - @Override - public int startOffset() throws IOException { - throw new ElasticsearchIllegalStateException(message); - } - @Override - public int endOffset() throws IOException { - throw new ElasticsearchIllegalStateException(message); - } - @Override - public BytesRef getPayload() throws IOException { - throw new ElasticsearchIllegalStateException(message); - } }; } diff --git a/src/main/java/org/elasticsearch/common/lucene/index/ElasticsearchDirectoryReader.java b/src/main/java/org/elasticsearch/common/lucene/index/ElasticsearchDirectoryReader.java index 01bf0252e6f..e566f510f4d 100644 --- a/src/main/java/org/elasticsearch/common/lucene/index/ElasticsearchDirectoryReader.java +++ b/src/main/java/org/elasticsearch/common/lucene/index/ElasticsearchDirectoryReader.java @@ -24,6 +24,8 @@ import org.apache.lucene.index.FilterLeafReader; import org.apache.lucene.index.LeafReader; import org.elasticsearch.index.shard.ShardId; +import java.io.IOException; + /** * A {@link org.apache.lucene.index.FilterDirectoryReader} that exposes * Elasticsearch internal per shard / index information like the shard ID. @@ -33,7 +35,7 @@ public final class ElasticsearchDirectoryReader extends FilterDirectoryReader { private final ShardId shardId; private final FilterDirectoryReader.SubReaderWrapper wrapper; - private ElasticsearchDirectoryReader(DirectoryReader in, FilterDirectoryReader.SubReaderWrapper wrapper, ShardId shardId) { + private ElasticsearchDirectoryReader(DirectoryReader in, FilterDirectoryReader.SubReaderWrapper wrapper, ShardId shardId) throws IOException { super(in, wrapper); this.wrapper = wrapper; this.shardId = shardId; @@ -47,7 +49,7 @@ public final class ElasticsearchDirectoryReader extends FilterDirectoryReader { } @Override - protected DirectoryReader doWrapDirectoryReader(DirectoryReader in) { + protected DirectoryReader doWrapDirectoryReader(DirectoryReader in) throws IOException { return new ElasticsearchDirectoryReader(in, wrapper, shardId); } @@ -59,7 +61,7 @@ public final class ElasticsearchDirectoryReader extends FilterDirectoryReader { * @param reader the reader to wrap * @param shardId the shard ID to expose via the elasticsearch internal reader wrappers. */ - public static ElasticsearchDirectoryReader wrap(DirectoryReader reader, ShardId shardId) { + public static ElasticsearchDirectoryReader wrap(DirectoryReader reader, ShardId shardId) throws IOException { return new ElasticsearchDirectoryReader(reader, new SubReaderWrapper(shardId), shardId); } diff --git a/src/main/java/org/elasticsearch/common/lucene/search/EmptyScorer.java b/src/main/java/org/elasticsearch/common/lucene/search/EmptyScorer.java index 856209ea4c2..836c7fdecce 100644 --- a/src/main/java/org/elasticsearch/common/lucene/search/EmptyScorer.java +++ b/src/main/java/org/elasticsearch/common/lucene/search/EmptyScorer.java @@ -65,24 +65,4 @@ public class EmptyScorer extends Scorer { public long cost() { return 0; } - - @Override - public int nextPosition() throws IOException { - return -1; - } - - @Override - public int startOffset() throws IOException { - return -1; - } - - @Override - public int endOffset() throws IOException { - return -1; - } - - @Override - public BytesRef getPayload() throws IOException { - return null; - } } diff --git a/src/main/java/org/elasticsearch/common/lucene/search/function/CustomBoostFactorScorer.java b/src/main/java/org/elasticsearch/common/lucene/search/function/CustomBoostFactorScorer.java index 6ef01bdceb2..b4ddaf2acf8 100644 --- a/src/main/java/org/elasticsearch/common/lucene/search/function/CustomBoostFactorScorer.java +++ b/src/main/java/org/elasticsearch/common/lucene/search/function/CustomBoostFactorScorer.java @@ -82,28 +82,6 @@ abstract class CustomBoostFactorScorer extends Scorer { return scorer.cost(); } - @Override - public int nextPosition() throws IOException { - return scorer.nextPosition(); - } - - @Override - public int startOffset() throws IOException { - return scorer.startOffset(); - } - - @Override - public int endOffset() throws IOException { - return scorer.endOffset(); - } - - @Override - public BytesRef getPayload() throws IOException { - return scorer.getPayload(); - } - - - public interface NextDoc { public int advance(int target) throws IOException; diff --git a/src/main/java/org/elasticsearch/common/lucene/search/function/ScriptScoreFunction.java b/src/main/java/org/elasticsearch/common/lucene/search/function/ScriptScoreFunction.java index 4b8579eac1b..c1ad415fdf4 100644 --- a/src/main/java/org/elasticsearch/common/lucene/search/function/ScriptScoreFunction.java +++ b/src/main/java/org/elasticsearch/common/lucene/search/function/ScriptScoreFunction.java @@ -65,26 +65,6 @@ public class ScriptScoreFunction extends ScoreFunction { throw new UnsupportedOperationException(); } - @Override - public int nextPosition() throws IOException { - return -1; - } - - @Override - public int startOffset() throws IOException { - return -1; - } - - @Override - public int endOffset() throws IOException { - return -1; - } - - @Override - public BytesRef getPayload() throws IOException { - return null; - } - @Override public long cost() { return 1; diff --git a/src/main/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQuery.java b/src/main/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQuery.java index 40b6036a389..6cda9c9fa3c 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQuery.java @@ -87,7 +87,9 @@ public class ChildrenConstantScoreQuery extends Query { @Override public void extractTerms(Set terms) { - rewrittenChildQuery.extractTerms(terms); + if (rewrittenChildQuery != null) { + rewrittenChildQuery.extractTerms(terms); + } } @Override diff --git a/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java b/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java index 77afcef4029..cf0d555b301 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java @@ -394,6 +394,11 @@ public class ChildrenQuery extends Query { this.scores = this.bigArrays.newFloatArray(512, false); } + @Override + public boolean needsScores() { + return true; + } + @Override protected void newParent(long parentIdx) throws IOException { scores = bigArrays.grow(scores, parentIdx + 1); @@ -642,26 +647,6 @@ public class ChildrenQuery extends Query { public long cost() { return parentsIterator.cost(); } - - @Override - public int nextPosition() throws IOException { - return -1; - } - - @Override - public int startOffset() throws IOException { - return -1; - } - - @Override - public int endOffset() throws IOException { - return -1; - } - - @Override - public BytesRef getPayload() throws IOException { - return null; - } } private static class ParentCountScorer extends ParentScorer { diff --git a/src/main/java/org/elasticsearch/index/search/child/ConstantScorer.java b/src/main/java/org/elasticsearch/index/search/child/ConstantScorer.java index 17976c79aca..b5789cff6c5 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ConstantScorer.java +++ b/src/main/java/org/elasticsearch/index/search/child/ConstantScorer.java @@ -74,24 +74,4 @@ public class ConstantScorer extends Scorer { public long cost() { return docIdSetIterator.cost(); } - - @Override - public int nextPosition() throws IOException { - return -1; - } - - @Override - public int startOffset() throws IOException { - return -1; - } - - @Override - public int endOffset() throws IOException { - return -1; - } - - @Override - public BytesRef getPayload() throws IOException { - return null; - } } \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java b/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java index 0e541e0bb80..d180b25645f 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java @@ -344,25 +344,5 @@ public class ParentQuery extends Query { public long cost() { return childrenIterator.cost(); } - - @Override - public int nextPosition() throws IOException { - return -1; - } - - @Override - public int startOffset() throws IOException { - return -1; - } - - @Override - public int endOffset() throws IOException { - return -1; - } - - @Override - public BytesRef getPayload() throws IOException { - return null; - } } } diff --git a/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java b/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java index 02c789e3b7d..e75878ca94e 100644 --- a/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java @@ -416,26 +416,6 @@ public class TopChildrenQuery extends Query { public final long cost() { return docs.length; } - - @Override - public int nextPosition() throws IOException { - return -1; - } - - @Override - public int startOffset() throws IOException { - return -1; - } - - @Override - public int endOffset() throws IOException { - return -1; - } - - @Override - public BytesRef getPayload() throws IOException { - return null; - } } private static class ParentDocComparator implements Comparator { diff --git a/src/main/java/org/elasticsearch/index/search/nested/IncludeNestedDocsQuery.java b/src/main/java/org/elasticsearch/index/search/nested/IncludeNestedDocsQuery.java index 527cb810c7a..3918c6c687d 100644 --- a/src/main/java/org/elasticsearch/index/search/nested/IncludeNestedDocsQuery.java +++ b/src/main/java/org/elasticsearch/index/search/nested/IncludeNestedDocsQuery.java @@ -235,26 +235,6 @@ public class IncludeNestedDocsQuery extends Query { return parentScorer.freq(); } - @Override - public int nextPosition() throws IOException { - return parentScorer.nextPosition(); - } - - @Override - public int startOffset() throws IOException { - return parentScorer.startOffset(); - } - - @Override - public int endOffset() throws IOException { - return parentScorer.endOffset(); - } - - @Override - public BytesRef getPayload() throws IOException { - return parentScorer.getPayload(); - } - @Override public int docID() { return currentDoc; diff --git a/src/main/java/org/elasticsearch/percolator/MultiDocumentPercolatorIndex.java b/src/main/java/org/elasticsearch/percolator/MultiDocumentPercolatorIndex.java index 1e626fc669a..618703af3aa 100644 --- a/src/main/java/org/elasticsearch/percolator/MultiDocumentPercolatorIndex.java +++ b/src/main/java/org/elasticsearch/percolator/MultiDocumentPercolatorIndex.java @@ -68,8 +68,8 @@ class MultiDocumentPercolatorIndex implements PercolatorIndex { Analyzer analyzer = context.mapperService().documentMapper(parsedDocument.type()).mappers().indexAnalyzer(); memoryIndices[i] = indexDoc(d, analyzer, memoryIndex).createSearcher().getIndexReader(); } - MultiReader mReader = new MultiReader(memoryIndices, true); try { + MultiReader mReader = new MultiReader(memoryIndices, true); LeafReader slowReader = SlowCompositeReaderWrapper.wrap(mReader); DocSearcher docSearcher = new DocSearcher(new IndexSearcher(slowReader), rootDocMemoryIndex); context.initialize(docSearcher, parsedDocument); diff --git a/src/main/java/org/elasticsearch/percolator/QueryCollector.java b/src/main/java/org/elasticsearch/percolator/QueryCollector.java index 204f19db202..2653c2de1b7 100644 --- a/src/main/java/org/elasticsearch/percolator/QueryCollector.java +++ b/src/main/java/org/elasticsearch/percolator/QueryCollector.java @@ -223,6 +223,11 @@ abstract class QueryCollector extends SimpleCollector { topDocsCollector = TopScoreDocCollector.create(context.size()); } + @Override + public boolean needsScores() { + return super.needsScores() || topDocsCollector.needsScores(); + } + @Override public void collect(int doc) throws IOException { final Query query = getQuery(doc); @@ -286,6 +291,11 @@ abstract class QueryCollector extends SimpleCollector { this.highlightPhase = highlightPhase; } + @Override + public boolean needsScores() { + return true; + } + @Override public void collect(int doc) throws IOException { final Query query = getQuery(doc); diff --git a/src/main/java/org/elasticsearch/search/lookup/IndexFieldTerm.java b/src/main/java/org/elasticsearch/search/lookup/IndexFieldTerm.java index 92dca06c231..1a63f4784c6 100644 --- a/src/main/java/org/elasticsearch/search/lookup/IndexFieldTerm.java +++ b/src/main/java/org/elasticsearch/search/lookup/IndexFieldTerm.java @@ -20,6 +20,7 @@ package org.elasticsearch.search.lookup; import org.apache.lucene.index.*; +import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.TermStatistics; import org.apache.lucene.util.BytesRef; import org.elasticsearch.ElasticsearchException; @@ -51,8 +52,6 @@ public class IndexFieldTerm implements Iterable { private final TermStatistics termStats; - static private EmptyScorer EMPTY_SCORER = new EmptyScorer(null); - // get the document frequency of the term public long df() throws IOException { return termStats.docFreq(); @@ -129,7 +128,53 @@ public class IndexFieldTerm implements Iterable { } if (postings == null) { - postings = EMPTY_SCORER; + final DocIdSetIterator empty = DocIdSetIterator.empty(); + postings = new PostingsEnum() { + @Override + public int docID() { + return empty.docID(); + } + + @Override + public int nextDoc() throws IOException { + return empty.nextDoc(); + } + + @Override + public int advance(int target) throws IOException { + return empty.advance(target); + } + + @Override + public long cost() { + return empty.cost(); + } + + @Override + public int freq() throws IOException { + return 1; + } + + @Override + public int nextPosition() throws IOException { + return -1; + } + + @Override + public int startOffset() throws IOException { + return -1; + } + + @Override + public int endOffset() throws IOException { + return -1; + } + + @Override + public BytesRef getPayload() throws IOException { + return null; + } + }; } } catch (IOException e) { diff --git a/src/test/java/org/elasticsearch/index/search/child/MockScorer.java b/src/test/java/org/elasticsearch/index/search/child/MockScorer.java index 6f8874e0a1e..2eecbceaa51 100644 --- a/src/test/java/org/elasticsearch/index/search/child/MockScorer.java +++ b/src/test/java/org/elasticsearch/index/search/child/MockScorer.java @@ -99,24 +99,4 @@ class MockScorer extends Scorer { public long cost() { return 0; } - - @Override - public int nextPosition() throws IOException { - return -1; - } - - @Override - public int startOffset() throws IOException { - return -1; - } - - @Override - public int endOffset() throws IOException { - return -1; - } - - @Override - public BytesRef getPayload() throws IOException { - return null; - } } diff --git a/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerTests.java b/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerTests.java index 6139727f0d6..a15e9c67aa6 100644 --- a/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerTests.java +++ b/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerTests.java @@ -261,13 +261,13 @@ public class RandomExceptionCircuitBreakerTests extends ElasticsearchIntegration } - public RandomExceptionDirectoryReaderWrapper(DirectoryReader in, Settings settings) { + public RandomExceptionDirectoryReaderWrapper(DirectoryReader in, Settings settings) throws IOException { super(in, new ThrowingSubReaderWrapper(settings)); this.settings = settings; } @Override - protected DirectoryReader doWrapDirectoryReader(DirectoryReader in) { + protected DirectoryReader doWrapDirectoryReader(DirectoryReader in) throws IOException { return new RandomExceptionDirectoryReaderWrapper(in, settings); } } diff --git a/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsTests.java b/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsTests.java index bad491167f3..15b5c6440c6 100644 --- a/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsTests.java +++ b/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsTests.java @@ -359,13 +359,13 @@ public class SearchWithRandomExceptionsTests extends ElasticsearchIntegrationTes } } - public RandomExceptionDirectoryReaderWrapper(DirectoryReader in, Settings settings) { + public RandomExceptionDirectoryReaderWrapper(DirectoryReader in, Settings settings) throws IOException { super(in, new ThrowingSubReaderWrapper(settings)); this.settings = settings; } @Override - protected DirectoryReader doWrapDirectoryReader(DirectoryReader in) { + protected DirectoryReader doWrapDirectoryReader(DirectoryReader in) throws IOException { return new RandomExceptionDirectoryReaderWrapper(in, settings); } } diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchLuceneTestCase.java b/src/test/java/org/elasticsearch/test/ElasticsearchLuceneTestCase.java index d7e011d4128..7a83b4df6c9 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchLuceneTestCase.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchLuceneTestCase.java @@ -24,6 +24,7 @@ import com.carrotsearch.randomizedtesting.annotations.*; import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope; import org.apache.lucene.codecs.Codec; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util.LuceneTestCase.SuppressFileSystems; import org.apache.lucene.util.TimeUnits; import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter; @@ -38,6 +39,7 @@ import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter; @ThreadLeakLingering(linger = 5000) // 5 sec lingering @TimeoutSuite(millis = TimeUnits.HOUR) @LuceneTestCase.SuppressSysoutChecks(bugUrl = "we log a lot on purpose") +@SuppressFileSystems("ExtrasFS") // we aren't ready for this yet. public abstract class ElasticsearchLuceneTestCase extends LuceneTestCase { private static final Codec DEFAULT_CODEC = Codec.getDefault(); diff --git a/src/test/java/org/elasticsearch/test/engine/MockInternalEngine.java b/src/test/java/org/elasticsearch/test/engine/MockInternalEngine.java index 037b4ea0dc7..fd6698c26e4 100644 --- a/src/test/java/org/elasticsearch/test/engine/MockInternalEngine.java +++ b/src/test/java/org/elasticsearch/test/engine/MockInternalEngine.java @@ -162,7 +162,7 @@ public class MockInternalEngine extends InternalEngine { public static abstract class DirectoryReaderWrapper extends FilterDirectoryReader { protected final SubReaderWrapper subReaderWrapper; - public DirectoryReaderWrapper(DirectoryReader in, SubReaderWrapper subReaderWrapper) { + public DirectoryReaderWrapper(DirectoryReader in, SubReaderWrapper subReaderWrapper) throws IOException { super(in, subReaderWrapper); this.subReaderWrapper = subReaderWrapper; }