Update Lucene to version 4.5.0.
This commit is contained in:
parent
a10c195667
commit
6b02611971
2
pom.xml
2
pom.xml
|
@ -30,7 +30,7 @@
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<lucene.version>4.4.0</lucene.version>
|
<lucene.version>4.5.0</lucene.version>
|
||||||
<tests.jvms>1</tests.jvms>
|
<tests.jvms>1</tests.jvms>
|
||||||
<tests.shuffle>true</tests.shuffle>
|
<tests.shuffle>true</tests.shuffle>
|
||||||
<tests.output>onerror</tests.output>
|
<tests.output>onerror</tests.output>
|
||||||
|
|
|
@ -19,12 +19,9 @@ package org.apache.lucene.queries;
|
||||||
*/
|
*/
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
import org.apache.lucene.index.TermContext;
|
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.BooleanClause.Occur;
|
||||||
import org.apache.lucene.search.BooleanQuery;
|
import org.elasticsearch.Version;
|
||||||
import org.apache.lucene.search.Query;
|
|
||||||
import org.apache.lucene.search.TermQuery;
|
|
||||||
|
|
||||||
import org.elasticsearch.common.lucene.search.Queries;
|
import org.elasticsearch.common.lucene.search.Queries;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,6 +54,7 @@ public class ExtendedCommonTermsQuery extends CommonTermsQuery {
|
||||||
return Queries.calculateMinShouldMatch(numOptional, spec);
|
return Queries.calculateMinShouldMatch(numOptional, spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected int calcHighFreqMinimumNumberShouldMatch(int numOptional) {
|
protected int calcHighFreqMinimumNumberShouldMatch(int numOptional) {
|
||||||
return calcMinimumNumberShouldMatch(highFreqMinNumShouldMatchSpec, numOptional);
|
return calcMinimumNumberShouldMatch(highFreqMinNumShouldMatchSpec, numOptional);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +63,7 @@ public class ExtendedCommonTermsQuery extends CommonTermsQuery {
|
||||||
this.highFreqMinNumShouldMatchSpec = spec;
|
this.highFreqMinNumShouldMatchSpec = spec;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHighFreqMinimumNumberShouldMatch() {
|
public String getHighFreqMinimumNumberShouldMatchSpec() {
|
||||||
return highFreqMinNumShouldMatchSpec;
|
return highFreqMinNumShouldMatchSpec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,66 +71,73 @@ public class ExtendedCommonTermsQuery extends CommonTermsQuery {
|
||||||
this.lowFreqMinNumShouldMatchSpec = spec;
|
this.lowFreqMinNumShouldMatchSpec = spec;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLowFreqMinimumNumberShouldMatch() {
|
public String getLowFreqMinimumNumberShouldMatchSpec() {
|
||||||
return lowFreqMinNumShouldMatchSpec;
|
return lowFreqMinNumShouldMatchSpec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
assert Version.CURRENT.luceneVersion.compareTo(org.apache.lucene.util.Version.LUCENE_45) == 0 : "Remove buildQuery() once 4.6 is out";
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
protected Query buildQuery(final int maxDoc, final TermContext[] contextArray, final Term[] queryTerms) {
|
protected Query buildQuery(final int maxDoc,
|
||||||
BooleanQuery lowFreq = new BooleanQuery(disableCoord);
|
final TermContext[] contextArray, final Term[] queryTerms) {
|
||||||
BooleanQuery highFreq = new BooleanQuery(disableCoord);
|
BooleanQuery lowFreq = new BooleanQuery(disableCoord);
|
||||||
highFreq.setBoost(highFreqBoost);
|
BooleanQuery highFreq = new BooleanQuery(disableCoord);
|
||||||
lowFreq.setBoost(lowFreqBoost);
|
highFreq.setBoost(highFreqBoost);
|
||||||
BooleanQuery query = new BooleanQuery(true);
|
lowFreq.setBoost(lowFreqBoost);
|
||||||
|
BooleanQuery query = new BooleanQuery(true);
|
||||||
for (int i = 0; i < queryTerms.length; i++) {
|
for (int i = 0; i < queryTerms.length; i++) {
|
||||||
TermContext termContext = contextArray[i];
|
TermContext termContext = contextArray[i];
|
||||||
if (termContext == null) {
|
if (termContext == null) {
|
||||||
lowFreq.add(new TermQuery(queryTerms[i]), lowFreqOccur);
|
lowFreq.add(new TermQuery(queryTerms[i]), lowFreqOccur);
|
||||||
} else {
|
} else {
|
||||||
if ((maxTermFrequency >= 1f && termContext.docFreq() > maxTermFrequency) || (termContext.docFreq() > (int) Math.ceil(maxTermFrequency * (float) maxDoc))) {
|
if ((maxTermFrequency >= 1f && termContext.docFreq() > maxTermFrequency)
|
||||||
highFreq.add(new TermQuery(queryTerms[i], termContext), highFreqOccur);
|
|| (termContext.docFreq() > (int) Math.ceil(maxTermFrequency
|
||||||
} else {
|
* (float) maxDoc))) {
|
||||||
lowFreq.add(new TermQuery(queryTerms[i], termContext), lowFreqOccur);
|
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();
|
final int numLowFreqClauses = lowFreq.clauses().size();
|
||||||
|
final int numHighFreqClauses = highFreq.clauses().size();
|
||||||
if (lowFreqOccur == Occur.SHOULD && numLowFreqClauses > 0) {
|
if (lowFreqOccur == Occur.SHOULD && numLowFreqClauses > 0) {
|
||||||
int minMustMatch = calcLowFreqMinimumNumberShouldMatch(numLowFreqClauses);
|
int minMustMatch = calcLowFreqMinimumNumberShouldMatch(numLowFreqClauses);
|
||||||
lowFreq.setMinimumNumberShouldMatch(minMustMatch);
|
lowFreq.setMinimumNumberShouldMatch(minMustMatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (highFreqOccur == Occur.SHOULD && numHighFreqClauses > 0) {
|
if (highFreqOccur == Occur.SHOULD && numHighFreqClauses > 0) {
|
||||||
int minMustMatch = calcHighFreqMinimumNumberShouldMatch(numHighFreqClauses);
|
int minMustMatch = calcHighFreqMinimumNumberShouldMatch(numHighFreqClauses);
|
||||||
highFreq.setMinimumNumberShouldMatch(minMustMatch);
|
highFreq.setMinimumNumberShouldMatch(minMustMatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lowFreq.clauses().isEmpty()) {
|
if (lowFreq.clauses().isEmpty()) {
|
||||||
/*
|
/*
|
||||||
* if lowFreq is empty we rewrite the high freq terms in a conjunction to
|
* if lowFreq is empty we rewrite the high freq terms in a conjunction to
|
||||||
* prevent slow queries.
|
* prevent slow queries.
|
||||||
* Only if a specic high_freq should_match is not specified.
|
* Only if a specic high_freq should_match is not specified.
|
||||||
*/
|
*/
|
||||||
if (highFreqMinNumShouldMatchSpec == null && highFreqOccur != Occur.MUST) {
|
if (highFreq.getMinimumNumberShouldMatch() == 0 && highFreqOccur != Occur.MUST) {
|
||||||
for (BooleanClause booleanClause : highFreq) {
|
for (BooleanClause booleanClause : highFreq) {
|
||||||
booleanClause.setOccur(Occur.MUST);
|
booleanClause.setOccur(Occur.MUST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
highFreq.setBoost(getBoost());
|
highFreq.setBoost(getBoost());
|
||||||
return highFreq;
|
return highFreq;
|
||||||
} else if (highFreq.clauses().isEmpty()) {
|
} else if (highFreq.clauses().isEmpty()) {
|
||||||
// only do low freq terms - we don't have high freq terms
|
// only do low freq terms - we don't have high freq terms
|
||||||
lowFreq.setBoost(getBoost());
|
lowFreq.setBoost(getBoost());
|
||||||
return lowFreq;
|
return lowFreq;
|
||||||
} else {
|
} else {
|
||||||
query.add(highFreq, Occur.SHOULD);
|
query.add(highFreq, Occur.SHOULD);
|
||||||
query.add(lowFreq, Occur.MUST);
|
query.add(lowFreq, Occur.MUST);
|
||||||
query.setBoost(getBoost());
|
query.setBoost(getBoost());
|
||||||
return query;
|
return query;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,10 @@ package org.apache.lucene.search.vectorhighlight;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
import org.apache.lucene.queries.FilterClause;
|
import org.apache.lucene.queries.FilterClause;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.search.*;
|
import org.apache.lucene.search.*;
|
||||||
import org.apache.lucene.search.spans.SpanTermQuery;
|
import org.apache.lucene.search.spans.SpanTermQuery;
|
||||||
import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery;
|
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.XBooleanFilter;
|
||||||
import org.elasticsearch.common.lucene.search.XFilteredQuery;
|
import org.elasticsearch.common.lucene.search.XFilteredQuery;
|
||||||
import org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery;
|
import org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery;
|
||||||
|
|
|
@ -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 <code>len</code> longs starting
|
|
||||||
* from <code>index</code> into <code>arr[off:off+len]</code> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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 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 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;
|
public static final Version CURRENT = V_1_0_0_Beta1;
|
||||||
|
|
||||||
|
|
|
@ -284,7 +284,7 @@ public final class TermVectorFields extends Fields {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SeekStatus seekCeil(BytesRef text, boolean useCache) throws IOException {
|
public SeekStatus seekCeil(BytesRef text) throws IOException {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ final class TermVectorWriter {
|
||||||
// current field
|
// current field
|
||||||
// get the doc frequency
|
// get the doc frequency
|
||||||
BytesRef term = iterator.term();
|
BytesRef term = iterator.term();
|
||||||
boolean foundTerm = topLevelIterator.seekExact(term, false);
|
boolean foundTerm = topLevelIterator.seekExact(term);
|
||||||
assert (foundTerm);
|
assert (foundTerm);
|
||||||
startTerm(term);
|
startTerm(term);
|
||||||
if (flags.contains(Flag.TermStatistics)) {
|
if (flags.contains(Flag.TermStatistics)) {
|
||||||
|
|
|
@ -44,7 +44,7 @@ import java.io.IOException;
|
||||||
*/
|
*/
|
||||||
public class Lucene {
|
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 ANALYZER_VERSION = VERSION;
|
||||||
public static final Version QUERYPARSER_VERSION = VERSION;
|
public static final Version QUERYPARSER_VERSION = VERSION;
|
||||||
|
|
||||||
|
@ -60,6 +60,9 @@ public class Lucene {
|
||||||
if (version == null) {
|
if (version == null) {
|
||||||
return defaultVersion;
|
return defaultVersion;
|
||||||
}
|
}
|
||||||
|
if ("4.5".equals(version)) {
|
||||||
|
return VERSION.LUCENE_45;
|
||||||
|
}
|
||||||
if ("4.4".equals(version)) {
|
if ("4.4".equals(version)) {
|
||||||
return VERSION.LUCENE_44;
|
return VERSION.LUCENE_44;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,7 @@ import org.apache.lucene.search.DocIdSetIterator;
|
||||||
import org.apache.lucene.util.Bits;
|
import org.apache.lucene.util.Bits;
|
||||||
import org.apache.lucene.util.FixedBitSet;
|
import org.apache.lucene.util.FixedBitSet;
|
||||||
import org.apache.lucene.util.OpenBitSetIterator;
|
import org.apache.lucene.util.OpenBitSetIterator;
|
||||||
import org.apache.lucene.util.Version;
|
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.lucene.Lucene;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -35,12 +33,6 @@ import java.io.IOException;
|
||||||
*/
|
*/
|
||||||
public class DocIdSets {
|
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) {
|
public static long sizeInBytes(DocIdSet docIdSet) {
|
||||||
if (docIdSet instanceof FixedBitSet) {
|
if (docIdSet instanceof FixedBitSet) {
|
||||||
return ((FixedBitSet) docIdSet).getBits().length * 8 + 16;
|
return ((FixedBitSet) docIdSet).getBits().length * 8 + 16;
|
||||||
|
@ -95,6 +87,7 @@ public class DocIdSets {
|
||||||
if (set instanceof FixedBitSet) {
|
if (set instanceof FixedBitSet) {
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
// TODO: should we use WAH8DocIdSet like Lucene?
|
||||||
FixedBitSet fixedBitSet = new FixedBitSet(reader.maxDoc());
|
FixedBitSet fixedBitSet = new FixedBitSet(reader.maxDoc());
|
||||||
do {
|
do {
|
||||||
fixedBitSet.set(doc);
|
fixedBitSet.set(doc);
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -19,9 +19,8 @@
|
||||||
|
|
||||||
package org.elasticsearch.common.lucene.uid;
|
package org.elasticsearch.common.lucene.uid;
|
||||||
|
|
||||||
import org.apache.lucene.util.Bits;
|
|
||||||
|
|
||||||
import org.apache.lucene.index.*;
|
import org.apache.lucene.index.*;
|
||||||
|
import org.apache.lucene.util.Bits;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.common.Numbers;
|
import org.elasticsearch.common.Numbers;
|
||||||
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
|
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
|
||||||
|
@ -91,8 +90,7 @@ public class Versions {
|
||||||
final Terms terms = reader.terms(UidFieldMapper.NAME);
|
final Terms terms = reader.terms(UidFieldMapper.NAME);
|
||||||
assert terms != null : "All segments must have a _uid field, but " + reader + " doesn't";
|
assert terms != null : "All segments must have a _uid field, but " + reader + " doesn't";
|
||||||
final TermsEnum termsEnum = terms.iterator(null);
|
final TermsEnum termsEnum = terms.iterator(null);
|
||||||
final boolean useCache = false; // avoid high cache churn
|
if (!termsEnum.seekExact(term.bytes())) {
|
||||||
if (!termsEnum.seekExact(term.bytes(), useCache)) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,6 @@ package org.elasticsearch.index.analysis;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.apache.lucene.analysis.CustomAnalyzerWrapper;
|
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
|
* 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);
|
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) {
|
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
|
// 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.name = name;
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
this.analyzer = analyzer;
|
this.analyzer = analyzer;
|
||||||
|
|
|
@ -156,7 +156,7 @@ public class SimpleIdCache extends AbstractIndexComponent implements IdCache, Se
|
||||||
break uid;
|
break uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
TermsEnum.SeekStatus status = termsEnum.seekCeil(nextParent.toBytesRef(), false);
|
TermsEnum.SeekStatus status = termsEnum.seekCeil(nextParent.toBytesRef());
|
||||||
if (status == TermsEnum.SeekStatus.END) {
|
if (status == TermsEnum.SeekStatus.END) {
|
||||||
break uid;
|
break uid;
|
||||||
} else if (status == TermsEnum.SeekStatus.NOT_FOUND) {
|
} else if (status == TermsEnum.SeekStatus.NOT_FOUND) {
|
||||||
|
|
|
@ -22,7 +22,7 @@ package org.elasticsearch.index.codec;
|
||||||
import org.apache.lucene.codecs.DocValuesFormat;
|
import org.apache.lucene.codecs.DocValuesFormat;
|
||||||
import org.apache.lucene.codecs.PostingsFormat;
|
import org.apache.lucene.codecs.PostingsFormat;
|
||||||
import org.apache.lucene.codecs.diskdv.DiskDocValuesFormat;
|
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.common.logging.ESLogger;
|
||||||
import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider;
|
import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider;
|
||||||
import org.elasticsearch.index.mapper.FieldMappers;
|
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.
|
* 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
|
// 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 ESLogger logger;
|
||||||
private final MapperService mapperService;
|
private final MapperService mapperService;
|
||||||
private final PostingsFormat defaultPostingFormat;
|
private final PostingsFormat defaultPostingFormat;
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.lucene.store.IndexOutput;
|
||||||
import org.apache.lucene.util.Bits;
|
import org.apache.lucene.util.Bits;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.apache.lucene.util.IOUtils;
|
import org.apache.lucene.util.IOUtils;
|
||||||
|
import org.apache.lucene.util.RamUsageEstimator;
|
||||||
import org.apache.lucene.util.automaton.CompiledAutomaton;
|
import org.apache.lucene.util.automaton.CompiledAutomaton;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -180,6 +181,11 @@ public final class BloomFilterPostingsFormat extends PostingsFormat {
|
||||||
return delegateFieldsProducer.getUniqueTermCount();
|
return delegateFieldsProducer.getUniqueTermCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long ramBytesUsed() {
|
||||||
|
return RamUsageEstimator.sizeOf(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +309,7 @@ public final class BloomFilterPostingsFormat extends PostingsFormat {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean seekExact(BytesRef text, boolean useCache)
|
public final boolean seekExact(BytesRef text)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
// The magical fail-fast speed up that is the entire point of all of
|
// 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
|
// 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)) {
|
if (!filter.mightContain(text)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return getDelegate().seekExact(text, useCache);
|
return getDelegate().seekExact(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final SeekStatus seekCeil(BytesRef text, boolean useCache)
|
public final SeekStatus seekCeil(BytesRef text)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return getDelegate().seekCeil(text, useCache);
|
return getDelegate().seekCeil(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,9 +22,9 @@ package org.elasticsearch.index.fielddata.ordinals;
|
||||||
import org.apache.lucene.util.ArrayUtil;
|
import org.apache.lucene.util.ArrayUtil;
|
||||||
import org.apache.lucene.util.LongsRef;
|
import org.apache.lucene.util.LongsRef;
|
||||||
import org.apache.lucene.util.RamUsageEstimator;
|
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.PackedInts;
|
||||||
import org.apache.lucene.util.packed.XAppendingPackedLongBuffer;
|
|
||||||
import org.apache.lucene.util.packed.XMonotonicAppendingLongBuffer;
|
|
||||||
import org.elasticsearch.index.fielddata.ordinals.Ordinals.Docs.Iter;
|
import org.elasticsearch.index.fielddata.ordinals.Ordinals.Docs.Iter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,14 +55,14 @@ public class MultiOrdinals implements Ordinals {
|
||||||
|
|
||||||
private final boolean multiValued;
|
private final boolean multiValued;
|
||||||
private final long numOrds;
|
private final long numOrds;
|
||||||
private final XMonotonicAppendingLongBuffer endOffsets;
|
private final MonotonicAppendingLongBuffer endOffsets;
|
||||||
private final XAppendingPackedLongBuffer ords;
|
private final AppendingPackedLongBuffer ords;
|
||||||
|
|
||||||
public MultiOrdinals(OrdinalsBuilder builder, float acceptableOverheadRatio) {
|
public MultiOrdinals(OrdinalsBuilder builder, float acceptableOverheadRatio) {
|
||||||
multiValued = builder.getNumMultiValuesDocs() > 0;
|
multiValued = builder.getNumMultiValuesDocs() > 0;
|
||||||
numOrds = builder.getNumOrds();
|
numOrds = builder.getNumOrds();
|
||||||
endOffsets = new XMonotonicAppendingLongBuffer(OFFSET_INIT_PAGE_COUNT, OFFSETS_PAGE_SIZE, acceptableOverheadRatio);
|
endOffsets = new MonotonicAppendingLongBuffer(OFFSET_INIT_PAGE_COUNT, OFFSETS_PAGE_SIZE, acceptableOverheadRatio);
|
||||||
ords = new XAppendingPackedLongBuffer(OFFSET_INIT_PAGE_COUNT, OFFSETS_PAGE_SIZE, acceptableOverheadRatio);
|
ords = new AppendingPackedLongBuffer(OFFSET_INIT_PAGE_COUNT, OFFSETS_PAGE_SIZE, acceptableOverheadRatio);
|
||||||
long lastEndOffset = 0;
|
long lastEndOffset = 0;
|
||||||
for (int i = 0; i < builder.maxDoc(); ++i) {
|
for (int i = 0; i < builder.maxDoc(); ++i) {
|
||||||
final LongsRef docOrds = builder.docOrds(i);
|
final LongsRef docOrds = builder.docOrds(i);
|
||||||
|
@ -120,8 +120,8 @@ public class MultiOrdinals implements Ordinals {
|
||||||
static class MultiDocs implements Ordinals.Docs {
|
static class MultiDocs implements Ordinals.Docs {
|
||||||
|
|
||||||
private final MultiOrdinals ordinals;
|
private final MultiOrdinals ordinals;
|
||||||
private final XMonotonicAppendingLongBuffer endOffsets;
|
private final MonotonicAppendingLongBuffer endOffsets;
|
||||||
private final XAppendingPackedLongBuffer ords;
|
private final AppendingPackedLongBuffer ords;
|
||||||
private final LongsRef longsScratch;
|
private final LongsRef longsScratch;
|
||||||
private final MultiIter iter;
|
private final MultiIter iter;
|
||||||
|
|
||||||
|
@ -198,10 +198,10 @@ public class MultiOrdinals implements Ordinals {
|
||||||
|
|
||||||
static class MultiIter implements Iter {
|
static class MultiIter implements Iter {
|
||||||
|
|
||||||
final XAppendingPackedLongBuffer ordinals;
|
final AppendingPackedLongBuffer ordinals;
|
||||||
long offset, endOffset;
|
long offset, endOffset;
|
||||||
|
|
||||||
MultiIter(XAppendingPackedLongBuffer ordinals) {
|
MultiIter(AppendingPackedLongBuffer ordinals) {
|
||||||
this.ordinals = ordinals;
|
this.ordinals = ordinals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.apache.lucene.analysis.AnalyzerWrapper;
|
import org.apache.lucene.analysis.AnalyzerWrapper;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
import org.apache.lucene.queries.FilterClause;
|
import org.apache.lucene.queries.FilterClause;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.queries.TermsFilter;
|
import org.apache.lucene.queries.TermsFilter;
|
||||||
import org.apache.lucene.search.BooleanClause;
|
import org.apache.lucene.search.BooleanClause;
|
||||||
import org.apache.lucene.search.Filter;
|
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.io.Streams;
|
||||||
import org.elasticsearch.common.lucene.search.AndFilter;
|
import org.elasticsearch.common.lucene.search.AndFilter;
|
||||||
import org.elasticsearch.common.lucene.search.NotFilter;
|
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.lucene.search.XBooleanFilter;
|
||||||
import org.elasticsearch.common.regex.Regex;
|
import org.elasticsearch.common.regex.Regex;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.document.FieldType;
|
import org.apache.lucene.document.FieldType;
|
||||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.queries.TermsFilter;
|
import org.apache.lucene.queries.TermsFilter;
|
||||||
import org.apache.lucene.search.*;
|
import org.apache.lucene.search.*;
|
||||||
import org.apache.lucene.util.BytesRef;
|
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.BytesRefs;
|
||||||
import org.elasticsearch.common.lucene.Lucene;
|
import org.elasticsearch.common.lucene.Lucene;
|
||||||
import org.elasticsearch.common.lucene.search.RegexpFilter;
|
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.ImmutableSettings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.index.mapper.core;
|
||||||
import org.apache.lucene.document.Field;
|
import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.document.FieldType;
|
import org.apache.lucene.document.FieldType;
|
||||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||||
|
@ -29,7 +30,6 @@ import org.elasticsearch.common.Booleans;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.lucene.Lucene;
|
import org.elasticsearch.common.lucene.Lucene;
|
||||||
import org.elasticsearch.common.lucene.search.TermFilter;
|
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.document.FieldType;
|
import org.apache.lucene.document.FieldType;
|
||||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.queries.TermsFilter;
|
import org.apache.lucene.queries.TermsFilter;
|
||||||
import org.apache.lucene.search.ConstantScoreQuery;
|
import org.apache.lucene.search.ConstantScoreQuery;
|
||||||
import org.apache.lucene.search.Filter;
|
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.BytesRefs;
|
||||||
import org.elasticsearch.common.lucene.Lucene;
|
import org.elasticsearch.common.lucene.Lucene;
|
||||||
import org.elasticsearch.common.lucene.search.Queries;
|
import org.elasticsearch.common.lucene.search.Queries;
|
||||||
import org.elasticsearch.common.lucene.search.TermFilter;
|
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider;
|
import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider;
|
||||||
|
|
|
@ -23,13 +23,13 @@ import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.document.FieldType;
|
import org.apache.lucene.document.FieldType;
|
||||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.search.PrefixFilter;
|
import org.apache.lucene.search.PrefixFilter;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.lucene.BytesRefs;
|
import org.elasticsearch.common.lucene.BytesRefs;
|
||||||
import org.elasticsearch.common.lucene.Lucene;
|
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.XConstantScoreQuery;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.mapper.internal;
|
package org.elasticsearch.index.mapper.internal;
|
||||||
|
|
||||||
|
import org.apache.lucene.document.Document;
|
||||||
import org.apache.lucene.document.Field;
|
import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.document.FieldType;
|
import org.apache.lucene.document.FieldType;
|
||||||
import org.apache.lucene.document.NumericDocValuesField;
|
import org.apache.lucene.document.NumericDocValuesField;
|
||||||
|
@ -169,8 +170,10 @@ public class UidFieldMapper extends AbstractFieldMapper<Uid> implements Internal
|
||||||
assert uidField != null;
|
assert uidField != null;
|
||||||
// we need to go over the docs and add it...
|
// we need to go over the docs and add it...
|
||||||
for (int i = 1; i < context.docs().size(); i++) {
|
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
|
final Document doc = context.docs().get(i);
|
||||||
context.docs().get(i).add(new Field(UidFieldMapper.NAME, uidField.stringValue(), Defaults.NESTED_FIELD_TYPE));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,12 @@ import org.apache.lucene.document.Document;
|
||||||
import org.apache.lucene.document.Field;
|
import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.index.IndexableField;
|
import org.apache.lucene.index.IndexableField;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.ElasticSearchIllegalStateException;
|
import org.elasticsearch.ElasticSearchIllegalStateException;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.joda.FormatDateTimeFormatter;
|
import org.elasticsearch.common.joda.FormatDateTimeFormatter;
|
||||||
import org.elasticsearch.common.lucene.search.TermFilter;
|
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.lucene.index.*;
|
||||||
import org.apache.lucene.index.FieldInfo.DocValuesType;
|
import org.apache.lucene.index.FieldInfo.DocValuesType;
|
||||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
|
import org.apache.lucene.util.Bits;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.apache.lucene.util.packed.GrowableWriter;
|
import org.apache.lucene.util.packed.GrowableWriter;
|
||||||
import org.apache.lucene.util.packed.PackedInts;
|
import org.apache.lucene.util.packed.PackedInts;
|
||||||
|
@ -132,6 +133,10 @@ public final class IndexUpgraderMergePolicy extends MergePolicy {
|
||||||
}
|
}
|
||||||
return super.getNumericDocValues(field);
|
return super.getNumericDocValues(field);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public Bits getDocsWithField(String field) throws IOException {
|
||||||
|
return new Bits.MatchAllBits(in.maxDoc());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package org.elasticsearch.index.percolator;
|
package org.elasticsearch.index.percolator;
|
||||||
|
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.ElasticSearchException;
|
import org.elasticsearch.ElasticSearchException;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.lucene.HashedBytesRef;
|
import org.elasticsearch.common.lucene.HashedBytesRef;
|
||||||
import org.elasticsearch.common.lucene.search.TermFilter;
|
|
||||||
import org.elasticsearch.common.lucene.search.XConstantScoreQuery;
|
import org.elasticsearch.common.lucene.search.XConstantScoreQuery;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
|
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
|
||||||
|
|
|
@ -20,10 +20,10 @@
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.lucene.BytesRefs;
|
import org.elasticsearch.common.lucene.BytesRefs;
|
||||||
import org.elasticsearch.common.lucene.search.TermFilter;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.cache.filter.support.CacheKeyFilter;
|
import org.elasticsearch.index.cache.filter.support.CacheKeyFilter;
|
||||||
import org.elasticsearch.index.mapper.MapperService;
|
import org.elasticsearch.index.mapper.MapperService;
|
||||||
|
|
|
@ -21,13 +21,17 @@ package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.queries.TermsFilter;
|
import org.apache.lucene.queries.TermsFilter;
|
||||||
import org.apache.lucene.search.BooleanClause;
|
import org.apache.lucene.search.BooleanClause;
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.lucene.BytesRefs;
|
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.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.cache.filter.support.CacheKeyFilter;
|
import org.elasticsearch.index.cache.filter.support.CacheKeyFilter;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
|
|
|
@ -20,10 +20,10 @@
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.lucene.search.TermFilter;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||||
import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
|
import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
|
||||||
|
|
|
@ -24,6 +24,7 @@ import com.carrotsearch.hppc.ObjectIntOpenHashMap;
|
||||||
import org.apache.lucene.index.AtomicReaderContext;
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.search.*;
|
import org.apache.lucene.search.*;
|
||||||
import org.apache.lucene.util.Bits;
|
import org.apache.lucene.util.Bits;
|
||||||
import org.apache.lucene.util.BytesRef;
|
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.docset.DocIdSets;
|
||||||
import org.elasticsearch.common.lucene.search.ApplyAcceptedDocsFilter;
|
import org.elasticsearch.common.lucene.search.ApplyAcceptedDocsFilter;
|
||||||
import org.elasticsearch.common.lucene.search.Queries;
|
import org.elasticsearch.common.lucene.search.Queries;
|
||||||
import org.elasticsearch.common.lucene.search.TermFilter;
|
|
||||||
import org.elasticsearch.common.recycler.Recycler;
|
import org.elasticsearch.common.recycler.Recycler;
|
||||||
import org.elasticsearch.index.cache.id.IdReaderTypeCache;
|
import org.elasticsearch.index.cache.id.IdReaderTypeCache;
|
||||||
import org.elasticsearch.index.mapper.Uid;
|
import org.elasticsearch.index.mapper.Uid;
|
||||||
|
|
|
@ -23,6 +23,7 @@ import com.carrotsearch.hppc.ObjectOpenHashSet;
|
||||||
import org.apache.lucene.index.AtomicReaderContext;
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.search.DocIdSet;
|
import org.apache.lucene.search.DocIdSet;
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.search.Query;
|
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.DocIdSets;
|
||||||
import org.elasticsearch.common.lucene.docset.MatchDocIdSet;
|
import org.elasticsearch.common.lucene.docset.MatchDocIdSet;
|
||||||
import org.elasticsearch.common.lucene.search.Queries;
|
import org.elasticsearch.common.lucene.search.Queries;
|
||||||
import org.elasticsearch.common.lucene.search.TermFilter;
|
|
||||||
import org.elasticsearch.common.recycler.Recycler;
|
import org.elasticsearch.common.recycler.Recycler;
|
||||||
import org.elasticsearch.index.cache.id.IdReaderTypeCache;
|
import org.elasticsearch.index.cache.id.IdReaderTypeCache;
|
||||||
import org.elasticsearch.index.mapper.Uid;
|
import org.elasticsearch.index.mapper.Uid;
|
||||||
|
|
|
@ -75,7 +75,7 @@ final class ParentIdsFilter extends Filter {
|
||||||
idSpare.bytes = ((HashedBytesArray) keys[i]).toBytes();
|
idSpare.bytes = ((HashedBytesArray) keys[i]).toBytes();
|
||||||
idSpare.length = idSpare.bytes.length;
|
idSpare.length = idSpare.bytes.length;
|
||||||
Uid.createUidAsBytes(parentTypeBr, idSpare, uidSpare);
|
Uid.createUidAsBytes(parentTypeBr, idSpare, uidSpare);
|
||||||
if (termsEnum.seekExact(uidSpare, false)) {
|
if (termsEnum.seekExact(uidSpare)) {
|
||||||
int docId;
|
int docId;
|
||||||
docsEnum = termsEnum.docs(acceptDocs, docsEnum, DocsEnum.FLAG_NONE);
|
docsEnum = termsEnum.docs(acceptDocs, docsEnum, DocsEnum.FLAG_NONE);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
|
|
|
@ -950,7 +950,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("fixing index, writing new segments file ...");
|
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()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("index fixed, wrote new segments file \"{}\"", status.segmentsFileName);
|
logger.debug("index fixed, wrote new segments file \"{}\"", status.segmentsFileName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ public class DfsPhase implements SearchPhase {
|
||||||
IndexReaderContext indexReaderContext = context.searcher().getTopReaderContext();
|
IndexReaderContext indexReaderContext = context.searcher().getTopReaderContext();
|
||||||
for (int i = 0; i < terms.length; i++) {
|
for (int i = 0; i < terms.length; i++) {
|
||||||
// LUCENE 4 UPGRADE: cache TermContext?
|
// 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);
|
termStatistics[i] = context.searcher().termStatistics(terms[i], termContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,12 +25,10 @@ import org.apache.lucene.index.*;
|
||||||
import org.apache.lucene.index.FilterAtomicReader.FilterTerms;
|
import org.apache.lucene.index.FilterAtomicReader.FilterTerms;
|
||||||
import org.apache.lucene.search.suggest.Lookup;
|
import org.apache.lucene.search.suggest.Lookup;
|
||||||
import org.apache.lucene.store.IOContext.Context;
|
import org.apache.lucene.store.IOContext.Context;
|
||||||
import org.apache.lucene.store.IndexInput;
|
import org.apache.lucene.store.*;
|
||||||
import org.apache.lucene.store.IndexOutput;
|
|
||||||
import org.apache.lucene.store.InputStreamDataInput;
|
|
||||||
import org.apache.lucene.store.OutputStreamDataOutput;
|
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.apache.lucene.util.IOUtils;
|
import org.apache.lucene.util.IOUtils;
|
||||||
|
import org.apache.lucene.util.RamUsageEstimator;
|
||||||
import org.elasticsearch.ElasticSearchIllegalStateException;
|
import org.elasticsearch.ElasticSearchIllegalStateException;
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
import org.elasticsearch.common.logging.ESLogger;
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
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 FieldsProducer delegateProducer;
|
||||||
private LookupFactory lookupFactory;
|
private LookupFactory lookupFactory;
|
||||||
|
@ -267,6 +265,11 @@ public class Completion090PostingsFormat extends PostingsFormat {
|
||||||
public int size() {
|
public int size() {
|
||||||
return delegateProducer.size();
|
return delegateProducer.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long ramBytesUsed() {
|
||||||
|
return RamUsageEstimator.sizeOf(lookupFactory) + delegateProducer.ramBytesUsed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class CompletionTerms extends FilterTerms {
|
public static final class CompletionTerms extends FilterTerms {
|
||||||
|
|
|
@ -87,6 +87,7 @@ public final class CompletionTokenStream extends TokenStream {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void end() throws IOException {
|
public void end() throws IOException {
|
||||||
|
super.end();
|
||||||
if (posInc == -1) {
|
if (posInc == -1) {
|
||||||
input.end();
|
input.end();
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ public final class DirectCandidateGenerator extends CandidateGenerator {
|
||||||
|
|
||||||
|
|
||||||
public long internalFrequency(BytesRef term) throws IOException {
|
public long internalFrequency(BytesRef term) throws IOException {
|
||||||
if (termsEnum.seekExact(term, true)) {
|
if (termsEnum.seekExact(term)) {
|
||||||
return useTotalTermFrequency ? termsEnum.totalTermFreq() : termsEnum.docFreq();
|
return useTotalTermFrequency ? termsEnum.totalTermFreq() : termsEnum.docFreq();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -63,7 +63,7 @@ public abstract class WordScorer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public long frequency(BytesRef term) throws IOException {
|
public long frequency(BytesRef term) throws IOException {
|
||||||
if (termsEnum.seekExact(term, true)) {
|
if (termsEnum.seekExact(term)) {
|
||||||
return useTotalTermFreq ? termsEnum.totalTermFreq() : termsEnum.docFreq();
|
return useTotalTermFreq ? termsEnum.totalTermFreq() : termsEnum.docFreq();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.lucene.document.Document;
|
||||||
import org.apache.lucene.document.Field;
|
import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.document.StringField;
|
import org.apache.lucene.document.StringField;
|
||||||
import org.apache.lucene.index.*;
|
import org.apache.lucene.index.*;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.queries.TermsFilter;
|
import org.apache.lucene.queries.TermsFilter;
|
||||||
import org.apache.lucene.search.DocIdSet;
|
import org.apache.lucene.search.DocIdSet;
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
|
@ -56,7 +57,7 @@ public class TermsFilterTests {
|
||||||
w.commit();
|
w.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AtomicReader reader = new SlowCompositeReaderWrapper(DirectoryReader.open(w, true));
|
AtomicReader reader = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(w, true));
|
||||||
w.close();
|
w.close();
|
||||||
|
|
||||||
TermFilter tf = new TermFilter(new Term(fieldName, "19"));
|
TermFilter tf = new TermFilter(new Term(fieldName, "19"));
|
||||||
|
@ -92,7 +93,7 @@ public class TermsFilterTests {
|
||||||
w.commit();
|
w.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AtomicReader reader = new SlowCompositeReaderWrapper(DirectoryReader.open(w, true));
|
AtomicReader reader = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(w, true));
|
||||||
w.close();
|
w.close();
|
||||||
|
|
||||||
TermsFilter tf = new TermsFilter(new Term[]{new Term(fieldName, "19")});
|
TermsFilter tf = new TermsFilter(new Term[]{new Term(fieldName, "19")});
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class XBooleanFilterLuceneTests {
|
||||||
addDoc(writer, "admin", "020", "20050101", "Maybe");
|
addDoc(writer, "admin", "020", "20050101", "Maybe");
|
||||||
addDoc(writer, "admin guest", "030", "20050101", "N");
|
addDoc(writer, "admin guest", "030", "20050101", "N");
|
||||||
writer.close();
|
writer.close();
|
||||||
reader = new SlowCompositeReaderWrapper(DirectoryReader.open(directory));
|
reader = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(directory));
|
||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.document.StringField;
|
import org.apache.lucene.document.StringField;
|
||||||
import org.apache.lucene.index.*;
|
import org.apache.lucene.index.*;
|
||||||
import org.apache.lucene.queries.FilterClause;
|
import org.apache.lucene.queries.FilterClause;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.search.BooleanClause;
|
import org.apache.lucene.search.BooleanClause;
|
||||||
import org.apache.lucene.search.DocIdSet;
|
import org.apache.lucene.search.DocIdSet;
|
||||||
import org.apache.lucene.search.FieldCacheTermsFilter;
|
import org.apache.lucene.search.FieldCacheTermsFilter;
|
||||||
|
@ -52,7 +53,7 @@ public class XBooleanFilterTests {
|
||||||
IndexWriter w = new IndexWriter(directory, new IndexWriterConfig(Lucene.VERSION, new KeywordAnalyzer()));
|
IndexWriter w = new IndexWriter(directory, new IndexWriterConfig(Lucene.VERSION, new KeywordAnalyzer()));
|
||||||
w.addDocuments(documents);
|
w.addDocuments(documents);
|
||||||
w.close();
|
w.close();
|
||||||
reader = new SlowCompositeReaderWrapper(DirectoryReader.open(directory));
|
reader = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(directory));
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.lucene.document.Document;
|
||||||
import org.apache.lucene.document.Field;
|
import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.document.TextField;
|
import org.apache.lucene.document.TextField;
|
||||||
import org.apache.lucene.index.*;
|
import org.apache.lucene.index.*;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.search.ConstantScoreQuery;
|
import org.apache.lucene.search.ConstantScoreQuery;
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.search.IndexSearcher;
|
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.Directory;
|
||||||
import org.apache.lucene.store.RAMDirectory;
|
import org.apache.lucene.store.RAMDirectory;
|
||||||
import org.elasticsearch.common.lucene.Lucene;
|
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.XConstantScoreQuery;
|
||||||
import org.elasticsearch.common.lucene.search.XFilteredQuery;
|
import org.elasticsearch.common.lucene.search.XFilteredQuery;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
|
|
|
@ -19,30 +19,13 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.codec.postingformat;
|
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.analysis.core.WhitespaceAnalyzer;
|
||||||
import org.apache.lucene.codecs.Codec;
|
import org.apache.lucene.codecs.Codec;
|
||||||
import org.apache.lucene.codecs.PostingsFormat;
|
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.Field.Store;
|
||||||
import org.apache.lucene.document.TextField;
|
import org.apache.lucene.document.TextField;
|
||||||
import org.apache.lucene.index.AtomicReader;
|
import org.apache.lucene.index.*;
|
||||||
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.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
import org.apache.lucene.store.RAMDirectory;
|
import org.apache.lucene.store.RAMDirectory;
|
||||||
import org.elasticsearch.common.lucene.Lucene;
|
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.elasticsearch.index.mapper.internal.UidFieldMapper;
|
||||||
import org.junit.Test;
|
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}
|
* Simple smoke test for {@link ElasticSearch090PostingsFormat}
|
||||||
*/
|
*/
|
||||||
public class DefaultPostingsFormatTests {
|
public class DefaultPostingsFormatTests {
|
||||||
|
|
||||||
private final class TestCodec extends Lucene42Codec {
|
private final class TestCodec extends Lucene45Codec {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PostingsFormat getPostingsFormatForField(String field) {
|
public PostingsFormat getPostingsFormatForField(String field) {
|
||||||
|
|
|
@ -53,7 +53,7 @@ public abstract class AbstractFieldDataTests extends ElasticSearchTestCase {
|
||||||
if (readerContext != null) {
|
if (readerContext != null) {
|
||||||
readerContext.reader().close();
|
readerContext.reader().close();
|
||||||
}
|
}
|
||||||
AtomicReader reader = new SlowCompositeReaderWrapper(DirectoryReader.open(writer, true));
|
AtomicReader reader = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(writer, true));
|
||||||
readerContext = reader.getContext();
|
readerContext = reader.getContext();
|
||||||
return readerContext;
|
return readerContext;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,9 @@ import org.apache.lucene.document.Field.Store;
|
||||||
import org.apache.lucene.document.StringField;
|
import org.apache.lucene.document.StringField;
|
||||||
import org.apache.lucene.index.DirectoryReader;
|
import org.apache.lucene.index.DirectoryReader;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.search.*;
|
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.ScoreMode;
|
||||||
import org.apache.lucene.search.join.ToParentBlockJoinQuery;
|
import org.apache.lucene.search.join.ToParentBlockJoinQuery;
|
||||||
import org.apache.lucene.util.BytesRef;
|
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.UnicodeUtil;
|
||||||
import org.apache.lucene.util._TestUtil;
|
import org.apache.lucene.util._TestUtil;
|
||||||
import org.elasticsearch.common.lucene.search.NotFilter;
|
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.lucene.search.XFilteredQuery;
|
||||||
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource;
|
import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource;
|
||||||
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
|
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 parentFilter = new TermFilter(new Term("type", "parent"));
|
||||||
Filter childFilter = new NotFilter(parentFilter);
|
Filter childFilter = new NotFilter(parentFilter);
|
||||||
NestedFieldComparatorSource nestedComparatorSource = new NestedFieldComparatorSource(sortMode, innerSource, parentFilter, childFilter);
|
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));
|
Sort sort = new Sort(new SortField("text", nestedComparatorSource));
|
||||||
TopFieldDocs topDocs = searcher.search(query, randomIntBetween(1, numParents), sort);
|
TopFieldDocs topDocs = searcher.search(query, randomIntBetween(1, numParents), sort);
|
||||||
assertTrue(topDocs.scoreDocs.length > 0);
|
assertTrue(topDocs.scoreDocs.length > 0);
|
||||||
|
|
|
@ -22,10 +22,7 @@ package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
import org.apache.lucene.queries.BoostingQuery;
|
import org.apache.lucene.queries.*;
|
||||||
import org.apache.lucene.queries.ExtendedCommonTermsQuery;
|
|
||||||
import org.apache.lucene.queries.FilterClause;
|
|
||||||
import org.apache.lucene.queries.TermsFilter;
|
|
||||||
import org.apache.lucene.sandbox.queries.FuzzyLikeThisQuery;
|
import org.apache.lucene.sandbox.queries.FuzzyLikeThisQuery;
|
||||||
import org.apache.lucene.search.*;
|
import org.apache.lucene.search.*;
|
||||||
import org.apache.lucene.search.spans.*;
|
import org.apache.lucene.search.spans.*;
|
||||||
|
@ -2227,8 +2224,8 @@ public class SimpleIndexQueryParserTests extends ElasticSearchTestCase {
|
||||||
Query parsedQuery = queryParser.parse(query).query();
|
Query parsedQuery = queryParser.parse(query).query();
|
||||||
assertThat(parsedQuery, instanceOf(ExtendedCommonTermsQuery.class));
|
assertThat(parsedQuery, instanceOf(ExtendedCommonTermsQuery.class));
|
||||||
ExtendedCommonTermsQuery ectQuery = (ExtendedCommonTermsQuery) parsedQuery;
|
ExtendedCommonTermsQuery ectQuery = (ExtendedCommonTermsQuery) parsedQuery;
|
||||||
assertThat(ectQuery.getHighFreqMinimumNumberShouldMatch(), nullValue());
|
assertThat(ectQuery.getHighFreqMinimumNumberShouldMatchSpec(), nullValue());
|
||||||
assertThat(ectQuery.getLowFreqMinimumNumberShouldMatch(), equalTo("2"));
|
assertThat(ectQuery.getLowFreqMinimumNumberShouldMatchSpec(), equalTo("2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2238,8 +2235,8 @@ public class SimpleIndexQueryParserTests extends ElasticSearchTestCase {
|
||||||
Query parsedQuery = queryParser.parse(query).query();
|
Query parsedQuery = queryParser.parse(query).query();
|
||||||
assertThat(parsedQuery, instanceOf(ExtendedCommonTermsQuery.class));
|
assertThat(parsedQuery, instanceOf(ExtendedCommonTermsQuery.class));
|
||||||
ExtendedCommonTermsQuery ectQuery = (ExtendedCommonTermsQuery) parsedQuery;
|
ExtendedCommonTermsQuery ectQuery = (ExtendedCommonTermsQuery) parsedQuery;
|
||||||
assertThat(ectQuery.getHighFreqMinimumNumberShouldMatch(), equalTo("50%"));
|
assertThat(ectQuery.getHighFreqMinimumNumberShouldMatchSpec(), equalTo("50%"));
|
||||||
assertThat(ectQuery.getLowFreqMinimumNumberShouldMatch(), equalTo("5<20%"));
|
assertThat(ectQuery.getLowFreqMinimumNumberShouldMatchSpec(), equalTo("5<20%"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2249,8 +2246,8 @@ public class SimpleIndexQueryParserTests extends ElasticSearchTestCase {
|
||||||
Query parsedQuery = queryParser.parse(query).query();
|
Query parsedQuery = queryParser.parse(query).query();
|
||||||
assertThat(parsedQuery, instanceOf(ExtendedCommonTermsQuery.class));
|
assertThat(parsedQuery, instanceOf(ExtendedCommonTermsQuery.class));
|
||||||
ExtendedCommonTermsQuery ectQuery = (ExtendedCommonTermsQuery) parsedQuery;
|
ExtendedCommonTermsQuery ectQuery = (ExtendedCommonTermsQuery) parsedQuery;
|
||||||
assertThat(ectQuery.getHighFreqMinimumNumberShouldMatch(), nullValue());
|
assertThat(ectQuery.getHighFreqMinimumNumberShouldMatchSpec(), nullValue());
|
||||||
assertThat(ectQuery.getLowFreqMinimumNumberShouldMatch(), equalTo("2"));
|
assertThat(ectQuery.getLowFreqMinimumNumberShouldMatchSpec(), equalTo("2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = QueryParsingException.class)
|
@Test(expected = QueryParsingException.class)
|
||||||
|
|
|
@ -25,22 +25,22 @@ import org.apache.lucene.document.StringField;
|
||||||
import org.apache.lucene.index.DirectoryReader;
|
import org.apache.lucene.index.DirectoryReader;
|
||||||
import org.apache.lucene.index.IndexableField;
|
import org.apache.lucene.index.IndexableField;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.search.*;
|
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.ScoreMode;
|
||||||
import org.apache.lucene.search.join.ToParentBlockJoinQuery;
|
import org.apache.lucene.search.join.ToParentBlockJoinQuery;
|
||||||
import org.elasticsearch.common.lucene.search.NotFilter;
|
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.lucene.search.XFilteredQuery;
|
||||||
|
import org.elasticsearch.index.fielddata.AbstractFieldDataTests;
|
||||||
import org.elasticsearch.index.fielddata.IndexFieldData;
|
import org.elasticsearch.index.fielddata.IndexFieldData;
|
||||||
import org.elasticsearch.index.fielddata.fieldcomparator.SortMode;
|
import org.elasticsearch.index.fielddata.fieldcomparator.SortMode;
|
||||||
import org.elasticsearch.index.fielddata.AbstractFieldDataTests;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
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 parentFilter = new TermFilter(new Term("__type", "parent"));
|
||||||
Filter childFilter = new NotFilter(parentFilter);
|
Filter childFilter = new NotFilter(parentFilter);
|
||||||
NestedFieldComparatorSource nestedComparatorSource = new NestedFieldComparatorSource(sortMode, innerFieldComparator, parentFilter, childFilter);
|
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));
|
Sort sort = new Sort(new SortField("field2", nestedComparatorSource));
|
||||||
TopFieldDocs topDocs = searcher.search(query, 5, sort);
|
TopFieldDocs topDocs = searcher.search(query, 5, sort);
|
||||||
|
@ -247,7 +247,7 @@ public abstract class AbstractNumberNestedSortingTests extends AbstractFieldData
|
||||||
nestedComparatorSource = new NestedFieldComparatorSource(sortMode, innerFieldComparator, parentFilter, childFilter);
|
nestedComparatorSource = new NestedFieldComparatorSource(sortMode, innerFieldComparator, parentFilter, childFilter);
|
||||||
query = new ToParentBlockJoinQuery(
|
query = new ToParentBlockJoinQuery(
|
||||||
new XFilteredQuery(new MatchAllDocsQuery(), childFilter),
|
new XFilteredQuery(new MatchAllDocsQuery(), childFilter),
|
||||||
new CachingWrapperFilter(parentFilter),
|
new FixedBitSetCachingWrapperFilter(parentFilter),
|
||||||
ScoreMode.None
|
ScoreMode.None
|
||||||
);
|
);
|
||||||
sort = new Sort(new SortField("field2", nestedComparatorSource, true));
|
sort = new Sort(new SortField("field2", nestedComparatorSource, true));
|
||||||
|
@ -324,7 +324,7 @@ public abstract class AbstractNumberNestedSortingTests extends AbstractFieldData
|
||||||
SortMode sortMode = SortMode.AVG;
|
SortMode sortMode = SortMode.AVG;
|
||||||
Filter childFilter = new NotFilter(parentFilter);
|
Filter childFilter = new NotFilter(parentFilter);
|
||||||
NestedFieldComparatorSource nestedComparatorSource = new NestedFieldComparatorSource(sortMode, innerFieldComparator, parentFilter, childFilter);
|
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));
|
Sort sort = new Sort(new SortField("field2", nestedComparatorSource));
|
||||||
TopDocs topDocs = searcher.search(query, 5, sort);
|
TopDocs topDocs = searcher.search(query, 5, sort);
|
||||||
assertThat(topDocs.totalHits, equalTo(7));
|
assertThat(topDocs.totalHits, equalTo(7));
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.lucene.document.DoubleField;
|
||||||
import org.apache.lucene.document.Field;
|
import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.index.IndexableField;
|
import org.apache.lucene.index.IndexableField;
|
||||||
import org.apache.lucene.search.*;
|
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.ScoreMode;
|
||||||
import org.apache.lucene.search.join.ToParentBlockJoinQuery;
|
import org.apache.lucene.search.join.ToParentBlockJoinQuery;
|
||||||
import org.elasticsearch.common.lucene.search.NotFilter;
|
import org.elasticsearch.common.lucene.search.NotFilter;
|
||||||
|
@ -35,7 +36,6 @@ import org.elasticsearch.index.fielddata.plain.DoubleArrayIndexFieldData;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,7 +62,7 @@ public class DoubleNestedSortingTests extends AbstractNumberNestedSortingTests {
|
||||||
SortMode sortMode = SortMode.AVG;
|
SortMode sortMode = SortMode.AVG;
|
||||||
Filter childFilter = new NotFilter(parentFilter);
|
Filter childFilter = new NotFilter(parentFilter);
|
||||||
NestedFieldComparatorSource nestedComparatorSource = new NestedFieldComparatorSource(sortMode, innerFieldComparator, parentFilter, childFilter);
|
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));
|
Sort sort = new Sort(new SortField("field2", nestedComparatorSource));
|
||||||
TopDocs topDocs = searcher.search(query, 5, sort);
|
TopDocs topDocs = searcher.search(query, 5, sort);
|
||||||
assertThat(topDocs.totalHits, equalTo(7));
|
assertThat(topDocs.totalHits, equalTo(7));
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.document.FloatField;
|
import org.apache.lucene.document.FloatField;
|
||||||
import org.apache.lucene.index.IndexableField;
|
import org.apache.lucene.index.IndexableField;
|
||||||
import org.apache.lucene.search.*;
|
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.ScoreMode;
|
||||||
import org.apache.lucene.search.join.ToParentBlockJoinQuery;
|
import org.apache.lucene.search.join.ToParentBlockJoinQuery;
|
||||||
import org.elasticsearch.common.lucene.search.NotFilter;
|
import org.elasticsearch.common.lucene.search.NotFilter;
|
||||||
|
@ -35,7 +36,6 @@ import org.elasticsearch.index.fielddata.plain.FloatArrayIndexFieldData;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,7 +62,7 @@ public class FloatNestedSortingTests extends AbstractNumberNestedSortingTests {
|
||||||
SortMode sortMode = SortMode.AVG;
|
SortMode sortMode = SortMode.AVG;
|
||||||
Filter childFilter = new NotFilter(parentFilter);
|
Filter childFilter = new NotFilter(parentFilter);
|
||||||
NestedFieldComparatorSource nestedComparatorSource = new NestedFieldComparatorSource(sortMode, innerFieldComparator, parentFilter, childFilter);
|
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));
|
Sort sort = new Sort(new SortField("field2", nestedComparatorSource));
|
||||||
TopDocs topDocs = searcher.search(query, 5, sort);
|
TopDocs topDocs = searcher.search(query, 5, sort);
|
||||||
assertThat(topDocs.totalHits, equalTo(7));
|
assertThat(topDocs.totalHits, equalTo(7));
|
||||||
|
|
|
@ -25,20 +25,21 @@ import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.document.StringField;
|
import org.apache.lucene.document.StringField;
|
||||||
import org.apache.lucene.index.DirectoryReader;
|
import org.apache.lucene.index.DirectoryReader;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
|
import org.apache.lucene.queries.TermFilter;
|
||||||
import org.apache.lucene.search.*;
|
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.ScoreMode;
|
||||||
import org.apache.lucene.search.join.ToParentBlockJoinQuery;
|
import org.apache.lucene.search.join.ToParentBlockJoinQuery;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.elasticsearch.common.lucene.search.AndFilter;
|
import org.elasticsearch.common.lucene.search.AndFilter;
|
||||||
import org.elasticsearch.common.lucene.search.NotFilter;
|
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.lucene.search.XFilteredQuery;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
|
import org.elasticsearch.index.fielddata.AbstractFieldDataTests;
|
||||||
import org.elasticsearch.index.fielddata.FieldDataType;
|
import org.elasticsearch.index.fielddata.FieldDataType;
|
||||||
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
|
import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparatorSource;
|
||||||
import org.elasticsearch.index.fielddata.fieldcomparator.SortMode;
|
import org.elasticsearch.index.fielddata.fieldcomparator.SortMode;
|
||||||
import org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData;
|
import org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData;
|
||||||
import org.elasticsearch.index.fielddata.AbstractFieldDataTests;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -218,7 +219,7 @@ public class NestedSortingTests extends AbstractFieldDataTests {
|
||||||
Filter parentFilter = new TermFilter(new Term("__type", "parent"));
|
Filter parentFilter = new TermFilter(new Term("__type", "parent"));
|
||||||
Filter childFilter = new NotFilter(parentFilter);
|
Filter childFilter = new NotFilter(parentFilter);
|
||||||
NestedFieldComparatorSource nestedComparatorSource = new NestedFieldComparatorSource(sortMode, innerSource, parentFilter, childFilter);
|
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));
|
Sort sort = new Sort(new SortField("field2", nestedComparatorSource));
|
||||||
TopFieldDocs topDocs = searcher.search(query, 5, sort);
|
TopFieldDocs topDocs = searcher.search(query, 5, sort);
|
||||||
|
@ -257,7 +258,7 @@ public class NestedSortingTests extends AbstractFieldDataTests {
|
||||||
nestedComparatorSource = new NestedFieldComparatorSource(sortMode, innerSource, parentFilter, childFilter);
|
nestedComparatorSource = new NestedFieldComparatorSource(sortMode, innerSource, parentFilter, childFilter);
|
||||||
query = new ToParentBlockJoinQuery(
|
query = new ToParentBlockJoinQuery(
|
||||||
new XFilteredQuery(new MatchAllDocsQuery(), childFilter),
|
new XFilteredQuery(new MatchAllDocsQuery(), childFilter),
|
||||||
new CachingWrapperFilter(parentFilter),
|
new FixedBitSetCachingWrapperFilter(parentFilter),
|
||||||
ScoreMode.None
|
ScoreMode.None
|
||||||
);
|
);
|
||||||
sort = new Sort(new SortField("field2", nestedComparatorSource, true));
|
sort = new Sort(new SortField("field2", nestedComparatorSource, true));
|
||||||
|
|
Loading…
Reference in New Issue