diff --git a/pom.xml b/pom.xml index aab1e0bc7a3..01b5593f0af 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ - 4.4.0 + 4.5.0 1 true onerror diff --git a/src/main/java/org/apache/lucene/queries/ExtendedCommonTermsQuery.java b/src/main/java/org/apache/lucene/queries/ExtendedCommonTermsQuery.java index c045f49a3e5..19649f85b96 100644 --- a/src/main/java/org/apache/lucene/queries/ExtendedCommonTermsQuery.java +++ b/src/main/java/org/apache/lucene/queries/ExtendedCommonTermsQuery.java @@ -19,12 +19,9 @@ package org.apache.lucene.queries; */ import org.apache.lucene.index.Term; import org.apache.lucene.index.TermContext; -import org.apache.lucene.search.BooleanClause; +import org.apache.lucene.search.*; import org.apache.lucene.search.BooleanClause.Occur; -import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TermQuery; - +import org.elasticsearch.Version; import org.elasticsearch.common.lucene.search.Queries; /** @@ -57,6 +54,7 @@ public class ExtendedCommonTermsQuery extends CommonTermsQuery { return Queries.calculateMinShouldMatch(numOptional, spec); } + @Override protected int calcHighFreqMinimumNumberShouldMatch(int numOptional) { return calcMinimumNumberShouldMatch(highFreqMinNumShouldMatchSpec, numOptional); } @@ -65,7 +63,7 @@ public class ExtendedCommonTermsQuery extends CommonTermsQuery { this.highFreqMinNumShouldMatchSpec = spec; } - public String getHighFreqMinimumNumberShouldMatch() { + public String getHighFreqMinimumNumberShouldMatchSpec() { return highFreqMinNumShouldMatchSpec; } @@ -73,66 +71,73 @@ public class ExtendedCommonTermsQuery extends CommonTermsQuery { this.lowFreqMinNumShouldMatchSpec = spec; } - public String getLowFreqMinimumNumberShouldMatch() { + public String getLowFreqMinimumNumberShouldMatchSpec() { return lowFreqMinNumShouldMatchSpec; } - + + static { + assert Version.CURRENT.luceneVersion.compareTo(org.apache.lucene.util.Version.LUCENE_45) == 0 : "Remove buildQuery() once 4.6 is out"; + } @Override - protected Query buildQuery(final int maxDoc, final TermContext[] contextArray, final Term[] queryTerms) { - BooleanQuery lowFreq = new BooleanQuery(disableCoord); - BooleanQuery highFreq = new BooleanQuery(disableCoord); - highFreq.setBoost(highFreqBoost); - lowFreq.setBoost(lowFreqBoost); - BooleanQuery query = new BooleanQuery(true); - - for (int i = 0; i < queryTerms.length; i++) { + protected Query buildQuery(final int maxDoc, + final TermContext[] contextArray, final Term[] queryTerms) { + BooleanQuery lowFreq = new BooleanQuery(disableCoord); + BooleanQuery highFreq = new BooleanQuery(disableCoord); + highFreq.setBoost(highFreqBoost); + lowFreq.setBoost(lowFreqBoost); + BooleanQuery query = new BooleanQuery(true); + for (int i = 0; i < queryTerms.length; i++) { TermContext termContext = contextArray[i]; if (termContext == null) { - lowFreq.add(new TermQuery(queryTerms[i]), lowFreqOccur); + lowFreq.add(new TermQuery(queryTerms[i]), lowFreqOccur); } else { - if ((maxTermFrequency >= 1f && termContext.docFreq() > maxTermFrequency) || (termContext.docFreq() > (int) Math.ceil(maxTermFrequency * (float) maxDoc))) { - highFreq.add(new TermQuery(queryTerms[i], termContext), highFreqOccur); - } else { - lowFreq.add(new TermQuery(queryTerms[i], termContext), lowFreqOccur); - } + if ((maxTermFrequency >= 1f && termContext.docFreq() > maxTermFrequency) + || (termContext.docFreq() > (int) Math.ceil(maxTermFrequency + * (float) maxDoc))) { + highFreq + .add(new TermQuery(queryTerms[i], termContext), highFreqOccur); + } else { + lowFreq.add(new TermQuery(queryTerms[i], termContext), lowFreqOccur); + } } - } - - final int numLowFreqClauses = lowFreq.clauses().size(), - numHighFreqClauses = highFreq.clauses().size(); - - if (lowFreqOccur == Occur.SHOULD && numLowFreqClauses > 0) { + + } + final int numLowFreqClauses = lowFreq.clauses().size(); + final int numHighFreqClauses = highFreq.clauses().size(); + if (lowFreqOccur == Occur.SHOULD && numLowFreqClauses > 0) { int minMustMatch = calcLowFreqMinimumNumberShouldMatch(numLowFreqClauses); lowFreq.setMinimumNumberShouldMatch(minMustMatch); - } - - if (highFreqOccur == Occur.SHOULD && numHighFreqClauses > 0) { + } + + if (highFreqOccur == Occur.SHOULD && numHighFreqClauses > 0) { int minMustMatch = calcHighFreqMinimumNumberShouldMatch(numHighFreqClauses); highFreq.setMinimumNumberShouldMatch(minMustMatch); - } - - if (lowFreq.clauses().isEmpty()) { - /* - * if lowFreq is empty we rewrite the high freq terms in a conjunction to - * prevent slow queries. - * Only if a specic high_freq should_match is not specified. - */ - if (highFreqMinNumShouldMatchSpec == null && highFreqOccur != Occur.MUST) { - for (BooleanClause booleanClause : highFreq) { - booleanClause.setOccur(Occur.MUST); - } - } - highFreq.setBoost(getBoost()); - return highFreq; - } else if (highFreq.clauses().isEmpty()) { + } + + if (lowFreq.clauses().isEmpty()) { + /* + * if lowFreq is empty we rewrite the high freq terms in a conjunction to + * prevent slow queries. + * Only if a specic high_freq should_match is not specified. + */ + if (highFreq.getMinimumNumberShouldMatch() == 0 && highFreqOccur != Occur.MUST) { + for (BooleanClause booleanClause : highFreq) { + booleanClause.setOccur(Occur.MUST); + } + } + highFreq.setBoost(getBoost()); + return highFreq; + } else if (highFreq.clauses().isEmpty()) { // only do low freq terms - we don't have high freq terms lowFreq.setBoost(getBoost()); return lowFreq; - } else { + } else { query.add(highFreq, Occur.SHOULD); query.add(lowFreq, Occur.MUST); query.setBoost(getBoost()); return query; + } } - } + + } diff --git a/src/main/java/org/apache/lucene/search/vectorhighlight/CustomFieldQuery.java b/src/main/java/org/apache/lucene/search/vectorhighlight/CustomFieldQuery.java index 5fccc6a8422..cb227a52619 100644 --- a/src/main/java/org/apache/lucene/search/vectorhighlight/CustomFieldQuery.java +++ b/src/main/java/org/apache/lucene/search/vectorhighlight/CustomFieldQuery.java @@ -22,10 +22,10 @@ package org.apache.lucene.search.vectorhighlight; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; import org.apache.lucene.queries.FilterClause; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.search.*; import org.apache.lucene.search.spans.SpanTermQuery; import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery; -import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.lucene.search.XBooleanFilter; import org.elasticsearch.common.lucene.search.XFilteredQuery; import org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery; diff --git a/src/main/java/org/apache/lucene/util/packed/XAbstractAppendingLongBuffer.java b/src/main/java/org/apache/lucene/util/packed/XAbstractAppendingLongBuffer.java deleted file mode 100644 index 6dae600c440..00000000000 --- a/src/main/java/org/apache/lucene/util/packed/XAbstractAppendingLongBuffer.java +++ /dev/null @@ -1,239 +0,0 @@ -package org.apache.lucene.util.packed; - -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.util.ArrayUtil; -import org.apache.lucene.util.RamUsageEstimator; -import org.apache.lucene.util.Version; -import org.elasticsearch.common.lucene.Lucene; - -import java.util.Arrays; - -import static org.apache.lucene.util.packed.PackedInts.checkBlockSize; - -/** - * Common functionality shared by {@link AppendingDeltaPackedLongBuffer} and {@link MonotonicAppendingLongBuffer}. - */ -abstract class XAbstractAppendingLongBuffer { - static { - // LUCENE MONITOR: this should be in Lucene 4.5. - assert Lucene.VERSION == Version.LUCENE_44 : "Elasticsearch has upgraded to Lucene Version: [" + Lucene.VERSION + "] this class should be removed"; - } - - - static final int MIN_PAGE_SIZE = 64; - // More than 1M doesn't really makes sense with these appending buffers - // since their goal is to try to have small numbers of bits per value - static final int MAX_PAGE_SIZE = 1 << 20; - - final int pageShift, pageMask; - PackedInts.Reader[] values; - private long valuesBytes; - int valuesOff; - long[] pending; - int pendingOff; - float acceptableOverheadRatio; - - XAbstractAppendingLongBuffer(int initialBlockCount, int pageSize, float acceptableOverheadRatio) { - values = new PackedInts.Reader[initialBlockCount]; - pending = new long[pageSize]; - pageShift = checkBlockSize(pageSize, MIN_PAGE_SIZE, MAX_PAGE_SIZE); - pageMask = pageSize - 1; - valuesOff = 0; - pendingOff = 0; - this.acceptableOverheadRatio = acceptableOverheadRatio; - } - - final int pageSize() { - return pageMask + 1; - } - - /** - * Get the number of values that have been added to the buffer. - */ - public final long size() { - long size = pendingOff; - if (valuesOff > 0) { - size += values[valuesOff - 1].size(); - } - if (valuesOff > 1) { - size += (long) (valuesOff - 1) * pageSize(); - } - return size; - } - - /** - * Append a value to this buffer. - */ - public final void add(long l) { - if (pending == null) { - throw new IllegalStateException("This buffer is frozen"); - } - if (pendingOff == pending.length) { - // check size - if (values.length == valuesOff) { - final int newLength = ArrayUtil.oversize(valuesOff + 1, 8); - grow(newLength); - } - packPendingValues(); - valuesBytes += values[valuesOff].ramBytesUsed(); - ++valuesOff; - // reset pending buffer - pendingOff = 0; - } - pending[pendingOff++] = l; - } - - void grow(int newBlockCount) { - values = Arrays.copyOf(values, newBlockCount); - } - - abstract void packPendingValues(); - - /** - * Get a value from this buffer. - */ - public final long get(long index) { - assert index >= 0 && index < size(); - final int block = (int) (index >> pageShift); - final int element = (int) (index & pageMask); - return get(block, element); - } - - /** - * Bulk get: read at least one and at most len longs starting - * from index into arr[off:off+len] and return - * the actual number of values that have been read. - */ - public final int get(long index, long[] arr, int off, int len) { - assert len > 0 : "len must be > 0 (got " + len + ")"; - assert index >= 0 && index < size(); - assert off + len <= arr.length; - - int block = (int) (index >> pageShift); - int element = (int) (index & pageMask); - return get(block, element, arr, off, len); - } - - - abstract long get(int block, int element); - - abstract int get(int block, int element, long[] arr, int off, int len); - - - /** - * Return an iterator over the values of this buffer. - */ - public Iterator iterator() { - return new Iterator(); - } - - final public class Iterator { - - long[] currentValues; - int vOff, pOff; - int currentCount; // number of entries of the current page - - Iterator() { - vOff = pOff = 0; - if (valuesOff == 0) { - currentValues = pending; - currentCount = pendingOff; - } else { - currentValues = new long[values[0].size()]; - fillValues(); - } - } - - void fillValues() { - if (vOff == valuesOff) { - currentValues = pending; - currentCount = pendingOff; - } else { - currentCount = values[vOff].size(); - for (int k = 0; k < currentCount; ) { - k += get(vOff, k, currentValues, k, currentCount - k); - } - } - } - - /** - * Whether or not there are remaining values. - */ - public final boolean hasNext() { - return pOff < currentCount; - } - - /** - * Return the next long in the buffer. - */ - public final long next() { - assert hasNext(); - long result = currentValues[pOff++]; - if (pOff == currentCount) { - vOff += 1; - pOff = 0; - if (vOff <= valuesOff) { - fillValues(); - } else { - currentCount = 0; - } - } - return result; - } - - } - - long baseRamBytesUsed() { - return RamUsageEstimator.NUM_BYTES_OBJECT_HEADER - + 2 * RamUsageEstimator.NUM_BYTES_OBJECT_REF // the 2 arrays - + 2 * RamUsageEstimator.NUM_BYTES_INT // the 2 offsets - + 2 * RamUsageEstimator.NUM_BYTES_INT // pageShift, pageMask - + RamUsageEstimator.NUM_BYTES_FLOAT // acceptable overhead - + RamUsageEstimator.NUM_BYTES_LONG; // valuesBytes - } - - /** - * Return the number of bytes used by this instance. - */ - public long ramBytesUsed() { - // TODO: this is called per-doc-per-norms/dv-field, can we optimize this? - long bytesUsed = RamUsageEstimator.alignObjectSize(baseRamBytesUsed()) - + (pending != null ? RamUsageEstimator.sizeOf(pending) : 0L) - + RamUsageEstimator.alignObjectSize(RamUsageEstimator.NUM_BYTES_ARRAY_HEADER + (long) RamUsageEstimator.NUM_BYTES_OBJECT_REF * values.length); // values - - return bytesUsed + valuesBytes; - } - - /** - * Pack all pending values in this buffer. Subsequent calls to {@link #add(long)} will fail. - */ - public void freeze() { - if (pendingOff > 0) { - if (values.length == valuesOff) { - grow(valuesOff + 1); // don't oversize! - } - packPendingValues(); - valuesBytes += values[valuesOff].ramBytesUsed(); - ++valuesOff; - pendingOff = 0; - } - pending = null; - } - -} diff --git a/src/main/java/org/apache/lucene/util/packed/XAppendingPackedLongBuffer.java b/src/main/java/org/apache/lucene/util/packed/XAppendingPackedLongBuffer.java deleted file mode 100644 index 05cc810bd4c..00000000000 --- a/src/main/java/org/apache/lucene/util/packed/XAppendingPackedLongBuffer.java +++ /dev/null @@ -1,107 +0,0 @@ -package org.apache.lucene.util.packed; - -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -import org.apache.lucene.util.Version; -import org.elasticsearch.common.lucene.Lucene; - -/** - * Utility class to buffer a list of signed longs in memory. This class only - * supports appending and is optimized for non-negative numbers with a uniform distribution over a fixed (limited) range - * - * @lucene.internal - */ -public final class XAppendingPackedLongBuffer extends XAbstractAppendingLongBuffer { - - static { - // LUCENE MONITOR: this should be in Lucene 4.5. - assert Lucene.VERSION == Version.LUCENE_44 : "Elasticsearch has upgraded to Lucene Version: [" + Lucene.VERSION + "] this class should be removed"; - } - - - /** - * {@link XAppendingPackedLongBuffer} - * - * @param initialPageCount the initial number of pages - * @param pageSize the size of a single page - * @param acceptableOverheadRatio an acceptable overhead ratio per value - */ - public XAppendingPackedLongBuffer(int initialPageCount, int pageSize, float acceptableOverheadRatio) { - super(initialPageCount, pageSize, acceptableOverheadRatio); - } - - /** - * Create an {@link XAppendingPackedLongBuffer} with initialPageCount=16, - * pageSize=1024 and acceptableOverheadRatio={@link PackedInts#DEFAULT} - */ - public XAppendingPackedLongBuffer() { - this(16, 1024, PackedInts.DEFAULT); - } - - /** - * Create an {@link XAppendingPackedLongBuffer} with initialPageCount=16, - * pageSize=1024 - */ - public XAppendingPackedLongBuffer(float acceptableOverheadRatio) { - this(16, 1024, acceptableOverheadRatio); - } - - @Override - long get(int block, int element) { - if (block == valuesOff) { - return pending[element]; - } else { - return values[block].get(element); - } - } - - @Override - int get(int block, int element, long[] arr, int off, int len) { - if (block == valuesOff) { - int sysCopyToRead = Math.min(len, pendingOff - element); - System.arraycopy(pending, element, arr, off, sysCopyToRead); - return sysCopyToRead; - } else { - /* packed block */ - return values[block].get(element, arr, off, len); - } - } - - @Override - void packPendingValues() { - // compute max delta - long minValue = pending[0]; - long maxValue = pending[0]; - for (int i = 1; i < pendingOff; ++i) { - minValue = Math.min(minValue, pending[i]); - maxValue = Math.max(maxValue, pending[i]); - } - - - // build a new packed reader - final int bitsRequired = minValue < 0 ? 64 : PackedInts.bitsRequired(maxValue); - final PackedInts.Mutable mutable = PackedInts.getMutable(pendingOff, bitsRequired, acceptableOverheadRatio); - for (int i = 0; i < pendingOff; ) { - i += mutable.set(i, pending, i, pendingOff - i); - } - values[valuesOff] = mutable; - - } - -} diff --git a/src/main/java/org/apache/lucene/util/packed/XMonotonicAppendingLongBuffer.java b/src/main/java/org/apache/lucene/util/packed/XMonotonicAppendingLongBuffer.java deleted file mode 100644 index a2a221577b6..00000000000 --- a/src/main/java/org/apache/lucene/util/packed/XMonotonicAppendingLongBuffer.java +++ /dev/null @@ -1,166 +0,0 @@ -package org.apache.lucene.util.packed; - -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.util.RamUsageEstimator; -import org.apache.lucene.util.Version; -import org.elasticsearch.common.lucene.Lucene; - -import java.util.Arrays; - -/** - * Utility class to buffer signed longs in memory, which is optimized for the - * case where the sequence is monotonic, although it can encode any sequence of - * arbitrary longs. It only supports appending. - * - * @lucene.internal - */ -public final class XMonotonicAppendingLongBuffer extends XAbstractAppendingLongBuffer { - static { - // LUCENE MONITOR: this should be in Lucene 4.5. - assert Lucene.VERSION == Version.LUCENE_44 : "Elasticsearch has upgraded to Lucene Version: [" + Lucene.VERSION + "] this class should be removed"; - } - - static long zigZagDecode(long n) { - return ((n >>> 1) ^ -(n & 1)); - } - - static long zigZagEncode(long n) { - return (n >> 63) ^ (n << 1); - } - - float[] averages; - long[] minValues; - - /** - * @param initialPageCount the initial number of pages - * @param pageSize the size of a single page - * @param acceptableOverheadRatio an acceptable overhead ratio per value - */ - public XMonotonicAppendingLongBuffer(int initialPageCount, int pageSize, float acceptableOverheadRatio) { - super(initialPageCount, pageSize, acceptableOverheadRatio); - averages = new float[values.length]; - minValues = new long[values.length]; - } - - /** - * Create an {@link MonotonicAppendingLongBuffer} with initialPageCount=16, - * pageSize=1024 and acceptableOverheadRatio={@link PackedInts#DEFAULT} - */ - public XMonotonicAppendingLongBuffer() { - this(16, 1024, PackedInts.DEFAULT); - } - - /** - * Create an {@link MonotonicAppendingLongBuffer} with initialPageCount=16, - * pageSize=1024 - */ - public XMonotonicAppendingLongBuffer(float acceptableOverheadRatio) { - this(16, 1024, acceptableOverheadRatio); - } - - - @Override - long get(int block, int element) { - if (block == valuesOff) { - return pending[element]; - } else { - final long base = minValues[block] + (long) (averages[block] * (long) element); - if (values[block] == null) { - return base; - } else { - return base + zigZagDecode(values[block].get(element)); - } - } - } - - @Override - int get(int block, int element, long[] arr, int off, int len) { - if (block == valuesOff) { - int sysCopyToRead = Math.min(len, pendingOff - element); - System.arraycopy(pending, element, arr, off, sysCopyToRead); - return sysCopyToRead; - } else { - if (values[block] == null) { - int toFill = Math.min(len, pending.length - element); - for (int r = 0; r < toFill; r++, off++, element++) { - arr[off] = minValues[block] + (long) (averages[block] * (long) element); - } - return toFill; - } else { - - /* packed block */ - int read = values[block].get(element, arr, off, len); - for (int r = 0; r < read; r++, off++, element++) { - arr[off] = minValues[block] + (long) (averages[block] * (long) element) + zigZagDecode(arr[off]); - } - return read; - } - } - } - - @Override - void grow(int newBlockCount) { - super.grow(newBlockCount); - this.averages = Arrays.copyOf(averages, newBlockCount); - this.minValues = Arrays.copyOf(minValues, newBlockCount); - } - - @Override - void packPendingValues() { - assert pendingOff > 0; - minValues[valuesOff] = pending[0]; - averages[valuesOff] = pendingOff == 1 ? 0 : (float) (pending[pendingOff - 1] - pending[0]) / (pendingOff - 1); - - for (int i = 0; i < pendingOff; ++i) { - pending[i] = zigZagEncode(pending[i] - minValues[valuesOff] - (long) (averages[valuesOff] * (long) i)); - } - long maxDelta = 0; - for (int i = 0; i < pendingOff; ++i) { - if (pending[i] < 0) { - maxDelta = -1; - break; - } else { - maxDelta = Math.max(maxDelta, pending[i]); - } - } - if (maxDelta == 0) { - values[valuesOff] = new PackedInts.NullReader(pendingOff); - } else { - final int bitsRequired = maxDelta < 0 ? 64 : PackedInts.bitsRequired(maxDelta); - final PackedInts.Mutable mutable = PackedInts.getMutable(pendingOff, bitsRequired, acceptableOverheadRatio); - for (int i = 0; i < pendingOff; ) { - i += mutable.set(i, pending, i, pendingOff - i); - } - values[valuesOff] = mutable; - } - } - - @Override - long baseRamBytesUsed() { - return super.baseRamBytesUsed() - + 2 * RamUsageEstimator.NUM_BYTES_OBJECT_REF; // 2 additional arrays - } - - @Override - public long ramBytesUsed() { - return super.ramBytesUsed() - + RamUsageEstimator.sizeOf(averages) + RamUsageEstimator.sizeOf(minValues); - } - -} diff --git a/src/main/java/org/elasticsearch/Version.java b/src/main/java/org/elasticsearch/Version.java index 448c37a8787..bd810466cde 100644 --- a/src/main/java/org/elasticsearch/Version.java +++ b/src/main/java/org/elasticsearch/Version.java @@ -136,7 +136,7 @@ public class Version implements Serializable { public static final Version V_0_90_6 = new Version(V_0_90_6_ID, false, org.apache.lucene.util.Version.LUCENE_44); public static final int V_1_0_0_Beta1_ID = /*00*/1000001; - public static final Version V_1_0_0_Beta1 = new Version(V_1_0_0_Beta1_ID, true, org.apache.lucene.util.Version.LUCENE_44); + public static final Version V_1_0_0_Beta1 = new Version(V_1_0_0_Beta1_ID, true, org.apache.lucene.util.Version.LUCENE_45); public static final Version CURRENT = V_1_0_0_Beta1; diff --git a/src/main/java/org/elasticsearch/action/termvector/TermVectorFields.java b/src/main/java/org/elasticsearch/action/termvector/TermVectorFields.java index 72ac9e842c6..3bd8372320c 100644 --- a/src/main/java/org/elasticsearch/action/termvector/TermVectorFields.java +++ b/src/main/java/org/elasticsearch/action/termvector/TermVectorFields.java @@ -284,7 +284,7 @@ public final class TermVectorFields extends Fields { } @Override - public SeekStatus seekCeil(BytesRef text, boolean useCache) throws IOException { + public SeekStatus seekCeil(BytesRef text) throws IOException { throw new UnsupportedOperationException(); } diff --git a/src/main/java/org/elasticsearch/action/termvector/TermVectorWriter.java b/src/main/java/org/elasticsearch/action/termvector/TermVectorWriter.java index 6903abc5c1e..4be5e8094ef 100644 --- a/src/main/java/org/elasticsearch/action/termvector/TermVectorWriter.java +++ b/src/main/java/org/elasticsearch/action/termvector/TermVectorWriter.java @@ -74,7 +74,7 @@ final class TermVectorWriter { // current field // get the doc frequency BytesRef term = iterator.term(); - boolean foundTerm = topLevelIterator.seekExact(term, false); + boolean foundTerm = topLevelIterator.seekExact(term); assert (foundTerm); startTerm(term); if (flags.contains(Flag.TermStatistics)) { diff --git a/src/main/java/org/elasticsearch/common/lucene/Lucene.java b/src/main/java/org/elasticsearch/common/lucene/Lucene.java index 3716932bcde..57c8b55d517 100644 --- a/src/main/java/org/elasticsearch/common/lucene/Lucene.java +++ b/src/main/java/org/elasticsearch/common/lucene/Lucene.java @@ -44,7 +44,7 @@ import java.io.IOException; */ public class Lucene { - public static final Version VERSION = Version.LUCENE_44; + public static final Version VERSION = Version.LUCENE_45; public static final Version ANALYZER_VERSION = VERSION; public static final Version QUERYPARSER_VERSION = VERSION; @@ -60,6 +60,9 @@ public class Lucene { if (version == null) { return defaultVersion; } + if ("4.5".equals(version)) { + return VERSION.LUCENE_45; + } if ("4.4".equals(version)) { return VERSION.LUCENE_44; } diff --git a/src/main/java/org/elasticsearch/common/lucene/docset/DocIdSets.java b/src/main/java/org/elasticsearch/common/lucene/docset/DocIdSets.java index 003840c41d2..b9626b456b7 100644 --- a/src/main/java/org/elasticsearch/common/lucene/docset/DocIdSets.java +++ b/src/main/java/org/elasticsearch/common/lucene/docset/DocIdSets.java @@ -25,9 +25,7 @@ import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.util.Bits; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.OpenBitSetIterator; -import org.apache.lucene.util.Version; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.lucene.Lucene; import java.io.IOException; @@ -35,12 +33,6 @@ import java.io.IOException; */ public class DocIdSets { - static { - // TODO when upgrading to Lucene 4.5. Lucene's CachingWrapperFilter now doesn't use FixedBitSet all the time in favor of - // more memory-efficient implementations. Maybe we should do the same in toCacheable? - assert Version.LUCENE_44.onOrAfter(Lucene.VERSION); - } - public static long sizeInBytes(DocIdSet docIdSet) { if (docIdSet instanceof FixedBitSet) { return ((FixedBitSet) docIdSet).getBits().length * 8 + 16; @@ -95,6 +87,7 @@ public class DocIdSets { if (set instanceof FixedBitSet) { return set; } + // TODO: should we use WAH8DocIdSet like Lucene? FixedBitSet fixedBitSet = new FixedBitSet(reader.maxDoc()); do { fixedBitSet.set(doc); diff --git a/src/main/java/org/elasticsearch/common/lucene/search/TermFilter.java b/src/main/java/org/elasticsearch/common/lucene/search/TermFilter.java deleted file mode 100644 index 3f54cf13262..00000000000 --- a/src/main/java/org/elasticsearch/common/lucene/search/TermFilter.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.common.lucene.search; - -import org.apache.lucene.index.*; -import org.apache.lucene.search.DocIdSet; -import org.apache.lucene.search.DocIdSetIterator; -import org.apache.lucene.search.Filter; -import org.apache.lucene.util.Bits; -import org.apache.lucene.util.Version; -import org.elasticsearch.common.lucene.Lucene; - -import java.io.IOException; - -/** - * A simple filter for a specific term. - */ -public class TermFilter extends Filter { - - static { - // Remove this class and TermsFilterTests when upgrading to Lucene 4.5 - assert Lucene.VERSION == Version.LUCENE_44; - } - - private final Term term; - - public TermFilter(Term term) { - this.term = term; - } - - public Term getTerm() { - return term; - } - - @Override - public DocIdSet getDocIdSet(AtomicReaderContext context, final Bits acceptDocs) throws IOException { - Terms terms = context.reader().terms(term.field()); - if (terms == null) { - return null; - } - - final TermsEnum termsEnum = terms.iterator(null); - if (!termsEnum.seekExact(term.bytes(), false)) { - return null; - } - return new DocIdSet() { - @Override - public DocIdSetIterator iterator() throws IOException { - return termsEnum.docs(acceptDocs, null, DocsEnum.FLAG_NONE); - } - - }; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - TermFilter that = (TermFilter) o; - - if (term != null ? !term.equals(that.term) : that.term != null) return false; - - return true; - } - - @Override - public int hashCode() { - return term != null ? term.hashCode() : 0; - } - - @Override - public String toString() { - return term.field() + ":" + term.text(); - } -} diff --git a/src/main/java/org/elasticsearch/common/lucene/uid/Versions.java b/src/main/java/org/elasticsearch/common/lucene/uid/Versions.java index 5f03afbdd0d..0fb6c605ceb 100644 --- a/src/main/java/org/elasticsearch/common/lucene/uid/Versions.java +++ b/src/main/java/org/elasticsearch/common/lucene/uid/Versions.java @@ -19,9 +19,8 @@ package org.elasticsearch.common.lucene.uid; -import org.apache.lucene.util.Bits; - import org.apache.lucene.index.*; +import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.Numbers; import org.elasticsearch.index.mapper.internal.UidFieldMapper; @@ -91,8 +90,7 @@ public class Versions { final Terms terms = reader.terms(UidFieldMapper.NAME); assert terms != null : "All segments must have a _uid field, but " + reader + " doesn't"; final TermsEnum termsEnum = terms.iterator(null); - final boolean useCache = false; // avoid high cache churn - if (!termsEnum.seekExact(term.bytes(), useCache)) { + if (!termsEnum.seekExact(term.bytes())) { return null; } diff --git a/src/main/java/org/elasticsearch/index/analysis/NamedAnalyzer.java b/src/main/java/org/elasticsearch/index/analysis/NamedAnalyzer.java index b5a6c9aa1f3..ff19800cdfe 100644 --- a/src/main/java/org/elasticsearch/index/analysis/NamedAnalyzer.java +++ b/src/main/java/org/elasticsearch/index/analysis/NamedAnalyzer.java @@ -21,8 +21,6 @@ package org.elasticsearch.index.analysis; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.CustomAnalyzerWrapper; -import org.apache.lucene.util.Version; -import org.elasticsearch.common.lucene.Lucene; /** * Named analyzer is an analyzer wrapper around an actual analyzer ({@link #analyzer} that is associated @@ -47,15 +45,9 @@ public class NamedAnalyzer extends CustomAnalyzerWrapper { this(name, scope, analyzer, Integer.MIN_VALUE); } - - static { - // LUCENE MONITOR: this should be in Lucene 4.5. - assert Lucene.VERSION == Version.LUCENE_44 : "when upgrading to 4.5, we should use call analyzer#getReuseStrategy(), see https://issues.apache.org/jira/browse/LUCENE-5170"; - } - public NamedAnalyzer(String name, AnalyzerScope scope, Analyzer analyzer, int positionOffsetGap) { // our named analyzer always wrap a non per field analyzer, so no need to have per field analyzer - super(new GlobalReuseStrategy()); + super(analyzer.getReuseStrategy()); this.name = name; this.scope = scope; this.analyzer = analyzer; diff --git a/src/main/java/org/elasticsearch/index/cache/id/simple/SimpleIdCache.java b/src/main/java/org/elasticsearch/index/cache/id/simple/SimpleIdCache.java index 8196a5eb417..5b535239e42 100644 --- a/src/main/java/org/elasticsearch/index/cache/id/simple/SimpleIdCache.java +++ b/src/main/java/org/elasticsearch/index/cache/id/simple/SimpleIdCache.java @@ -156,7 +156,7 @@ public class SimpleIdCache extends AbstractIndexComponent implements IdCache, Se break uid; } - TermsEnum.SeekStatus status = termsEnum.seekCeil(nextParent.toBytesRef(), false); + TermsEnum.SeekStatus status = termsEnum.seekCeil(nextParent.toBytesRef()); if (status == TermsEnum.SeekStatus.END) { break uid; } else if (status == TermsEnum.SeekStatus.NOT_FOUND) { diff --git a/src/main/java/org/elasticsearch/index/codec/PerFieldMappingPostingFormatCodec.java b/src/main/java/org/elasticsearch/index/codec/PerFieldMappingPostingFormatCodec.java index 28ba31fa4e6..b55d875282a 100644 --- a/src/main/java/org/elasticsearch/index/codec/PerFieldMappingPostingFormatCodec.java +++ b/src/main/java/org/elasticsearch/index/codec/PerFieldMappingPostingFormatCodec.java @@ -22,7 +22,7 @@ package org.elasticsearch.index.codec; import org.apache.lucene.codecs.DocValuesFormat; import org.apache.lucene.codecs.PostingsFormat; import org.apache.lucene.codecs.diskdv.DiskDocValuesFormat; -import org.apache.lucene.codecs.lucene42.Lucene42Codec; +import org.apache.lucene.codecs.lucene45.Lucene45Codec; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; import org.elasticsearch.index.mapper.FieldMappers; @@ -38,7 +38,7 @@ import org.elasticsearch.index.mapper.internal.UidFieldMapper; * configured for a specific field the default postings format is used. */ // LUCENE UPGRADE: make sure to move to a new codec depending on the lucene version -public class PerFieldMappingPostingFormatCodec extends Lucene42Codec { +public class PerFieldMappingPostingFormatCodec extends Lucene45Codec { private final ESLogger logger; private final MapperService mapperService; private final PostingsFormat defaultPostingFormat; diff --git a/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormat.java b/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormat.java index cfbf383f3f7..30026cc43f7 100644 --- a/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormat.java +++ b/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormat.java @@ -27,6 +27,7 @@ import org.apache.lucene.store.IndexOutput; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.IOUtils; +import org.apache.lucene.util.RamUsageEstimator; import org.apache.lucene.util.automaton.CompiledAutomaton; import java.io.IOException; @@ -180,6 +181,11 @@ public final class BloomFilterPostingsFormat extends PostingsFormat { return delegateFieldsProducer.getUniqueTermCount(); } + @Override + public long ramBytesUsed() { + return RamUsageEstimator.sizeOf(this); + } + } @@ -303,7 +309,7 @@ public final class BloomFilterPostingsFormat extends PostingsFormat { } @Override - public final boolean seekExact(BytesRef text, boolean useCache) + public final boolean seekExact(BytesRef text) throws IOException { // The magical fail-fast speed up that is the entire point of all of // this code - save a disk seek if there is a match on an in-memory @@ -313,13 +319,13 @@ public final class BloomFilterPostingsFormat extends PostingsFormat { if (!filter.mightContain(text)) { return false; } - return getDelegate().seekExact(text, useCache); + return getDelegate().seekExact(text); } @Override - public final SeekStatus seekCeil(BytesRef text, boolean useCache) + public final SeekStatus seekCeil(BytesRef text) throws IOException { - return getDelegate().seekCeil(text, useCache); + return getDelegate().seekCeil(text); } @Override diff --git a/src/main/java/org/elasticsearch/index/fielddata/ordinals/MultiOrdinals.java b/src/main/java/org/elasticsearch/index/fielddata/ordinals/MultiOrdinals.java index 6fca30ff032..d83f4998f7c 100644 --- a/src/main/java/org/elasticsearch/index/fielddata/ordinals/MultiOrdinals.java +++ b/src/main/java/org/elasticsearch/index/fielddata/ordinals/MultiOrdinals.java @@ -22,9 +22,9 @@ package org.elasticsearch.index.fielddata.ordinals; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.LongsRef; import org.apache.lucene.util.RamUsageEstimator; +import org.apache.lucene.util.packed.AppendingPackedLongBuffer; +import org.apache.lucene.util.packed.MonotonicAppendingLongBuffer; import org.apache.lucene.util.packed.PackedInts; -import org.apache.lucene.util.packed.XAppendingPackedLongBuffer; -import org.apache.lucene.util.packed.XMonotonicAppendingLongBuffer; import org.elasticsearch.index.fielddata.ordinals.Ordinals.Docs.Iter; /** @@ -55,14 +55,14 @@ public class MultiOrdinals implements Ordinals { private final boolean multiValued; private final long numOrds; - private final XMonotonicAppendingLongBuffer endOffsets; - private final XAppendingPackedLongBuffer ords; + private final MonotonicAppendingLongBuffer endOffsets; + private final AppendingPackedLongBuffer ords; public MultiOrdinals(OrdinalsBuilder builder, float acceptableOverheadRatio) { multiValued = builder.getNumMultiValuesDocs() > 0; numOrds = builder.getNumOrds(); - endOffsets = new XMonotonicAppendingLongBuffer(OFFSET_INIT_PAGE_COUNT, OFFSETS_PAGE_SIZE, acceptableOverheadRatio); - ords = new XAppendingPackedLongBuffer(OFFSET_INIT_PAGE_COUNT, OFFSETS_PAGE_SIZE, acceptableOverheadRatio); + endOffsets = new MonotonicAppendingLongBuffer(OFFSET_INIT_PAGE_COUNT, OFFSETS_PAGE_SIZE, acceptableOverheadRatio); + ords = new AppendingPackedLongBuffer(OFFSET_INIT_PAGE_COUNT, OFFSETS_PAGE_SIZE, acceptableOverheadRatio); long lastEndOffset = 0; for (int i = 0; i < builder.maxDoc(); ++i) { final LongsRef docOrds = builder.docOrds(i); @@ -120,8 +120,8 @@ public class MultiOrdinals implements Ordinals { static class MultiDocs implements Ordinals.Docs { private final MultiOrdinals ordinals; - private final XMonotonicAppendingLongBuffer endOffsets; - private final XAppendingPackedLongBuffer ords; + private final MonotonicAppendingLongBuffer endOffsets; + private final AppendingPackedLongBuffer ords; private final LongsRef longsScratch; private final MultiIter iter; @@ -198,10 +198,10 @@ public class MultiOrdinals implements Ordinals { static class MultiIter implements Iter { - final XAppendingPackedLongBuffer ordinals; + final AppendingPackedLongBuffer ordinals; long offset, endOffset; - MultiIter(XAppendingPackedLongBuffer ordinals) { + MultiIter(AppendingPackedLongBuffer ordinals) { this.ordinals = ordinals; } diff --git a/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/src/main/java/org/elasticsearch/index/mapper/MapperService.java index f9b8ddcfa6d..395b8a18305 100644 --- a/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -25,6 +25,7 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.AnalyzerWrapper; import org.apache.lucene.index.Term; import org.apache.lucene.queries.FilterClause; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.queries.TermsFilter; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.Filter; @@ -35,7 +36,6 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.lucene.search.AndFilter; import org.elasticsearch.common.lucene.search.NotFilter; -import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.lucene.search.XBooleanFilter; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Settings; diff --git a/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java index 62fce4c2f59..369124b7805 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/AbstractFieldMapper.java @@ -25,6 +25,7 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.index.Term; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.queries.TermsFilter; import org.apache.lucene.search.*; import org.apache.lucene.util.BytesRef; @@ -33,7 +34,6 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.lucene.BytesRefs; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.search.RegexpFilter; -import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; diff --git a/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java index 69135289407..858d8cc2e14 100644 --- a/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/core/BooleanFieldMapper.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.mapper.core; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.index.FieldInfo.IndexOptions; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.search.Filter; import org.apache.lucene.util.BytesRef; import org.elasticsearch.ElasticSearchIllegalArgumentException; @@ -29,7 +30,6 @@ import org.elasticsearch.common.Booleans; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.lucene.Lucene; -import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java index 041b1a1302a..d5edfbf71f8 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/ParentFieldMapper.java @@ -23,6 +23,7 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.index.Term; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.queries.TermsFilter; import org.apache.lucene.search.ConstantScoreQuery; import org.apache.lucene.search.Filter; @@ -33,7 +34,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.lucene.BytesRefs; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.search.Queries; -import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider; diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/TypeFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/TypeFieldMapper.java index 27f045d0980..8c2eb5c1b8f 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/TypeFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/TypeFieldMapper.java @@ -23,13 +23,13 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.index.Term; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.search.Filter; import org.apache.lucene.search.PrefixFilter; import org.apache.lucene.search.Query; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.lucene.BytesRefs; import org.elasticsearch.common.lucene.Lucene; -import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.lucene.search.XConstantScoreQuery; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java index 4080c3dda3c..98b6e1cca82 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.mapper.internal; +import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.document.NumericDocValuesField; @@ -169,8 +170,10 @@ public class UidFieldMapper extends AbstractFieldMapper implements Internal assert uidField != null; // we need to go over the docs and add it... for (int i = 1; i < context.docs().size(); i++) { - // we don't need to add it as a full uid field in nested docs, since we don't need versioning - context.docs().get(i).add(new Field(UidFieldMapper.NAME, uidField.stringValue(), Defaults.NESTED_FIELD_TYPE)); + final Document doc = context.docs().get(i); + doc.add(new Field(UidFieldMapper.NAME, uidField.stringValue(), Defaults.NESTED_FIELD_TYPE)); + // If we don't set a value on all documents, Lucene will write a BitSet to know which documents have a value + doc.add(new NumericDocValuesField(UidFieldMapper.VERSION, 0L)); } } } diff --git a/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java b/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java index ed9839476b2..38c309b35b8 100644 --- a/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java @@ -24,12 +24,12 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.search.Filter; import org.apache.lucene.util.BytesRef; import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.joda.FormatDateTimeFormatter; -import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; diff --git a/src/main/java/org/elasticsearch/index/merge/policy/IndexUpgraderMergePolicy.java b/src/main/java/org/elasticsearch/index/merge/policy/IndexUpgraderMergePolicy.java index c38f1685784..d0c82e63d93 100644 --- a/src/main/java/org/elasticsearch/index/merge/policy/IndexUpgraderMergePolicy.java +++ b/src/main/java/org/elasticsearch/index/merge/policy/IndexUpgraderMergePolicy.java @@ -24,6 +24,7 @@ import org.apache.lucene.index.*; import org.apache.lucene.index.FieldInfo.DocValuesType; import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.store.Directory; +import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.packed.GrowableWriter; import org.apache.lucene.util.packed.PackedInts; @@ -132,6 +133,10 @@ public final class IndexUpgraderMergePolicy extends MergePolicy { } return super.getNumericDocValues(field); } + @Override + public Bits getDocsWithField(String field) throws IOException { + return new Bits.MatchAllBits(in.maxDoc()); + } }; } diff --git a/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java b/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java index b9762384053..52c753d148e 100644 --- a/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java +++ b/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java @@ -1,13 +1,13 @@ package org.elasticsearch.index.percolator; import org.apache.lucene.index.Term; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.search.Query; import org.apache.lucene.util.BytesRef; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.lucene.HashedBytesRef; -import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.lucene.search.XConstantScoreQuery; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; diff --git a/src/main/java/org/elasticsearch/index/query/TermFilterParser.java b/src/main/java/org/elasticsearch/index/query/TermFilterParser.java index 2e369f969e1..7d0f63d19c9 100644 --- a/src/main/java/org/elasticsearch/index/query/TermFilterParser.java +++ b/src/main/java/org/elasticsearch/index/query/TermFilterParser.java @@ -20,10 +20,10 @@ package org.elasticsearch.index.query; import org.apache.lucene.index.Term; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.search.Filter; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.lucene.BytesRefs; -import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.cache.filter.support.CacheKeyFilter; import org.elasticsearch.index.mapper.MapperService; diff --git a/src/main/java/org/elasticsearch/index/query/TermsFilterParser.java b/src/main/java/org/elasticsearch/index/query/TermsFilterParser.java index b54ea47a17f..c0d3431704c 100644 --- a/src/main/java/org/elasticsearch/index/query/TermsFilterParser.java +++ b/src/main/java/org/elasticsearch/index/query/TermsFilterParser.java @@ -21,13 +21,17 @@ package org.elasticsearch.index.query; import com.google.common.collect.Lists; import org.apache.lucene.index.Term; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.queries.TermsFilter; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.Filter; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.lucene.BytesRefs; -import org.elasticsearch.common.lucene.search.*; +import org.elasticsearch.common.lucene.search.AndFilter; +import org.elasticsearch.common.lucene.search.OrFilter; +import org.elasticsearch.common.lucene.search.Queries; +import org.elasticsearch.common.lucene.search.XBooleanFilter; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.cache.filter.support.CacheKeyFilter; import org.elasticsearch.index.mapper.FieldMapper; diff --git a/src/main/java/org/elasticsearch/index/query/TypeFilterParser.java b/src/main/java/org/elasticsearch/index/query/TypeFilterParser.java index 1b10569f597..23f7127dd1d 100644 --- a/src/main/java/org/elasticsearch/index/query/TypeFilterParser.java +++ b/src/main/java/org/elasticsearch/index/query/TypeFilterParser.java @@ -20,10 +20,10 @@ package org.elasticsearch.index.query; import org.apache.lucene.index.Term; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.search.Filter; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.internal.TypeFieldMapper; 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 9efa8857965..16688b16fa1 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java @@ -24,6 +24,7 @@ import com.carrotsearch.hppc.ObjectIntOpenHashMap; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.search.*; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; @@ -33,7 +34,6 @@ import org.elasticsearch.common.bytes.HashedBytesArray; import org.elasticsearch.common.lucene.docset.DocIdSets; import org.elasticsearch.common.lucene.search.ApplyAcceptedDocsFilter; import org.elasticsearch.common.lucene.search.Queries; -import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.recycler.Recycler; import org.elasticsearch.index.cache.id.IdReaderTypeCache; import org.elasticsearch.index.mapper.Uid; diff --git a/src/main/java/org/elasticsearch/index/search/child/HasChildFilter.java b/src/main/java/org/elasticsearch/index/search/child/HasChildFilter.java index 6ad4ab0bf83..0f7442f40e8 100644 --- a/src/main/java/org/elasticsearch/index/search/child/HasChildFilter.java +++ b/src/main/java/org/elasticsearch/index/search/child/HasChildFilter.java @@ -23,6 +23,7 @@ import com.carrotsearch.hppc.ObjectOpenHashSet; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.Filter; import org.apache.lucene.search.Query; @@ -33,7 +34,6 @@ import org.elasticsearch.common.bytes.HashedBytesArray; import org.elasticsearch.common.lucene.docset.DocIdSets; import org.elasticsearch.common.lucene.docset.MatchDocIdSet; import org.elasticsearch.common.lucene.search.Queries; -import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.recycler.Recycler; import org.elasticsearch.index.cache.id.IdReaderTypeCache; import org.elasticsearch.index.mapper.Uid; diff --git a/src/main/java/org/elasticsearch/index/search/child/ParentIdsFilter.java b/src/main/java/org/elasticsearch/index/search/child/ParentIdsFilter.java index adae685218b..bda2f425fce 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ParentIdsFilter.java +++ b/src/main/java/org/elasticsearch/index/search/child/ParentIdsFilter.java @@ -75,7 +75,7 @@ final class ParentIdsFilter extends Filter { idSpare.bytes = ((HashedBytesArray) keys[i]).toBytes(); idSpare.length = idSpare.bytes.length; Uid.createUidAsBytes(parentTypeBr, idSpare, uidSpare); - if (termsEnum.seekExact(uidSpare, false)) { + if (termsEnum.seekExact(uidSpare)) { int docId; docsEnum = termsEnum.docs(acceptDocs, docsEnum, DocsEnum.FLAG_NONE); if (result == null) { diff --git a/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java b/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java index 1b3b1865ecd..c88a345c6a8 100644 --- a/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java +++ b/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java @@ -950,7 +950,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I if (logger.isDebugEnabled()) { logger.debug("fixing index, writing new segments file ..."); } - checkIndex.fixIndex(status, codecService.codec(indexSettings.get(Engine.INDEX_CODEC, "default"))); + checkIndex.fixIndex(status); if (logger.isDebugEnabled()) { logger.debug("index fixed, wrote new segments file \"{}\"", status.segmentsFileName); } diff --git a/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java b/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java index 012067ada44..bc290a34858 100644 --- a/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java +++ b/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java @@ -79,7 +79,7 @@ public class DfsPhase implements SearchPhase { IndexReaderContext indexReaderContext = context.searcher().getTopReaderContext(); for (int i = 0; i < terms.length; i++) { // LUCENE 4 UPGRADE: cache TermContext? - TermContext termContext = TermContext.build(indexReaderContext, terms[i], false); + TermContext termContext = TermContext.build(indexReaderContext, terms[i]); termStatistics[i] = context.searcher().termStatistics(terms[i], termContext); } diff --git a/src/main/java/org/elasticsearch/search/suggest/completion/Completion090PostingsFormat.java b/src/main/java/org/elasticsearch/search/suggest/completion/Completion090PostingsFormat.java index 7fabd3c09dd..646d1b54d89 100644 --- a/src/main/java/org/elasticsearch/search/suggest/completion/Completion090PostingsFormat.java +++ b/src/main/java/org/elasticsearch/search/suggest/completion/Completion090PostingsFormat.java @@ -25,12 +25,10 @@ import org.apache.lucene.index.*; import org.apache.lucene.index.FilterAtomicReader.FilterTerms; import org.apache.lucene.search.suggest.Lookup; import org.apache.lucene.store.IOContext.Context; -import org.apache.lucene.store.IndexInput; -import org.apache.lucene.store.IndexOutput; -import org.apache.lucene.store.InputStreamDataInput; -import org.apache.lucene.store.OutputStreamDataOutput; +import org.apache.lucene.store.*; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.IOUtils; +import org.apache.lucene.util.RamUsageEstimator; import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; @@ -205,7 +203,7 @@ public class Completion090PostingsFormat extends PostingsFormat { } } - private class CompletionFieldsProducer extends FieldsProducer { + private static class CompletionFieldsProducer extends FieldsProducer { private FieldsProducer delegateProducer; private LookupFactory lookupFactory; @@ -267,6 +265,11 @@ public class Completion090PostingsFormat extends PostingsFormat { public int size() { return delegateProducer.size(); } + + @Override + public long ramBytesUsed() { + return RamUsageEstimator.sizeOf(lookupFactory) + delegateProducer.ramBytesUsed(); + } } public static final class CompletionTerms extends FilterTerms { diff --git a/src/main/java/org/elasticsearch/search/suggest/completion/CompletionTokenStream.java b/src/main/java/org/elasticsearch/search/suggest/completion/CompletionTokenStream.java index 72f5b48d09e..260bd57246d 100644 --- a/src/main/java/org/elasticsearch/search/suggest/completion/CompletionTokenStream.java +++ b/src/main/java/org/elasticsearch/search/suggest/completion/CompletionTokenStream.java @@ -87,6 +87,7 @@ public final class CompletionTokenStream extends TokenStream { @Override public void end() throws IOException { + super.end(); if (posInc == -1) { input.end(); } diff --git a/src/main/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGenerator.java b/src/main/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGenerator.java index 4760e93dbaf..64ee92d8518 100644 --- a/src/main/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGenerator.java +++ b/src/main/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGenerator.java @@ -97,7 +97,7 @@ public final class DirectCandidateGenerator extends CandidateGenerator { public long internalFrequency(BytesRef term) throws IOException { - if (termsEnum.seekExact(term, true)) { + if (termsEnum.seekExact(term)) { return useTotalTermFrequency ? termsEnum.totalTermFreq() : termsEnum.docFreq(); } return 0; diff --git a/src/main/java/org/elasticsearch/search/suggest/phrase/WordScorer.java b/src/main/java/org/elasticsearch/search/suggest/phrase/WordScorer.java index 487c8729403..4c93e123b05 100644 --- a/src/main/java/org/elasticsearch/search/suggest/phrase/WordScorer.java +++ b/src/main/java/org/elasticsearch/search/suggest/phrase/WordScorer.java @@ -63,7 +63,7 @@ public abstract class WordScorer { } public long frequency(BytesRef term) throws IOException { - if (termsEnum.seekExact(term, true)) { + if (termsEnum.seekExact(term)) { return useTotalTermFreq ? termsEnum.totalTermFreq() : termsEnum.docFreq(); } return 0; diff --git a/src/test/java/org/elasticsearch/common/lucene/search/TermsFilterTests.java b/src/test/java/org/elasticsearch/common/lucene/search/TermsFilterTests.java index af40bd11797..eb22c09e714 100644 --- a/src/test/java/org/elasticsearch/common/lucene/search/TermsFilterTests.java +++ b/src/test/java/org/elasticsearch/common/lucene/search/TermsFilterTests.java @@ -24,6 +24,7 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.StringField; import org.apache.lucene.index.*; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.queries.TermsFilter; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.store.Directory; @@ -56,7 +57,7 @@ public class TermsFilterTests { w.commit(); } } - AtomicReader reader = new SlowCompositeReaderWrapper(DirectoryReader.open(w, true)); + AtomicReader reader = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(w, true)); w.close(); TermFilter tf = new TermFilter(new Term(fieldName, "19")); @@ -92,7 +93,7 @@ public class TermsFilterTests { w.commit(); } } - AtomicReader reader = new SlowCompositeReaderWrapper(DirectoryReader.open(w, true)); + AtomicReader reader = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(w, true)); w.close(); TermsFilter tf = new TermsFilter(new Term[]{new Term(fieldName, "19")}); diff --git a/src/test/java/org/elasticsearch/common/lucene/search/XBooleanFilterLuceneTests.java b/src/test/java/org/elasticsearch/common/lucene/search/XBooleanFilterLuceneTests.java index 149aa45fb87..53b68909cdc 100644 --- a/src/test/java/org/elasticsearch/common/lucene/search/XBooleanFilterLuceneTests.java +++ b/src/test/java/org/elasticsearch/common/lucene/search/XBooleanFilterLuceneTests.java @@ -42,7 +42,7 @@ public class XBooleanFilterLuceneTests { addDoc(writer, "admin", "020", "20050101", "Maybe"); addDoc(writer, "admin guest", "030", "20050101", "N"); writer.close(); - reader = new SlowCompositeReaderWrapper(DirectoryReader.open(directory)); + reader = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(directory)); writer.close(); } diff --git a/src/test/java/org/elasticsearch/common/lucene/search/XBooleanFilterTests.java b/src/test/java/org/elasticsearch/common/lucene/search/XBooleanFilterTests.java index ef5f6f216d7..243bf044156 100644 --- a/src/test/java/org/elasticsearch/common/lucene/search/XBooleanFilterTests.java +++ b/src/test/java/org/elasticsearch/common/lucene/search/XBooleanFilterTests.java @@ -6,6 +6,7 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.StringField; import org.apache.lucene.index.*; import org.apache.lucene.queries.FilterClause; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.FieldCacheTermsFilter; @@ -52,7 +53,7 @@ public class XBooleanFilterTests { IndexWriter w = new IndexWriter(directory, new IndexWriterConfig(Lucene.VERSION, new KeywordAnalyzer())); w.addDocuments(documents); w.close(); - reader = new SlowCompositeReaderWrapper(DirectoryReader.open(directory)); + reader = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(directory)); } @After diff --git a/src/test/java/org/elasticsearch/index/cache/filter/FilterCacheTests.java b/src/test/java/org/elasticsearch/index/cache/filter/FilterCacheTests.java index 661a2d2f77c..95defe25723 100644 --- a/src/test/java/org/elasticsearch/index/cache/filter/FilterCacheTests.java +++ b/src/test/java/org/elasticsearch/index/cache/filter/FilterCacheTests.java @@ -23,6 +23,7 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.TextField; import org.apache.lucene.index.*; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.search.ConstantScoreQuery; import org.apache.lucene.search.Filter; import org.apache.lucene.search.IndexSearcher; @@ -30,7 +31,6 @@ import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.elasticsearch.common.lucene.Lucene; -import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.lucene.search.XConstantScoreQuery; import org.elasticsearch.common.lucene.search.XFilteredQuery; import org.elasticsearch.index.Index; diff --git a/src/test/java/org/elasticsearch/index/codec/postingformat/DefaultPostingsFormatTests.java b/src/test/java/org/elasticsearch/index/codec/postingformat/DefaultPostingsFormatTests.java index 8fd452c5bc0..114663e47ea 100644 --- a/src/test/java/org/elasticsearch/index/codec/postingformat/DefaultPostingsFormatTests.java +++ b/src/test/java/org/elasticsearch/index/codec/postingformat/DefaultPostingsFormatTests.java @@ -19,30 +19,13 @@ package org.elasticsearch.index.codec.postingformat; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.not; - -import java.io.IOException; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - import org.apache.lucene.analysis.core.WhitespaceAnalyzer; import org.apache.lucene.codecs.Codec; import org.apache.lucene.codecs.PostingsFormat; -import org.apache.lucene.codecs.lucene42.Lucene42Codec; +import org.apache.lucene.codecs.lucene45.Lucene45Codec; import org.apache.lucene.document.Field.Store; import org.apache.lucene.document.TextField; -import org.apache.lucene.index.AtomicReader; -import org.apache.lucene.index.AtomicReaderContext; -import org.apache.lucene.index.DirectoryReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.index.Terms; -import org.apache.lucene.index.TermsEnum; +import org.apache.lucene.index.*; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.elasticsearch.common.lucene.Lucene; @@ -51,12 +34,21 @@ import org.elasticsearch.index.codec.postingsformat.ElasticSearch090PostingsForm import org.elasticsearch.index.mapper.internal.UidFieldMapper; import org.junit.Test; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + /** * Simple smoke test for {@link ElasticSearch090PostingsFormat} */ public class DefaultPostingsFormatTests { - private final class TestCodec extends Lucene42Codec { + private final class TestCodec extends Lucene45Codec { @Override public PostingsFormat getPostingsFormatForField(String field) { diff --git a/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTests.java b/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTests.java index 3c8cf4403bd..e2b64efe1d9 100644 --- a/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTests.java +++ b/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTests.java @@ -53,7 +53,7 @@ public abstract class AbstractFieldDataTests extends ElasticSearchTestCase { if (readerContext != null) { readerContext.reader().close(); } - AtomicReader reader = new SlowCompositeReaderWrapper(DirectoryReader.open(writer, true)); + AtomicReader reader = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(writer, true)); readerContext = reader.getContext(); return readerContext; } diff --git a/src/test/java/org/elasticsearch/index/fielddata/AbstractStringFieldDataTests.java b/src/test/java/org/elasticsearch/index/fielddata/AbstractStringFieldDataTests.java index 20e9d52ab8e..4443495fd88 100644 --- a/src/test/java/org/elasticsearch/index/fielddata/AbstractStringFieldDataTests.java +++ b/src/test/java/org/elasticsearch/index/fielddata/AbstractStringFieldDataTests.java @@ -27,7 +27,9 @@ import org.apache.lucene.document.Field.Store; import org.apache.lucene.document.StringField; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.Term; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.search.*; +import org.apache.lucene.search.join.FixedBitSetCachingWrapperFilter; import org.apache.lucene.search.join.ScoreMode; import org.apache.lucene.search.join.ToParentBlockJoinQuery; import org.apache.lucene.util.BytesRef; @@ -35,7 +37,6 @@ import org.apache.lucene.util.OpenBitSet; import org.apache.lucene.util.UnicodeUtil; import org.apache.lucene.util._TestUtil; import org.elasticsearch.common.lucene.search.NotFilter; -import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.lucene.search.XFilteredQuery; import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource; import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource; @@ -386,7 +387,7 @@ public abstract class AbstractStringFieldDataTests extends AbstractFieldDataImpl Filter parentFilter = new TermFilter(new Term("type", "parent")); Filter childFilter = new NotFilter(parentFilter); NestedFieldComparatorSource nestedComparatorSource = new NestedFieldComparatorSource(sortMode, innerSource, parentFilter, childFilter); - ToParentBlockJoinQuery query = new ToParentBlockJoinQuery(new XFilteredQuery(new MatchAllDocsQuery(), childFilter), new CachingWrapperFilter(parentFilter), ScoreMode.None); + ToParentBlockJoinQuery query = new ToParentBlockJoinQuery(new XFilteredQuery(new MatchAllDocsQuery(), childFilter), new FixedBitSetCachingWrapperFilter(parentFilter), ScoreMode.None); Sort sort = new Sort(new SortField("text", nestedComparatorSource)); TopFieldDocs topDocs = searcher.search(query, randomIntBetween(1, numParents), sort); assertTrue(topDocs.scoreDocs.length > 0); diff --git a/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java b/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java index 77876638a7d..e704f4ba1b2 100644 --- a/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java +++ b/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java @@ -22,10 +22,7 @@ package org.elasticsearch.index.query; import com.google.common.collect.Lists; import org.apache.lucene.index.Term; -import org.apache.lucene.queries.BoostingQuery; -import org.apache.lucene.queries.ExtendedCommonTermsQuery; -import org.apache.lucene.queries.FilterClause; -import org.apache.lucene.queries.TermsFilter; +import org.apache.lucene.queries.*; import org.apache.lucene.sandbox.queries.FuzzyLikeThisQuery; import org.apache.lucene.search.*; import org.apache.lucene.search.spans.*; @@ -2227,8 +2224,8 @@ public class SimpleIndexQueryParserTests extends ElasticSearchTestCase { Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(ExtendedCommonTermsQuery.class)); ExtendedCommonTermsQuery ectQuery = (ExtendedCommonTermsQuery) parsedQuery; - assertThat(ectQuery.getHighFreqMinimumNumberShouldMatch(), nullValue()); - assertThat(ectQuery.getLowFreqMinimumNumberShouldMatch(), equalTo("2")); + assertThat(ectQuery.getHighFreqMinimumNumberShouldMatchSpec(), nullValue()); + assertThat(ectQuery.getLowFreqMinimumNumberShouldMatchSpec(), equalTo("2")); } @Test @@ -2238,8 +2235,8 @@ public class SimpleIndexQueryParserTests extends ElasticSearchTestCase { Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(ExtendedCommonTermsQuery.class)); ExtendedCommonTermsQuery ectQuery = (ExtendedCommonTermsQuery) parsedQuery; - assertThat(ectQuery.getHighFreqMinimumNumberShouldMatch(), equalTo("50%")); - assertThat(ectQuery.getLowFreqMinimumNumberShouldMatch(), equalTo("5<20%")); + assertThat(ectQuery.getHighFreqMinimumNumberShouldMatchSpec(), equalTo("50%")); + assertThat(ectQuery.getLowFreqMinimumNumberShouldMatchSpec(), equalTo("5<20%")); } @Test @@ -2249,8 +2246,8 @@ public class SimpleIndexQueryParserTests extends ElasticSearchTestCase { Query parsedQuery = queryParser.parse(query).query(); assertThat(parsedQuery, instanceOf(ExtendedCommonTermsQuery.class)); ExtendedCommonTermsQuery ectQuery = (ExtendedCommonTermsQuery) parsedQuery; - assertThat(ectQuery.getHighFreqMinimumNumberShouldMatch(), nullValue()); - assertThat(ectQuery.getLowFreqMinimumNumberShouldMatch(), equalTo("2")); + assertThat(ectQuery.getHighFreqMinimumNumberShouldMatchSpec(), nullValue()); + assertThat(ectQuery.getLowFreqMinimumNumberShouldMatchSpec(), equalTo("2")); } @Test(expected = QueryParsingException.class) diff --git a/src/test/java/org/elasticsearch/index/search/nested/AbstractNumberNestedSortingTests.java b/src/test/java/org/elasticsearch/index/search/nested/AbstractNumberNestedSortingTests.java index 546dba10dd4..8fb59e6dc18 100644 --- a/src/test/java/org/elasticsearch/index/search/nested/AbstractNumberNestedSortingTests.java +++ b/src/test/java/org/elasticsearch/index/search/nested/AbstractNumberNestedSortingTests.java @@ -25,22 +25,22 @@ import org.apache.lucene.document.StringField; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.search.*; +import org.apache.lucene.search.join.FixedBitSetCachingWrapperFilter; import org.apache.lucene.search.join.ScoreMode; import org.apache.lucene.search.join.ToParentBlockJoinQuery; import org.elasticsearch.common.lucene.search.NotFilter; -import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.lucene.search.XFilteredQuery; +import org.elasticsearch.index.fielddata.AbstractFieldDataTests; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.fieldcomparator.SortMode; -import org.elasticsearch.index.fielddata.AbstractFieldDataTests; import org.junit.Test; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; /** @@ -211,7 +211,7 @@ public abstract class AbstractNumberNestedSortingTests extends AbstractFieldData Filter parentFilter = new TermFilter(new Term("__type", "parent")); Filter childFilter = new NotFilter(parentFilter); NestedFieldComparatorSource nestedComparatorSource = new NestedFieldComparatorSource(sortMode, innerFieldComparator, parentFilter, childFilter); - ToParentBlockJoinQuery query = new ToParentBlockJoinQuery(new XFilteredQuery(new MatchAllDocsQuery(), childFilter), new CachingWrapperFilter(parentFilter), ScoreMode.None); + ToParentBlockJoinQuery query = new ToParentBlockJoinQuery(new XFilteredQuery(new MatchAllDocsQuery(), childFilter), new FixedBitSetCachingWrapperFilter(parentFilter), ScoreMode.None); Sort sort = new Sort(new SortField("field2", nestedComparatorSource)); TopFieldDocs topDocs = searcher.search(query, 5, sort); @@ -247,7 +247,7 @@ public abstract class AbstractNumberNestedSortingTests extends AbstractFieldData nestedComparatorSource = new NestedFieldComparatorSource(sortMode, innerFieldComparator, parentFilter, childFilter); query = new ToParentBlockJoinQuery( new XFilteredQuery(new MatchAllDocsQuery(), childFilter), - new CachingWrapperFilter(parentFilter), + new FixedBitSetCachingWrapperFilter(parentFilter), ScoreMode.None ); sort = new Sort(new SortField("field2", nestedComparatorSource, true)); @@ -324,7 +324,7 @@ public abstract class AbstractNumberNestedSortingTests extends AbstractFieldData SortMode sortMode = SortMode.AVG; Filter childFilter = new NotFilter(parentFilter); NestedFieldComparatorSource nestedComparatorSource = new NestedFieldComparatorSource(sortMode, innerFieldComparator, parentFilter, childFilter); - Query query = new ToParentBlockJoinQuery(new XFilteredQuery(new MatchAllDocsQuery(), childFilter), new CachingWrapperFilter(parentFilter), ScoreMode.None); + Query query = new ToParentBlockJoinQuery(new XFilteredQuery(new MatchAllDocsQuery(), childFilter), new FixedBitSetCachingWrapperFilter(parentFilter), ScoreMode.None); Sort sort = new Sort(new SortField("field2", nestedComparatorSource)); TopDocs topDocs = searcher.search(query, 5, sort); assertThat(topDocs.totalHits, equalTo(7)); diff --git a/src/test/java/org/elasticsearch/index/search/nested/DoubleNestedSortingTests.java b/src/test/java/org/elasticsearch/index/search/nested/DoubleNestedSortingTests.java index 71b5e93c654..c573d2a1b3d 100644 --- a/src/test/java/org/elasticsearch/index/search/nested/DoubleNestedSortingTests.java +++ b/src/test/java/org/elasticsearch/index/search/nested/DoubleNestedSortingTests.java @@ -23,6 +23,7 @@ import org.apache.lucene.document.DoubleField; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.*; +import org.apache.lucene.search.join.FixedBitSetCachingWrapperFilter; import org.apache.lucene.search.join.ScoreMode; import org.apache.lucene.search.join.ToParentBlockJoinQuery; import org.elasticsearch.common.lucene.search.NotFilter; @@ -35,7 +36,6 @@ import org.elasticsearch.index.fielddata.plain.DoubleArrayIndexFieldData; import java.io.IOException; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; /** @@ -62,7 +62,7 @@ public class DoubleNestedSortingTests extends AbstractNumberNestedSortingTests { SortMode sortMode = SortMode.AVG; Filter childFilter = new NotFilter(parentFilter); NestedFieldComparatorSource nestedComparatorSource = new NestedFieldComparatorSource(sortMode, innerFieldComparator, parentFilter, childFilter); - Query query = new ToParentBlockJoinQuery(new XFilteredQuery(new MatchAllDocsQuery(), childFilter), new CachingWrapperFilter(parentFilter), ScoreMode.None); + Query query = new ToParentBlockJoinQuery(new XFilteredQuery(new MatchAllDocsQuery(), childFilter), new FixedBitSetCachingWrapperFilter(parentFilter), ScoreMode.None); Sort sort = new Sort(new SortField("field2", nestedComparatorSource)); TopDocs topDocs = searcher.search(query, 5, sort); assertThat(topDocs.totalHits, equalTo(7)); diff --git a/src/test/java/org/elasticsearch/index/search/nested/FloatNestedSortingTests.java b/src/test/java/org/elasticsearch/index/search/nested/FloatNestedSortingTests.java index 39d6174144c..9d4bbeb8a90 100644 --- a/src/test/java/org/elasticsearch/index/search/nested/FloatNestedSortingTests.java +++ b/src/test/java/org/elasticsearch/index/search/nested/FloatNestedSortingTests.java @@ -23,6 +23,7 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.FloatField; import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.*; +import org.apache.lucene.search.join.FixedBitSetCachingWrapperFilter; import org.apache.lucene.search.join.ScoreMode; import org.apache.lucene.search.join.ToParentBlockJoinQuery; import org.elasticsearch.common.lucene.search.NotFilter; @@ -35,7 +36,6 @@ import org.elasticsearch.index.fielddata.plain.FloatArrayIndexFieldData; import java.io.IOException; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; /** @@ -62,7 +62,7 @@ public class FloatNestedSortingTests extends AbstractNumberNestedSortingTests { SortMode sortMode = SortMode.AVG; Filter childFilter = new NotFilter(parentFilter); NestedFieldComparatorSource nestedComparatorSource = new NestedFieldComparatorSource(sortMode, innerFieldComparator, parentFilter, childFilter); - Query query = new ToParentBlockJoinQuery(new XFilteredQuery(new MatchAllDocsQuery(), childFilter), new CachingWrapperFilter(parentFilter), ScoreMode.None); + Query query = new ToParentBlockJoinQuery(new XFilteredQuery(new MatchAllDocsQuery(), childFilter), new FixedBitSetCachingWrapperFilter(parentFilter), ScoreMode.None); Sort sort = new Sort(new SortField("field2", nestedComparatorSource)); TopDocs topDocs = searcher.search(query, 5, sort); assertThat(topDocs.totalHits, equalTo(7)); diff --git a/src/test/java/org/elasticsearch/index/search/nested/NestedSortingTests.java b/src/test/java/org/elasticsearch/index/search/nested/NestedSortingTests.java index 16b3b0207ac..fa348133ac8 100644 --- a/src/test/java/org/elasticsearch/index/search/nested/NestedSortingTests.java +++ b/src/test/java/org/elasticsearch/index/search/nested/NestedSortingTests.java @@ -25,20 +25,21 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.StringField; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.Term; +import org.apache.lucene.queries.TermFilter; import org.apache.lucene.search.*; +import org.apache.lucene.search.join.FixedBitSetCachingWrapperFilter; import org.apache.lucene.search.join.ScoreMode; import org.apache.lucene.search.join.ToParentBlockJoinQuery; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.lucene.search.AndFilter; import org.elasticsearch.common.lucene.search.NotFilter; -import org.elasticsearch.common.lucene.search.TermFilter; import org.elasticsearch.common.lucene.search.XFilteredQuery; import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.index.fielddata.AbstractFieldDataTests; import org.elasticsearch.index.fielddata.FieldDataType; import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource; import org.elasticsearch.index.fielddata.fieldcomparator.SortMode; import org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData; -import org.elasticsearch.index.fielddata.AbstractFieldDataTests; import org.junit.Test; import java.util.ArrayList; @@ -218,7 +219,7 @@ public class NestedSortingTests extends AbstractFieldDataTests { Filter parentFilter = new TermFilter(new Term("__type", "parent")); Filter childFilter = new NotFilter(parentFilter); NestedFieldComparatorSource nestedComparatorSource = new NestedFieldComparatorSource(sortMode, innerSource, parentFilter, childFilter); - ToParentBlockJoinQuery query = new ToParentBlockJoinQuery(new XFilteredQuery(new MatchAllDocsQuery(), childFilter), new CachingWrapperFilter(parentFilter), ScoreMode.None); + ToParentBlockJoinQuery query = new ToParentBlockJoinQuery(new XFilteredQuery(new MatchAllDocsQuery(), childFilter), new FixedBitSetCachingWrapperFilter(parentFilter), ScoreMode.None); Sort sort = new Sort(new SortField("field2", nestedComparatorSource)); TopFieldDocs topDocs = searcher.search(query, 5, sort); @@ -257,7 +258,7 @@ public class NestedSortingTests extends AbstractFieldDataTests { nestedComparatorSource = new NestedFieldComparatorSource(sortMode, innerSource, parentFilter, childFilter); query = new ToParentBlockJoinQuery( new XFilteredQuery(new MatchAllDocsQuery(), childFilter), - new CachingWrapperFilter(parentFilter), + new FixedBitSetCachingWrapperFilter(parentFilter), ScoreMode.None ); sort = new Sort(new SortField("field2", nestedComparatorSource, true));