Upgrade to lucene-5.3.0.

From a user perspective, the main benefit from this upgrade is that the new
Lucene53Codec has disk-based norms. The elasticsearch directory has been fixed
to load these norms through mmap instead of nio.

Other changes include the removal of `max_thread_states`, the fact that
PhraseQuery and BooleanQuery are now immutable, and that deleted docs are now
applied on top of the Scorer API.

This change introduces a couple of `AwaitsFix`s but I don't think it should
hold us from merging.
This commit is contained in:
Adrien Grand 2015-08-04 11:42:29 +02:00
parent 7571276b84
commit 5d9fb2e8a6
115 changed files with 548 additions and 816 deletions
core/src
main/java/org
apache/lucene
elasticsearch
Version.java
action/termvectors
common
env
index
indices/cache/query
search
test/java/org/elasticsearch
distribution/licenses

@ -27,7 +27,6 @@ import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Weight;
import org.apache.lucene.util.Bits;
import java.io.IOException;
@ -60,7 +59,7 @@ public final class MinDocQuery extends Query {
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
return new ConstantScoreWeight(this) {
@Override
public Scorer scorer(LeafReaderContext context, final Bits acceptDocs) throws IOException {
public Scorer scorer(LeafReaderContext context) throws IOException {
final int maxDoc = context.reader().maxDoc();
if (context.docBase + maxDoc <= minDoc) {
return null;
@ -89,12 +88,6 @@ public final class MinDocQuery extends Query {
} else {
doc = target;
}
while (doc < maxDoc) {
if (acceptDocs == null || acceptDocs.get(doc)) {
break;
}
doc += 1;
}
if (doc >= maxDoc) {
doc = NO_MORE_DOCS;
}

@ -279,7 +279,7 @@ public class MapperQueryParser extends QueryParser {
if (q != null) {
added = true;
applyBoost(mField, q);
applySlop(q, slop);
q = applySlop(q, slop);
disMaxQuery.add(q);
}
}
@ -293,7 +293,7 @@ public class MapperQueryParser extends QueryParser {
Query q = super.getFieldQuery(mField, queryText, slop);
if (q != null) {
applyBoost(mField, q);
applySlop(q, slop);
q = applySlop(q, slop);
clauses.add(new BooleanClause(q, BooleanClause.Occur.SHOULD));
}
}
@ -718,15 +718,6 @@ public class MapperQueryParser extends QueryParser {
return super.getWildcardQuery(field, aggStr.toString());
}
@Override
protected WildcardQuery newWildcardQuery(Term t) {
// Backport: https://issues.apache.org/jira/browse/LUCENE-6677
assert Version.LATEST == Version.LUCENE_5_2_1;
WildcardQuery query = new WildcardQuery(t, maxDeterminizedStates);
query.setRewriteMethod(multiTermRewriteMethod);
return query;
}
@Override
protected Query getRegexpQuery(String field, String termStr) throws ParseException {
if (lowercaseExpandedTerms) {
@ -815,14 +806,24 @@ public class MapperQueryParser extends QueryParser {
}
}
private void applySlop(Query q, int slop) {
if (q instanceof FilteredQuery) {
applySlop(((FilteredQuery)q).getQuery(), slop);
}
private Query applySlop(Query q, int slop) {
if (q instanceof PhraseQuery) {
((PhraseQuery) q).setSlop(slop);
PhraseQuery pq = (PhraseQuery) q;
PhraseQuery.Builder builder = new PhraseQuery.Builder();
builder.setSlop(slop);
final Term[] terms = pq.getTerms();
final int[] positions = pq.getPositions();
for (int i = 0; i < terms.length; ++i) {
builder.add(terms[i], positions[i]);
}
pq = builder.build();
pq.setBoost(q.getBoost());
return pq;
} else if (q instanceof MultiPhraseQuery) {
((MultiPhraseQuery) q).setSlop(slop);
return q;
} else {
return q;
}
}

@ -1,153 +0,0 @@
/*
Licensed to Elasticsearch 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.apache.lucene.search.postingshighlight;
import java.text.BreakIterator;
import java.text.CharacterIterator;
/**
* A {@link BreakIterator} that breaks the text whenever a certain separator, provided as a constructor argument, is found.
*/
public class CustomSeparatorBreakIterator extends BreakIterator {
private final char separator;
private CharacterIterator text;
private int current;
public CustomSeparatorBreakIterator(char separator) {
this.separator = separator;
}
@Override
public int current() {
return current;
}
@Override
public int first() {
text.setIndex(text.getBeginIndex());
return current = text.getIndex();
}
@Override
public int last() {
text.setIndex(text.getEndIndex());
return current = text.getIndex();
}
@Override
public int next() {
if (text.getIndex() == text.getEndIndex()) {
return DONE;
} else {
return advanceForward();
}
}
private int advanceForward() {
char c;
while( (c = text.next()) != CharacterIterator.DONE) {
if (c == separator) {
return current = text.getIndex() + 1;
}
}
assert text.getIndex() == text.getEndIndex();
return current = text.getIndex();
}
@Override
public int following(int pos) {
if (pos < text.getBeginIndex() || pos > text.getEndIndex()) {
throw new IllegalArgumentException("offset out of bounds");
} else if (pos == text.getEndIndex()) {
// this conflicts with the javadocs, but matches actual behavior (Oracle has a bug in something)
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=9000909
text.setIndex(text.getEndIndex());
current = text.getIndex();
return DONE;
} else {
text.setIndex(pos);
current = text.getIndex();
return advanceForward();
}
}
@Override
public int previous() {
if (text.getIndex() == text.getBeginIndex()) {
return DONE;
} else {
return advanceBackward();
}
}
private int advanceBackward() {
char c;
while( (c = text.previous()) != CharacterIterator.DONE) {
if (c == separator) {
return current = text.getIndex() + 1;
}
}
assert text.getIndex() == text.getBeginIndex();
return current = text.getIndex();
}
@Override
public int preceding(int pos) {
if (pos < text.getBeginIndex() || pos > text.getEndIndex()) {
throw new IllegalArgumentException("offset out of bounds");
} else if (pos == text.getBeginIndex()) {
// this conflicts with the javadocs, but matches actual behavior (Oracle has a bug in something)
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=9000909
text.setIndex(text.getBeginIndex());
current = text.getIndex();
return DONE;
} else {
text.setIndex(pos);
current = text.getIndex();
return advanceBackward();
}
}
@Override
public int next(int n) {
if (n < 0) {
for (int i = 0; i < -n; i++) {
previous();
}
} else {
for (int i = 0; i < n; i++) {
next();
}
}
return current();
}
@Override
public CharacterIterator getText() {
return text;
}
@Override
public void setText(CharacterIterator newText) {
text = newText;
current = text.getBeginIndex();
}
}

@ -28,6 +28,7 @@ import org.apache.lucene.search.suggest.Lookup;
import org.apache.lucene.store.*;
import org.apache.lucene.util.*;
import org.apache.lucene.util.automaton.Automaton;
import org.apache.lucene.util.automaton.LimitedFiniteStringsIterator;
import org.apache.lucene.util.automaton.Operations;
import org.apache.lucene.util.automaton.Transition;
import org.apache.lucene.util.fst.*;
@ -465,16 +466,12 @@ public long ramBytesUsed() {
byte buffer[] = new byte[8];
try {
ByteArrayDataOutput output = new ByteArrayDataOutput(buffer);
BytesRef surfaceForm;
while ((surfaceForm = iterator.next()) != null) {
Set<IntsRef> paths = toFiniteStrings(surfaceForm, ts2a);
maxAnalyzedPathsForOneInput = Math.max(maxAnalyzedPathsForOneInput, paths.size());
for (IntsRef path : paths) {
Util.toBytesRef(path, scratch);
for (BytesRef surfaceForm; (surfaceForm = iterator.next()) != null;) {
LimitedFiniteStringsIterator finiteStrings =
new LimitedFiniteStringsIterator(toAutomaton(surfaceForm, ts2a), maxGraphExpansions);
for (IntsRef string; (string = finiteStrings.next()) != null; count++) {
Util.toBytesRef(string, scratch);
// length of the analyzed text (FST input)
if (scratch.length() > Short.MAX_VALUE-2) {
@ -526,7 +523,7 @@ public long ramBytesUsed() {
writer.write(buffer, 0, output.getPosition());
}
count++;
maxAnalyzedPathsForOneInput = Math.max(maxAnalyzedPathsForOneInput, finiteStrings.size());
}
writer.close();
@ -912,23 +909,17 @@ public long ramBytesUsed() {
return prefixPaths;
}
public final Set<IntsRef> toFiniteStrings(final BytesRef surfaceForm, final TokenStreamToAutomaton ts2a) throws IOException {
// Analyze surface form:
TokenStream ts = indexAnalyzer.tokenStream("", surfaceForm.utf8ToString());
return toFiniteStrings(ts2a, ts);
final Automaton toAutomaton(final BytesRef surfaceForm, final TokenStreamToAutomaton ts2a) throws IOException {
try (TokenStream ts = indexAnalyzer.tokenStream("", surfaceForm.utf8ToString())) {
return toAutomaton(ts, ts2a);
}
}
public final Set<IntsRef> toFiniteStrings(final TokenStreamToAutomaton ts2a, final TokenStream ts) throws IOException {
Automaton automaton = null;
try {
final Automaton toAutomaton(TokenStream ts, final TokenStreamToAutomaton ts2a) throws IOException {
// Create corresponding automaton: labels are bytes
// from each analyzed token, with byte 0 used as
// separator between tokens:
automaton = ts2a.toAutomaton(ts);
} finally {
IOUtils.closeWhileHandlingException(ts);
}
Automaton automaton = ts2a.toAutomaton(ts);
automaton = replaceSep(automaton);
automaton = convertAutomaton(automaton);
@ -940,11 +931,24 @@ public long ramBytesUsed() {
// more than one path, eg if the analyzer created a
// graph using SynFilter or WDF):
// TODO: we could walk & add simultaneously, so we
// don't have to alloc [possibly biggish]
// intermediate HashSet in RAM:
return automaton;
}
return Operations.getFiniteStrings(automaton, maxGraphExpansions);
// EDIT: Adrien, needed by lookup providers
// NOTE: these XForks are unmaintainable, we need to get rid of them...
public Set<IntsRef> toFiniteStrings(TokenStream stream) throws IOException {
final TokenStreamToAutomaton ts2a = getTokenStreamToAutomaton();
Automaton automaton;
try (TokenStream ts = stream) {
automaton = toAutomaton(ts, ts2a);
}
LimitedFiniteStringsIterator finiteStrings =
new LimitedFiniteStringsIterator(automaton, maxGraphExpansions);
Set<IntsRef> set = new HashSet<>();
for (IntsRef string = finiteStrings.next(); string != null; string = finiteStrings.next()) {
set.add(IntsRef.deepCopyOf(string));
}
return Collections.unmodifiableSet(set);
}
final Automaton toLookupAutomaton(final CharSequence key) throws IOException {

@ -28,9 +28,10 @@ import org.apache.lucene.util.fst.FST;
import org.apache.lucene.util.fst.PairOutputs;
import java.io.IOException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import static org.apache.lucene.util.automaton.Operations.DEFAULT_MAX_DETERMINIZED_STATES;
/**
* Implements a fuzzy {@link AnalyzingSuggester}. The similarity measurement is
@ -221,42 +222,37 @@ public final class XFuzzySuggester extends XAnalyzingSuggester {
}
Automaton toLevenshteinAutomata(Automaton automaton) {
final Set<IntsRef> ref = Operations.getFiniteStrings(automaton, -1);
Automaton subs[] = new Automaton[ref.size()];
int upto = 0;
for (IntsRef path : ref) {
if (path.length <= nonFuzzyPrefix || path.length < minFuzzyLength) {
subs[upto] = Automata.makeString(path.ints, path.offset, path.length);
upto++;
List<Automaton> subs = new ArrayList<>();
FiniteStringsIterator finiteStrings = new FiniteStringsIterator(automaton);
for (IntsRef string; (string = finiteStrings.next()) != null;) {
if (string.length <= nonFuzzyPrefix || string.length < minFuzzyLength) {
subs.add(Automata.makeString(string.ints, string.offset, string.length));
} else {
int ints[] = new int[path.length-nonFuzzyPrefix];
System.arraycopy(path.ints, path.offset+nonFuzzyPrefix, ints, 0, ints.length);
int ints[] = new int[string.length-nonFuzzyPrefix];
System.arraycopy(string.ints, string.offset+nonFuzzyPrefix, ints, 0, ints.length);
// TODO: maybe add alphaMin to LevenshteinAutomata,
// and pass 1 instead of 0? We probably don't want
// to allow the trailing dedup bytes to be
// edited... but then 0 byte is "in general" allowed
// on input (but not in UTF8).
LevenshteinAutomata lev = new LevenshteinAutomata(ints, unicodeAware ? Character.MAX_CODE_POINT : 255, transpositions);
subs[upto] = lev.toAutomaton(maxEdits, UnicodeUtil.newString(path.ints, path.offset, nonFuzzyPrefix));
upto++;
subs.add(lev.toAutomaton(maxEdits, UnicodeUtil.newString(string.ints, string.offset, nonFuzzyPrefix)));
}
}
if (subs.length == 0) {
if (subs.isEmpty()) {
// automaton is empty, there is no accepted paths through it
return Automata.makeEmpty(); // matches nothing
} else if (subs.length == 1) {
} else if (subs.size() == 1) {
// no synonyms or anything: just a single path through the tokenstream
return subs[0];
return subs.get(0);
} else {
// multiple paths: this is really scary! is it slow?
// maybe we should not do this and throw UOE?
Automaton a = Operations.union(Arrays.asList(subs));
Automaton a = Operations.union(subs);
// TODO: we could call toLevenshteinAutomata() before det?
// this only happens if you have multiple paths anyway (e.g. synonyms)
// This automaton should not blow up during determinize:
return Operations.determinize(a, Integer.MAX_VALUE);
return Operations.determinize(a, DEFAULT_MAX_DETERMINIZED_STATES);
}
}
}

@ -258,7 +258,7 @@ public class Version {
public static final int V_2_0_0_ID = 2000099;
public static final Version V_2_0_0 = new Version(V_2_0_0_ID, true, org.apache.lucene.util.Version.LUCENE_5_2_1);
public static final int V_2_1_0_ID = 2010099;
public static final Version V_2_1_0 = new Version(V_2_1_0_ID, true, org.apache.lucene.util.Version.LUCENE_5_2_1);
public static final Version V_2_1_0 = new Version(V_2_1_0_ID, true, org.apache.lucene.util.Version.LUCENE_5_3_0);
public static final Version CURRENT = V_2_1_0;

@ -336,7 +336,7 @@ public final class TermVectorsFields extends Fields {
}
@Override
public PostingsEnum postings(Bits liveDocs, PostingsEnum reuse, int flags) throws IOException {
public PostingsEnum postings(PostingsEnum reuse, int flags) throws IOException {
final TermVectorPostingsEnum retVal = (reuse instanceof TermVectorPostingsEnum ? (TermVectorPostingsEnum) reuse
: new TermVectorPostingsEnum());
return retVal.reset(hasPositions ? positions : null, hasOffsets ? startOffsets : null, hasOffsets ? endOffsets

@ -286,7 +286,7 @@ public class TermVectorsFilter {
}
private int getTermFreq(TermsEnum termsEnum, PostingsEnum docsEnum) throws IOException {
docsEnum = termsEnum.postings(null, docsEnum);
docsEnum = termsEnum.postings(docsEnum);
docsEnum.nextDoc();
return docsEnum.freq();
}

@ -220,7 +220,7 @@ public class TermVectorsResponse extends ActionResponse implements ToXContent {
builder.startObject(spare.toString());
buildTermStatistics(builder, termIter);
// finally write the term vectors
PostingsEnum posEnum = termIter.postings(null, null, PostingsEnum.ALL);
PostingsEnum posEnum = termIter.postings(null, PostingsEnum.ALL);
int termFreq = posEnum.freq();
builder.field(FieldStrings.TERM_FREQ, termFreq);
initMemory(curTerms, termFreq);

@ -151,7 +151,7 @@ final class TermVectorsWriter {
}
private PostingsEnum writeTermWithDocsOnly(TermsEnum iterator, PostingsEnum docsEnum) throws IOException {
docsEnum = iterator.postings(null, docsEnum);
docsEnum = iterator.postings(docsEnum);
int nextDoc = docsEnum.nextDoc();
assert nextDoc != DocIdSetIterator.NO_MORE_DOCS;
writeFreq(docsEnum.freq());
@ -162,7 +162,7 @@ final class TermVectorsWriter {
private PostingsEnum writeTermWithDocsAndPos(TermsEnum iterator, PostingsEnum docsAndPosEnum, boolean positions,
boolean offsets, boolean payloads) throws IOException {
docsAndPosEnum = iterator.postings(null, docsAndPosEnum, PostingsEnum.ALL);
docsAndPosEnum = iterator.postings(docsAndPosEnum, PostingsEnum.ALL);
// for each term (iterator next) in this field (field)
// iterate over the docs (should only be one)
int nextDoc = docsAndPosEnum.nextDoc();

@ -30,7 +30,6 @@ import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.text.Text;
import org.joda.time.ReadableInstant;
@ -43,8 +42,6 @@ import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
@ -456,14 +453,6 @@ public abstract class StreamOutput extends OutputStream {
}
}
static {
assert Version.CURRENT.luceneVersion == org.apache.lucene.util.Version.LUCENE_5_2_1: "Remove these regex once we upgrade to Lucene 5.3 and get proper getters for these expections";
}
private final static Pattern CORRUPT_INDEX_EXCEPTION_REGEX = Regex.compile("^(.+) \\(resource=(.+)\\)$", "");
private final static Pattern INDEX_FORMAT_TOO_NEW_EXCEPTION_REGEX = Regex.compile("Format version is not supported \\(resource (.+)\\): (-?\\d+) \\(needs to be between (-?\\d+) and (-?\\d+)\\)", "");
private final static Pattern INDEX_FORMAT_TOO_OLD_EXCEPTION_REGEX_1 = Regex.compile("Format version is not supported \\(resource (.+)\\): (-?\\d+)(?: \\(needs to be between (-?\\d+) and (-?\\d+)\\)). This version of Lucene only supports indexes created with release 4.0 and later\\.", "");
private final static Pattern INDEX_FORMAT_TOO_OLD_EXCEPTION_REGEX_2 = Regex.compile("Format version is not supported \\(resource (.+)\\): (.+). This version of Lucene only supports indexes created with release 4.0 and later\\.", "");
private static int parseIntSafe(String val, int defaultVal) {
try {
return Integer.parseInt(val);
@ -481,73 +470,29 @@ public abstract class StreamOutput extends OutputStream {
boolean writeMessage = true;
if (throwable instanceof CorruptIndexException) {
writeVInt(1);
// Lucene 5.3 will have getters for all these
// we should switch to using getters instead of trying to parse the message:
// writeOptionalString(((CorruptIndexException)throwable).getDescription());
// writeOptionalString(((CorruptIndexException)throwable).getResource());
Matcher matcher = CORRUPT_INDEX_EXCEPTION_REGEX.matcher(throwable.getMessage());
if (matcher.find()) {
writeOptionalString(matcher.group(1)); // message
writeOptionalString(matcher.group(2)); // resource
} else {
// didn't match
writeOptionalString("???"); // message
writeOptionalString("???"); // resource
}
writeOptionalString(((CorruptIndexException)throwable).getOriginalMessage());
writeOptionalString(((CorruptIndexException)throwable).getResourceDescription());
writeMessage = false;
} else if (throwable instanceof IndexFormatTooNewException) {
writeVInt(2);
// Lucene 5.3 will have getters for all these
// we should switch to using getters instead of trying to parse the message:
// writeOptionalString(((CorruptIndexException)throwable).getResource());
// writeInt(((IndexFormatTooNewException)throwable).getVersion());
// writeInt(((IndexFormatTooNewException)throwable).getMinVersion());
// writeInt(((IndexFormatTooNewException)throwable).getMaxVersion());
Matcher matcher = INDEX_FORMAT_TOO_NEW_EXCEPTION_REGEX.matcher(throwable.getMessage());
if (matcher.find()) {
writeOptionalString(matcher.group(1)); // resource
writeInt(parseIntSafe(matcher.group(2), -1)); // version
writeInt(parseIntSafe(matcher.group(3), -1)); // min version
writeInt(parseIntSafe(matcher.group(4), -1)); // max version
} else {
// didn't match
writeOptionalString("???"); // resource
writeInt(-1); // version
writeInt(-1); // min version
writeInt(-1); // max version
}
writeOptionalString(((IndexFormatTooNewException)throwable).getResourceDescription());
writeInt(((IndexFormatTooNewException)throwable).getVersion());
writeInt(((IndexFormatTooNewException)throwable).getMinVersion());
writeInt(((IndexFormatTooNewException)throwable).getMaxVersion());
writeMessage = false;
writeCause = false;
} else if (throwable instanceof IndexFormatTooOldException) {
writeVInt(3);
// Lucene 5.3 will have getters for all these
// we should switch to using getters instead of trying to parse the message:
// writeOptionalString(((CorruptIndexException)throwable).getResource());
// writeInt(((IndexFormatTooNewException)throwable).getVersion());
// writeInt(((IndexFormatTooNewException)throwable).getMinVersion());
// writeInt(((IndexFormatTooNewException)throwable).getMaxVersion());
Matcher matcher = INDEX_FORMAT_TOO_OLD_EXCEPTION_REGEX_1.matcher(throwable.getMessage());
if (matcher.find()) {
// version with numeric version in constructor
writeOptionalString(matcher.group(1)); // resource
writeBoolean(true);
writeInt(parseIntSafe(matcher.group(2), -1)); // version
writeInt(parseIntSafe(matcher.group(3), -1)); // min version
writeInt(parseIntSafe(matcher.group(4), -1)); // max version
} else {
matcher = INDEX_FORMAT_TOO_OLD_EXCEPTION_REGEX_2.matcher(throwable.getMessage());
if (matcher.matches()) {
writeOptionalString(matcher.group(1)); // resource
IndexFormatTooOldException t = (IndexFormatTooOldException) throwable;
writeOptionalString(t.getResourceDescription());
if (t.getVersion() == null) {
writeBoolean(false);
writeOptionalString(matcher.group(2)); // version
writeOptionalString(t.getReason());
} else {
// didn't match
writeOptionalString("???"); // resource
writeBoolean(true);
writeInt(-1); // version
writeInt(-1); // min version
writeInt(-1); // max version
}
writeInt(t.getVersion());
writeInt(t.getMinVersion());
writeInt(t.getMaxVersion());
}
writeMessage = false;
writeCause = false;

@ -62,7 +62,7 @@ public class Lucene {
public static final Version QUERYPARSER_VERSION = VERSION;
public static final String LATEST_DOC_VALUES_FORMAT = "Lucene50";
public static final String LATEST_POSTINGS_FORMAT = "Lucene50";
public static final String LATEST_CODEC = "Lucene50";
public static final String LATEST_CODEC = "Lucene53";
static {
Deprecated annotation = PostingsFormat.forName(LATEST_POSTINGS_FORMAT).getClass().getAnnotation(Deprecated.class);
@ -138,36 +138,6 @@ public class Lucene {
return SegmentInfos.readCommit(directory, segmentsFileName);
}
/**
* Tries to acquire the {@link IndexWriter#WRITE_LOCK_NAME} on the given directory. The returned lock must be closed once
* the lock is released. If the lock can't be obtained a {@link LockObtainFailedException} is thrown.
* This method uses the {@link IndexWriterConfig#getDefaultWriteLockTimeout()} as the lock timeout.
*/
public static Lock acquireWriteLock(Directory directory) throws IOException {
return acquireLock(directory, IndexWriter.WRITE_LOCK_NAME, IndexWriterConfig.getDefaultWriteLockTimeout());
}
/**
* Tries to acquire a lock on the given directory. The returned lock must be closed once
* the lock is released. If the lock can't be obtained a {@link LockObtainFailedException} is thrown.
*/
@SuppressForbidden(reason = "this method uses trappy Directory#makeLock API")
public static Lock acquireLock(Directory directory, String lockName, long timeout) throws IOException {
final Lock writeLock = directory.makeLock(lockName);
boolean success = false;
try {
if (writeLock.obtain(timeout) == false) {
throw new LockObtainFailedException("failed to obtain lock: " + writeLock);
}
success = true;
} finally {
if (success == false) {
writeLock.close();
}
}
return writeLock;
}
/**
* This method removes all files from the given directory that are not referenced by the given segments file.
* This method will open an IndexWriter and relies on index file deleter to remove all unreferenced files. Segment files
@ -179,7 +149,7 @@ public class Lucene {
*/
public static SegmentInfos pruneUnreferencedFiles(String segmentsFileName, Directory directory) throws IOException {
final SegmentInfos si = readSegmentInfos(segmentsFileName, directory);
try (Lock writeLock = acquireWriteLock(directory)) {
try (Lock writeLock = directory.obtainLock(IndexWriter.WRITE_LOCK_NAME)) {
int foundSegmentFiles = 0;
for (final String file : directory.listAll()) {
/**
@ -218,7 +188,7 @@ public class Lucene {
* this operation fails.
*/
public static void cleanLuceneIndex(Directory directory) throws IOException {
try (Lock writeLock = acquireWriteLock(directory)) {
try (Lock writeLock = directory.obtainLock(IndexWriter.WRITE_LOCK_NAME)) {
for (final String file : directory.listAll()) {
if (file.startsWith(IndexFileNames.SEGMENTS) || file.equals(IndexFileNames.OLD_SEGMENTS_GEN)) {
directory.deleteFile(file); // remove all segment_N files

@ -19,27 +19,32 @@
package org.elasticsearch.common.lucene.all;
import org.apache.lucene.analysis.payloads.PayloadHelper;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermContext;
import org.apache.lucene.index.TermState;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.search.CollectionStatistics;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.payloads.AveragePayloadFunction;
import org.apache.lucene.search.payloads.PayloadTermQuery;
import org.apache.lucene.search.TermStatistics;
import org.apache.lucene.search.Weight;
import org.apache.lucene.search.similarities.Similarity;
import org.apache.lucene.search.similarities.Similarity.SimScorer;
import org.apache.lucene.search.spans.SpanWeight;
import org.apache.lucene.search.spans.TermSpans;
import org.apache.lucene.util.Bits;
import org.apache.lucene.search.similarities.Similarity.SimWeight;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.ToStringUtils;
import java.io.IOException;
import static org.apache.lucene.analysis.payloads.PayloadHelper.decodeFloat;
import java.util.Set;
/**
* A term query that takes all payload boost values into account.
@ -49,78 +54,12 @@ import static org.apache.lucene.analysis.payloads.PayloadHelper.decodeFloat;
* determine how the payload should be factored in, it just parses
* the float and multiplies the average with the regular score.
*/
public final class AllTermQuery extends PayloadTermQuery {
public final class AllTermQuery extends Query {
private final Term term;
public AllTermQuery(Term term) {
super(term, new AveragePayloadFunction());
}
@Override
public SpanWeight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
// TODO: needsScores
// we should be able to just return a regular SpanTermWeight, at most here if needsScores == false?
return new AllTermWeight(this, searcher, needsScores);
}
class AllTermWeight extends PayloadTermWeight {
AllTermWeight(AllTermQuery query, IndexSearcher searcher, boolean needsScores) throws IOException {
super(query, searcher, needsScores);
}
@Override
public AllTermSpanScorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
if (this.stats == null) {
return null;
}
// we have a custom weight class, we must check in case something is wrong with _all
Terms terms = context.reader().terms(query.getField());
if (terms != null && terms.hasPositions() == false) {
throw new IllegalStateException("field \"" + term.field() + "\" was indexed without position data; cannot run AllTermQuery (term=" + term.text() + ")");
}
TermSpans spans = (TermSpans) query.getSpans(context, acceptDocs, termContexts);
if (spans == null) {
return null;
}
SimScorer sloppySimScorer = similarity.simScorer(stats, context);
return new AllTermSpanScorer(spans, this, sloppySimScorer);
}
class AllTermSpanScorer extends PayloadTermSpanScorer {
final PostingsEnum postings;
AllTermSpanScorer(TermSpans spans, SpanWeight weight, Similarity.SimScorer docScorer) throws IOException {
super(spans, weight, docScorer);
postings = spans.getPostings();
}
@Override
protected void processPayload(Similarity similarity) throws IOException {
// note: similarity is ignored here (we just use decodeFloat always).
// this is the only difference between this class and PayloadTermQuery.
if (spans.isPayloadAvailable()) {
BytesRef payload = postings.getPayload();
payloadScore += decodeFloat(payload.bytes, payload.offset);
payloadsSeen++;
}
}
}
}
@Override
public int hashCode() {
return super.hashCode() + 1;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
return true;
this.term = term;
}
@Override
@ -150,4 +89,144 @@ public final class AllTermQuery extends PayloadTermQuery {
return this;
}
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
if (needsScores == false) {
return new TermQuery(term).createWeight(searcher, needsScores);
}
final TermContext termStates = TermContext.build(searcher.getTopReaderContext(), term);
final CollectionStatistics collectionStats = searcher.collectionStatistics(term.field());
final TermStatistics termStats = searcher.termStatistics(term, termStates);
final Similarity similarity = searcher.getSimilarity(needsScores);
final SimWeight stats = similarity.computeWeight(getBoost(), collectionStats, termStats);
return new Weight(this) {
@Override
public final float getValueForNormalization() throws IOException {
return stats.getValueForNormalization();
}
@Override
public final void normalize(float norm, float topLevelBoost) {
stats.normalize(norm, topLevelBoost);
}
@Override
public void extractTerms(Set<Term> terms) {
terms.add(term);
}
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
AllTermScorer scorer = scorer(context);
if (scorer != null) {
int newDoc = scorer.advance(doc);
if (newDoc == doc) {
float score = scorer.score();
float freq = scorer.freq();
SimScorer docScorer = similarity.simScorer(stats, context);
Explanation freqExplanation = Explanation.match(freq, "termFreq=" + freq);
Explanation termScoreExplanation = docScorer.explain(doc, freqExplanation);
Explanation payloadBoostExplanation = Explanation.match(scorer.payloadBoost(), "payloadBoost=" + scorer.payloadBoost());
return Explanation.match(
score,
"weight(" + getQuery() + " in " + doc + ") ["
+ similarity.getClass().getSimpleName() + "], product of:",
termScoreExplanation, payloadBoostExplanation);
}
}
return Explanation.noMatch("no matching term");
}
@Override
public AllTermScorer scorer(LeafReaderContext context) throws IOException {
final Terms terms = context.reader().terms(term.field());
if (terms == null) {
return null;
}
final TermsEnum termsEnum = terms.iterator();
if (termsEnum == null) {
return null;
}
final TermState state = termStates.get(context.ord);
termsEnum.seekExact(term.bytes(), state);
PostingsEnum docs = termsEnum.postings(null, PostingsEnum.PAYLOADS);
assert docs != null;
return new AllTermScorer(this, docs, similarity.simScorer(stats, context));
}
};
}
private static class AllTermScorer extends Scorer {
final PostingsEnum postings;
final Similarity.SimScorer docScorer;
int doc = -1;
float payloadBoost;
AllTermScorer(Weight weight, PostingsEnum postings, Similarity.SimScorer docScorer) {
super(weight);
this.postings = postings;
this.docScorer = docScorer;
}
float payloadBoost() throws IOException {
if (doc != docID()) {
final int freq = postings.freq();
payloadBoost = 0;
for (int i = 0; i < freq; ++i) {
postings.nextPosition();
final BytesRef payload = postings.getPayload();
float boost;
if (payload == null) {
boost = 1;
} else {
assert payload.length == 4;
boost = PayloadHelper.decodeFloat(payload.bytes, payload.offset);
}
payloadBoost += boost;
}
payloadBoost /= freq;
doc = docID();
}
return payloadBoost;
}
@Override
public float score() throws IOException {
return payloadBoost() * docScorer.score(postings.docID(), postings.freq());
}
@Override
public int freq() throws IOException {
return postings.freq();
}
@Override
public int docID() {
return postings.docID();
}
@Override
public int nextDoc() throws IOException {
return postings.nextDoc();
}
@Override
public int advance(int target) throws IOException {
return postings.advance(target);
}
@Override
public long cost() {
return postings.cost();
}
}
@Override
public String toString(String field) {
return new TermQuery(term).toString(field) + ToStringUtils.boost(getBoost());
}
}

@ -25,11 +25,12 @@ import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.FilteredDocIdSetIterator;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Weight;
import org.apache.lucene.util.BitDocIdSet;
import org.apache.lucene.util.BitSet;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.Nullable;
@ -96,25 +97,32 @@ public class FilterableTermsEnum extends TermsEnum {
if (termsEnum == null) {
continue;
}
Bits bits = null;
BitSet bits = null;
if (weight != null) {
// we want to force apply deleted docs
Scorer docs = weight.scorer(context, context.reader().getLiveDocs());
DocIdSetIterator docs = weight.scorer(context);
if (docs == null) {
// fully filtered, none matching, no need to iterate on this
continue;
}
// we want to force apply deleted docs
final Bits liveDocs = context.reader().getLiveDocs();
if (liveDocs != null) {
docs = new FilteredDocIdSetIterator(docs) {
@Override
protected boolean match(int doc) {
return liveDocs.get(doc);
}
};
}
BitDocIdSet.Builder builder = new BitDocIdSet.Builder(context.reader().maxDoc());
builder.or(docs);
bits = builder.build().bits();
// Count how many docs are in our filtered set
// TODO make this lazy-loaded only for those that need it?
docs = weight.scorer(context, context.reader().getLiveDocs());
while (docs.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
numDocs++;
}
numDocs += bits.cardinality();
}
enums.add(new Holder(termsEnum, bits));
}
@ -147,10 +155,13 @@ public class FilterableTermsEnum extends TermsEnum {
totalTermFreq += leafTotalTermFreq;
}
} else {
final PostingsEnum docsEnum = anEnum.docsEnum = anEnum.termsEnum.postings(anEnum.bits, anEnum.docsEnum, docsEnumFlag);
final PostingsEnum docsEnum = anEnum.docsEnum = anEnum.termsEnum.postings(anEnum.docsEnum, docsEnumFlag);
// 2 choices for performing same heavy loop - one attempts to calculate totalTermFreq and other does not
if (docsEnumFlag == PostingsEnum.FREQS) {
for (int docId = docsEnum.nextDoc(); docId != DocIdSetIterator.NO_MORE_DOCS; docId = docsEnum.nextDoc()) {
if (anEnum.bits != null && anEnum.bits.get(docId) == false) {
continue;
}
docFreq++;
// docsEnum.freq() returns 1 if doc indexed with IndexOptions.DOCS_ONLY so no way of knowing if value
// is really 1 or unrecorded when filtering like this
@ -158,6 +169,9 @@ public class FilterableTermsEnum extends TermsEnum {
}
} else {
for (int docId = docsEnum.nextDoc(); docId != DocIdSetIterator.NO_MORE_DOCS; docId = docsEnum.nextDoc()) {
if (anEnum.bits != null && anEnum.bits.get(docId) == false) {
continue;
}
// docsEnum.freq() behaviour is undefined if docsEnumFlag==PostingsEnum.FLAG_NONE so don't bother with call
docFreq++;
}
@ -204,7 +218,7 @@ public class FilterableTermsEnum extends TermsEnum {
}
@Override
public PostingsEnum postings(Bits liveDocs, PostingsEnum reuse, int flags) throws IOException {
public PostingsEnum postings(PostingsEnum reuse, int flags) throws IOException {
throw new UnsupportedOperationException(UNSUPPORTED_MESSAGE);
}

@ -44,7 +44,7 @@ public class FilteredCollector implements Collector {
@Override
public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
final Scorer filterScorer = filter.scorer(context, null);
final Scorer filterScorer = filter.scorer(context);
final LeafCollector in = collector.getLeafCollector(context);
final Bits bits = Lucene.asSequentialAccessBits(context.reader().maxDoc(), filterScorer);

@ -166,7 +166,7 @@ public class MoreLikeThisQuery extends Query {
BooleanQuery bq = new BooleanQuery();
if (this.likeFields != null) {
Query mltQuery = mlt.like(this.likeFields);
Queries.applyMinimumShouldMatch((BooleanQuery) mltQuery, minimumShouldMatch);
mltQuery = Queries.applyMinimumShouldMatch((BooleanQuery) mltQuery, minimumShouldMatch);
bq.add(mltQuery, BooleanClause.Occur.SHOULD);
}
if (this.likeText != null) {
@ -176,7 +176,7 @@ public class MoreLikeThisQuery extends Query {
}
//LUCENE 4 UPGRADE this mapps the 3.6 behavior (only use the first field)
Query mltQuery = mlt.like(moreLikeFields[0], readers);
Queries.applyMinimumShouldMatch((BooleanQuery) mltQuery, minimumShouldMatch);
mltQuery = Queries.applyMinimumShouldMatch((BooleanQuery) mltQuery, minimumShouldMatch);
bq.add(mltQuery, BooleanClause.Occur.SHOULD);
}

@ -107,9 +107,9 @@ public class Queries {
return false;
}
public static void applyMinimumShouldMatch(BooleanQuery query, @Nullable String minimumShouldMatch) {
public static BooleanQuery applyMinimumShouldMatch(BooleanQuery query, @Nullable String minimumShouldMatch) {
if (minimumShouldMatch == null) {
return;
return query;
}
int optionalClauses = 0;
for (BooleanClause c : query.clauses()) {
@ -120,8 +120,17 @@ public class Queries {
int msm = calculateMinShouldMatch(optionalClauses, minimumShouldMatch);
if (0 < msm) {
query.setMinimumNumberShouldMatch(msm);
BooleanQuery.Builder builder = new BooleanQuery.Builder();
builder.setDisableCoord(query.isCoordDisabled());
for (BooleanClause clause : query) {
builder.add(clause);
}
builder.setMinimumNumberShouldMatch(msm);
BooleanQuery bq = builder.build();
bq.setBoost(query.getBoost());
query = bq;
}
return query;
}
private static Pattern spaceAroundLessThanPattern = Pattern.compile("(\\s+<\\s*)|(\\s*<\\s+)");

@ -852,7 +852,7 @@ public final class XMoreLikeThis {
continue;
}
final PostingsEnum docs = termsEnum.postings(null, null);
final PostingsEnum docs = termsEnum.postings(null);
int freq = 0;
while(docs != null && docs.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
freq += docs.freq();

@ -169,11 +169,11 @@ public class FiltersFunctionScoreQuery extends Query {
}
@Override
public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
public Scorer scorer(LeafReaderContext context) throws IOException {
// we ignore scoreDocsInOrder parameter, because we need to score in
// order if documents are scored with a script. The
// ShardLookup depends on in order scoring.
Scorer subQueryScorer = subQueryWeight.scorer(context, acceptDocs);
Scorer subQueryScorer = subQueryWeight.scorer(context);
if (subQueryScorer == null) {
return null;
}
@ -182,7 +182,7 @@ public class FiltersFunctionScoreQuery extends Query {
for (int i = 0; i < filterFunctions.length; i++) {
FilterFunction filterFunction = filterFunctions[i];
functions[i] = filterFunction.function.getLeafScoreFunction(context);
Scorer filterScorer = filterWeights[i].scorer(context, null); // no need to apply accepted docs
Scorer filterScorer = filterWeights[i].scorer(context);
docSets[i] = Lucene.asSequentialAccessBits(context.reader().maxDoc(), filterScorer);
}
return new FiltersFunctionFactorScorer(this, subQueryScorer, scoreMode, filterFunctions, maxBoost, functions, docSets, combineFunction, minScore, needsScores);
@ -208,7 +208,7 @@ public class FiltersFunctionScoreQuery extends Query {
}
Bits docSet = Lucene.asSequentialAccessBits(context.reader().maxDoc(),
filterWeights[i].scorer(context, null));
filterWeights[i].scorer(context));
if (docSet.get(doc)) {
Explanation functionExplanation = filterFunction.function.getLeafScoreFunction(context).explainScore(doc, subQueryExpl);
double factor = functionExplanation.getValue();

@ -128,8 +128,8 @@ public class FunctionScoreQuery extends Query {
}
@Override
public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
Scorer subQueryScorer = subQueryWeight.scorer(context, acceptDocs);
public Scorer scorer(LeafReaderContext context) throws IOException {
Scorer subQueryScorer = subQueryWeight.scorer(context);
if (subQueryScorer == null) {
return null;
}

@ -105,9 +105,13 @@ final class PerThreadIDAndVersionLookup {
// Use NDV to retrieve the version, in which case we only need PostingsEnum:
// there may be more than one matching docID, in the case of nested docs, so we want the last one:
PostingsEnum docs = docsEnums[seg] = termsEnums[seg].postings(liveDocs[seg], docsEnums[seg], 0);
PostingsEnum docs = docsEnums[seg] = termsEnums[seg].postings(docsEnums[seg], 0);
final Bits liveDocs = this.liveDocs[seg];
int docID = DocIdSetIterator.NO_MORE_DOCS;
for (int d = docs.nextDoc(); d != DocIdSetIterator.NO_MORE_DOCS; d = docs.nextDoc()) {
if (liveDocs != null && liveDocs.get(d) == false) {
continue;
}
docID = d;
}
@ -125,9 +129,13 @@ final class PerThreadIDAndVersionLookup {
}
// ... but used to be stored as payloads; in this case we must use PostingsEnum
PostingsEnum dpe = posEnums[seg] = termsEnums[seg].postings(liveDocs[seg], posEnums[seg], PostingsEnum.PAYLOADS);
PostingsEnum dpe = posEnums[seg] = termsEnums[seg].postings(posEnums[seg], PostingsEnum.PAYLOADS);
assert dpe != null; // terms has payloads
final Bits liveDocs = this.liveDocs[seg];
for (int d = dpe.nextDoc(); d != DocIdSetIterator.NO_MORE_DOCS; d = dpe.nextDoc()) {
if (liveDocs != null && liveDocs.get(d) == false) {
continue;
}
dpe.nextPosition();
final BytesRef payload = dpe.getPayload();
if (payload != null && payload.length == 8) {

@ -33,7 +33,6 @@ import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.env.ShardLock;
@ -86,7 +85,7 @@ public class MultiDataPathUpgrader {
ShardStateMetaData.FORMAT.write(loaded, loaded.version, targetPath.getShardStatePath());
Files.createDirectories(targetPath.resolveIndex());
try (SimpleFSDirectory directory = new SimpleFSDirectory(targetPath.resolveIndex())) {
try (final Lock lock = Lucene.acquireWriteLock(directory)) {
try (final Lock lock = directory.obtainLock(IndexWriter.WRITE_LOCK_NAME)) {
upgradeFiles(shard, targetPath, targetPath.resolveIndex(), ShardPath.INDEX_FOLDER_NAME, paths);
} catch (LockObtainFailedException ex) {
throw new IllegalStateException("Can't obtain lock on " + targetPath.resolveIndex(), ex);

@ -30,13 +30,11 @@ import org.apache.lucene.util.IOUtils;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.Index;
@ -154,7 +152,7 @@ public class NodeEnvironment extends AbstractComponent implements Closeable {
try (Directory luceneDir = FSDirectory.open(dir, NativeFSLockFactory.INSTANCE)) {
logger.trace("obtaining node lock on {} ...", dir.toAbsolutePath());
try {
locks[dirIndex] = Lucene.acquireLock(luceneDir, NODE_LOCK_FILENAME, 0);
locks[dirIndex] = luceneDir.obtainLock(NODE_LOCK_FILENAME);
nodePaths[dirIndex] = new NodePath(dir, environment);
localNodeId = possibleLockId;
} catch (LockObtainFailedException ex) {
@ -324,7 +322,7 @@ public class NodeEnvironment extends AbstractComponent implements Closeable {
dirs[i] = new SimpleFSDirectory(p, FsDirectoryService.buildLockFactory(indexSettings));
// create a lock for the "write.lock" file
try {
locks[i] = Lucene.acquireWriteLock(dirs[i]);
locks[i] = dirs[i].obtainLock(IndexWriter.WRITE_LOCK_NAME);
} catch (IOException ex) {
throw new LockObtainFailedException("unable to acquire " +
IndexWriter.WRITE_LOCK_NAME + " for " + p);
@ -730,7 +728,7 @@ public class NodeEnvironment extends AbstractComponent implements Closeable {
if (!closed.get() && locks != null) {
for (Lock lock : locks) {
try {
assert lock.isLocked() : "Lock: " + lock + "is not locked";
lock.ensureValid();
} catch (IOException e) {
logger.warn("lock assertion failed", e);
return false;

@ -22,8 +22,8 @@ package org.elasticsearch.index.codec;
import com.google.common.collect.ImmutableMap;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.lucene50.Lucene50Codec;
import org.apache.lucene.codecs.lucene50.Lucene50StoredFieldsFormat.Mode;
import org.apache.lucene.codecs.lucene53.Lucene53Codec;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
@ -65,8 +65,8 @@ public class CodecService extends AbstractIndexComponent {
this.mapperService = mapperService;
MapBuilder<String, Codec> codecs = MapBuilder.<String, Codec>newMapBuilder();
if (mapperService == null) {
codecs.put(DEFAULT_CODEC, new Lucene50Codec());
codecs.put(BEST_COMPRESSION_CODEC, new Lucene50Codec(Mode.BEST_COMPRESSION));
codecs.put(DEFAULT_CODEC, new Lucene53Codec());
codecs.put(BEST_COMPRESSION_CODEC, new Lucene53Codec(Mode.BEST_COMPRESSION));
} else {
codecs.put(DEFAULT_CODEC,
new PerFieldMappingPostingFormatCodec(Mode.BEST_SPEED, mapperService, logger));

@ -21,11 +21,10 @@ package org.elasticsearch.index.codec;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.codecs.lucene50.Lucene50Codec;
import org.apache.lucene.codecs.lucene50.Lucene50StoredFieldsFormat;
import org.apache.lucene.codecs.lucene53.Lucene53Codec;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.core.CompletionFieldMapper;
@ -39,7 +38,7 @@ import org.elasticsearch.index.mapper.core.CompletionFieldMapper;
* configured for a specific field the default postings format is used.
*/
// LUCENE UPGRADE: make sure to move to a new codec depending on the lucene version
public class PerFieldMappingPostingFormatCodec extends Lucene50Codec {
public class PerFieldMappingPostingFormatCodec extends Lucene53Codec {
private final ESLogger logger;
private final MapperService mapperService;

@ -323,8 +323,8 @@ public class BloomFilterPostingsFormat extends PostingsFormat {
@Override
public PostingsEnum postings(Bits liveDocs, PostingsEnum reuse, int flags) throws IOException {
return getDelegate().postings(liveDocs, reuse, flags);
public PostingsEnum postings(PostingsEnum reuse, int flags) throws IOException {
return getDelegate().postings(reuse, flags);
}
}
@ -384,7 +384,7 @@ public class BloomFilterPostingsFormat extends PostingsFormat {
bloomFilters.put(fieldInfo, bloomFilter);
}
// Make sure there's at least one doc for this term:
postings = termsEnum.postings(null, postings, 0);
postings = termsEnum.postings(postings, 0);
if (postings.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
bloomFilter.put(term);
}

@ -20,7 +20,6 @@ package org.elasticsearch.index.engine;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.MergePolicy;
import org.apache.lucene.search.QueryCache;
import org.apache.lucene.search.QueryCachingPolicy;
@ -30,7 +29,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.index.codec.CodecService;
import org.elasticsearch.index.deletionpolicy.SnapshotDeletionPolicy;
import org.elasticsearch.index.indexing.ShardIndexingService;
@ -56,7 +54,6 @@ public final class EngineConfig {
private volatile ByteSizeValue indexingBufferSize;
private volatile ByteSizeValue versionMapSize;
private volatile String versionMapSizeSetting;
private final int indexConcurrency;
private volatile boolean compoundOnFlush = true;
private long gcDeletesInMillis = DEFAULT_GC_DELETES.millis();
private volatile boolean enableGcDeletes = true;
@ -79,13 +76,6 @@ public final class EngineConfig {
private final QueryCachingPolicy queryCachingPolicy;
private final IndexSearcherWrappingService wrappingService;
/**
* Index setting for index concurrency / number of threadstates in the indexwriter.
* The default is depending on the number of CPUs in the system. We use a 0.65 the number of CPUs or at least {@value org.apache.lucene.index.IndexWriterConfig#DEFAULT_MAX_THREAD_STATES}
* This setting is <b>not</b> realtime updateable
*/
public static final String INDEX_CONCURRENCY_SETTING = "index.index_concurrency";
/**
* Index setting for compound file on flush. This setting is realtime updateable.
*/
@ -161,7 +151,6 @@ public final class EngineConfig {
this.wrappingService = wrappingService;
this.optimizeAutoGenerateId = indexSettings.getAsBoolean(EngineConfig.INDEX_OPTIMIZE_AUTOGENERATED_ID_SETTING, false);
this.compoundOnFlush = indexSettings.getAsBoolean(EngineConfig.INDEX_COMPOUND_ON_FLUSH, compoundOnFlush);
this.indexConcurrency = indexSettings.getAsInt(EngineConfig.INDEX_CONCURRENCY_SETTING, Math.max(IndexWriterConfig.DEFAULT_MAX_THREAD_STATES, (int) (EsExecutors.boundedNumberOfProcessors(indexSettings) * 0.65)));
codecName = indexSettings.get(EngineConfig.INDEX_CODEC_SETTING, EngineConfig.DEFAULT_CODEC_NAME);
indexingBufferSize = indexSettings.getAsBytesSize(INDEX_BUFFER_SIZE_SETTING, DEFAULT_INDEX_BUFFER_SIZE);
gcDeletesInMillis = indexSettings.getAsTime(INDEX_GC_DELETES_SETTING, EngineConfig.DEFAULT_GC_DELETES).millis();
@ -235,16 +224,6 @@ public final class EngineConfig {
return indexingBufferSize;
}
/**
* Returns the index concurrency that directly translates into the number of thread states used in the engines
* {@code IndexWriter}.
*
* @see org.apache.lucene.index.IndexWriterConfig#getMaxThreadStates()
*/
public int getIndexConcurrency() {
return indexConcurrency;
}
/**
* Returns <code>true</code> iff flushed segments should be written as compound file system. Defaults to <code>true</code>
*/

@ -136,7 +136,7 @@ public class InternalEngine extends Engine {
this.indexingService = engineConfig.getIndexingService();
this.warmer = engineConfig.getWarmer();
mergeScheduler = scheduler = new EngineMergeScheduler(engineConfig.getShardId(), engineConfig.getIndexSettings(), engineConfig.getMergeSchedulerConfig());
this.dirtyLocks = new Object[engineConfig.getIndexConcurrency() * 50]; // we multiply it to have enough...
this.dirtyLocks = new Object[Runtime.getRuntime().availableProcessors() * 10]; // we multiply it to have enough...
for (int i = 0; i < dirtyLocks.length; i++) {
dirtyLocks[i] = new Object();
}
@ -1038,7 +1038,6 @@ public class InternalEngine extends Engine {
iwc.setMergePolicy(mergePolicy);
iwc.setSimilarity(engineConfig.getSimilarity());
iwc.setRAMBufferSizeMB(engineConfig.getIndexingBufferSize().mbFrac());
iwc.setMaxThreadStates(engineConfig.getIndexConcurrency());
iwc.setCodec(engineConfig.getCodec());
/* We set this timeout to a highish value to work around
* the default poll interval in the Lucene lock that is

@ -470,7 +470,7 @@ public final class OrdinalsBuilder implements Closeable {
public BytesRef next() throws IOException {
BytesRef ref;
if ((ref = termsEnum.next()) != null) {
docsEnum = termsEnum.postings(null, docsEnum, PostingsEnum.NONE);
docsEnum = termsEnum.postings(docsEnum, PostingsEnum.NONE);
nextOrdinal();
int docId;
while ((docId = docsEnum.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {

@ -97,7 +97,7 @@ public class PagedBytesIndexFieldData extends AbstractIndexOrdinalsFieldData {
final long termOrd = builder.nextOrdinal();
assert termOrd == termOrdToBytesOffset.size();
termOrdToBytesOffset.add(bytes.copyUsingLengthPrefix(term));
docsEnum = termsEnum.postings(null, docsEnum, PostingsEnum.NONE);
docsEnum = termsEnum.postings(docsEnum, PostingsEnum.NONE);
for (int docId = docsEnum.nextDoc(); docId != DocIdSetIterator.NO_MORE_DOCS; docId = docsEnum.nextDoc()) {
builder.addDoc(docId);
}

@ -194,7 +194,7 @@ public class ParentChildIndexFieldData extends AbstractIndexFieldData<AtomicPare
final long termOrd = typeBuilder.builder.nextOrdinal();
assert termOrd == typeBuilder.termOrdToBytesOffset.size();
typeBuilder.termOrdToBytesOffset.add(typeBuilder.bytes.copyUsingLengthPrefix(id));
docsEnum = estimatedTermsEnum.postings(null, docsEnum, PostingsEnum.NONE);
docsEnum = estimatedTermsEnum.postings(docsEnum, PostingsEnum.NONE);
for (int docId = docsEnum.nextDoc(); docId != DocIdSetIterator.NO_MORE_DOCS; docId = docsEnum.nextDoc()) {
typeBuilder.builder.addDoc(docId);
}

@ -23,12 +23,10 @@ import com.carrotsearch.hppc.IntArrayList;
import org.apache.lucene.index.*;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
@ -65,16 +63,16 @@ final class ParentChildIntersectTermsEnum extends TermsEnum {
}
@Override
public PostingsEnum postings(Bits liveDocs, PostingsEnum reuse, int flags) throws IOException {
public PostingsEnum postings(PostingsEnum reuse, int flags) throws IOException {
int size = stateSlots.size();
assert size > 0;
if (size == 1) {
// Can't use 'reuse' since we don't know to which previous TermsEnum it belonged to.
return states.get(stateSlots.get(0)).termsEnum.postings(liveDocs, null, flags);
return states.get(stateSlots.get(0)).termsEnum.postings(null, flags);
} else {
List<PostingsEnum> docsEnums = new ArrayList<>(stateSlots.size());
for (int i = 0; i < stateSlots.size(); i++) {
docsEnums.add(states.get(stateSlots.get(i)).termsEnum.postings(liveDocs, null, flags));
docsEnums.add(states.get(stateSlots.get(i)).termsEnum.postings(null, flags));
}
return new CompoundDocsEnum(docsEnums);
}

@ -166,7 +166,7 @@ public class BoolQueryParser implements QueryParser {
booleanQuery.add(clause);
}
booleanQuery.setBoost(boost);
Queries.applyMinimumShouldMatch(booleanQuery, minimumShouldMatch);
booleanQuery = Queries.applyMinimumShouldMatch(booleanQuery, minimumShouldMatch);
Query query = adjustPureNegative ? fixNegativeQueryIfNeeded(booleanQuery) : booleanQuery;
if (queryName != null) {
parseContext.addNamedQuery(queryName, query);

@ -168,7 +168,7 @@ public class MatchQueryParser implements QueryParser {
}
if (query instanceof BooleanQuery) {
Queries.applyMinimumShouldMatch((BooleanQuery) query, minimumShouldMatch);
query = Queries.applyMinimumShouldMatch((BooleanQuery) query, minimumShouldMatch);
} else if (query instanceof ExtendedCommonTermsQuery) {
((ExtendedCommonTermsQuery)query).setLowFreqMinimumNumberShouldMatch(minimumShouldMatch);
}

@ -233,7 +233,7 @@ public class QueryStringQueryParser implements QueryParser {
}
query = fixNegativeQueryIfNeeded(query);
if (query instanceof BooleanQuery) {
Queries.applyMinimumShouldMatch((BooleanQuery) query, qpSettings.minimumShouldMatch());
query = Queries.applyMinimumShouldMatch((BooleanQuery) query, qpSettings.minimumShouldMatch());
}
if (queryName != null) {
parseContext.addNamedQuery(queryName, query);

@ -171,29 +171,26 @@ public class SimpleQueryParser extends org.apache.lucene.queryparser.simple.Simp
// rewind buffer
buffer.reset();
BytesRef bytes = termAtt == null ? null : termAtt.getBytesRef();
if (numTokens == 0) {
return null;
} else if (numTokens == 1) {
try {
boolean hasNext = buffer.incrementToken();
assert hasNext == true;
termAtt.fillBytesRef();
} catch (IOException e) {
// safe to ignore, because we know the number of tokens
}
return new PrefixQuery(new Term(field, BytesRef.deepCopyOf(bytes)));
return new PrefixQuery(new Term(field, BytesRef.deepCopyOf(termAtt.getBytesRef())));
} else {
BooleanQuery bq = new BooleanQuery();
for (int i = 0; i < numTokens; i++) {
try {
boolean hasNext = buffer.incrementToken();
assert hasNext == true;
termAtt.fillBytesRef();
} catch (IOException e) {
// safe to ignore, because we know the number of tokens
}
bq.add(new BooleanClause(new PrefixQuery(new Term(field, BytesRef.deepCopyOf(bytes))), BooleanClause.Occur.SHOULD));
bq.add(new BooleanClause(new PrefixQuery(new Term(field, BytesRef.deepCopyOf(termAtt.getBytesRef()))), BooleanClause.Occur.SHOULD));
}
return bq;
}

@ -215,7 +215,7 @@ public class SimpleQueryStringParser implements QueryParser {
}
if (minimumShouldMatch != null && query instanceof BooleanQuery) {
Queries.applyMinimumShouldMatch((BooleanQuery) query, minimumShouldMatch);
query = Queries.applyMinimumShouldMatch((BooleanQuery) query, minimumShouldMatch);
}
if (query != null) {

@ -201,8 +201,7 @@ public class TermsQueryParser implements QueryParser {
bq.add(new TermQuery(new Term(fieldName, BytesRefs.toBytesRef(term))), Occur.SHOULD);
}
}
Queries.applyMinimumShouldMatch(bq, minShouldMatch);
query = bq;
query = Queries.applyMinimumShouldMatch(bq, minShouldMatch);
}
query.setBoost(boost);

@ -29,7 +29,6 @@ import org.apache.lucene.search.Query;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
import org.elasticsearch.index.query.QueryParseContext;
@ -55,7 +54,7 @@ public class MultiMatchQuery extends MatchQuery {
private Query parseAndApply(Type type, String fieldName, Object value, String minimumShouldMatch, Float boostValue) throws IOException {
Query query = parse(type, fieldName, value);
if (query instanceof BooleanQuery) {
Queries.applyMinimumShouldMatch((BooleanQuery) query, minimumShouldMatch);
query = Queries.applyMinimumShouldMatch((BooleanQuery) query, minimumShouldMatch);
}
if (boostValue != null && query != null) {
query.setBoost(boostValue);

@ -198,13 +198,13 @@ public class ChildrenConstantScoreQuery extends IndexCacheableQuery {
}
@Override
public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
public Scorer scorer(LeafReaderContext context) throws IOException {
if (remaining == 0) {
return null;
}
if (shortCircuitFilter != null) {
DocIdSet docIdSet = shortCircuitFilter.getDocIdSet(context, acceptDocs);
DocIdSet docIdSet = shortCircuitFilter.getDocIdSet(context, null);
if (!Lucene.isEmpty(docIdSet)) {
DocIdSetIterator iterator = docIdSet.iterator();
if (iterator != null) {
@ -214,7 +214,7 @@ public class ChildrenConstantScoreQuery extends IndexCacheableQuery {
return null;
}
DocIdSet parentDocIdSet = this.parentFilter.getDocIdSet(context, acceptDocs);
DocIdSet parentDocIdSet = this.parentFilter.getDocIdSet(context, null);
if (!Lucene.isEmpty(parentDocIdSet)) {
// We can't be sure of the fact that liveDocs have been applied, so we apply it here. The "remaining"
// count down (short circuit) logic will then work as expected.

@ -262,8 +262,8 @@ public final class ChildrenQuery extends IndexCacheableQuery {
}
@Override
public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
DocIdSet parentsSet = parentFilter.getDocIdSet(context, acceptDocs);
public Scorer scorer(LeafReaderContext context) throws IOException {
DocIdSet parentsSet = parentFilter.getDocIdSet(context, null);
if (Lucene.isEmpty(parentsSet) || remaining == 0) {
return null;
}

@ -22,7 +22,17 @@ import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.SortedDocValues;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.*;
import org.apache.lucene.search.BitsFilteredDocIdSet;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.FilteredDocIdSetIterator;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Weight;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.LongBitSet;
import org.elasticsearch.common.lucene.IndexCacheableQuery;
@ -162,14 +172,16 @@ public class ParentConstantScoreQuery extends IndexCacheableQuery {
}
@Override
public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
DocIdSet childrenDocIdSet = childrenFilter.getDocIdSet(context, acceptDocs);
public Scorer scorer(LeafReaderContext context) throws IOException {
DocIdSet childrenDocIdSet = childrenFilter.getDocIdSet(context, null);
if (Lucene.isEmpty(childrenDocIdSet)) {
return null;
}
SortedDocValues globalValues = globalIfd.load(context).getOrdinalsValues(parentType);
if (globalValues != null) {
// we forcefully apply live docs here so that deleted children don't give matching parents
childrenDocIdSet = BitsFilteredDocIdSet.wrap(childrenDocIdSet, context.reader().getLiveDocs());
DocIdSetIterator innerIterator = childrenDocIdSet.iterator();
if (innerIterator != null) {
ChildrenDocIdIterator childrenDocIdIterator = new ChildrenDocIdIterator(

@ -158,11 +158,17 @@ final class ParentIdsFilter extends Filter {
parentIds.get(i, idSpare);
BytesRef uid = Uid.createUidAsBytes(parentTypeBr, idSpare, uidSpare);
if (termsEnum.seekExact(uid)) {
docsEnum = termsEnum.postings(docsEnum, PostingsEnum.NONE);
int docId;
docsEnum = termsEnum.postings(acceptDocs, docsEnum, PostingsEnum.NONE);
for (docId = docsEnum.nextDoc(); docId != DocIdSetIterator.NO_MORE_DOCS; docId = docsEnum.nextDoc()) {
if (acceptDocs == null || acceptDocs.get(docId)) {
break;
}
}
if (docId == DocIdSetIterator.NO_MORE_DOCS) {
continue;
}
if (result == null) {
docId = docsEnum.nextDoc();
if (docId != DocIdSetIterator.NO_MORE_DOCS) {
// very rough heuristic that tries to get an idea of the number of documents
// in the set based on the number of parent ids that we didn't find in this segment
final int expectedCardinality = size / (i + 1);
@ -172,14 +178,6 @@ final class ParentIdsFilter extends Filter {
} else {
result = new SparseFixedBitSet(context.reader().maxDoc());
}
} else {
continue;
}
} else {
docId = docsEnum.nextDoc();
if (docId == DocIdSetIterator.NO_MORE_DOCS) {
continue;
}
}
if (nonNestedDocs != null) {
docId = nonNestedDocs.nextSetBit(docId);

@ -23,6 +23,7 @@ import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.SortedDocValues;
import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BitsFilteredDocIdSet;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.DocIdSet;
@ -243,8 +244,10 @@ public class ParentQuery extends IndexCacheableQuery {
}
@Override
public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
DocIdSet childrenDocSet = childrenFilter.getDocIdSet(context, acceptDocs);
public Scorer scorer(LeafReaderContext context) throws IOException {
DocIdSet childrenDocSet = childrenFilter.getDocIdSet(context, null);
// we forcefully apply live docs here so that deleted children don't give matching parents
childrenDocSet = BitsFilteredDocIdSet.wrap(childrenDocSet, context.reader().getLiveDocs());
if (Lucene.isEmpty(childrenDocSet)) {
return null;
}

@ -141,10 +141,10 @@ public class GeoDistanceRangeQuery extends Query {
}
return new ConstantScoreWeight(this) {
@Override
public Scorer scorer(LeafReaderContext context, final Bits acceptDocs) throws IOException {
public Scorer scorer(LeafReaderContext context) throws IOException {
final DocIdSetIterator approximation;
if (boundingBoxWeight != null) {
approximation = boundingBoxWeight.scorer(context, null);
approximation = boundingBoxWeight.scorer(context);
} else {
approximation = DocIdSetIterator.all(context.reader().maxDoc());
}
@ -157,9 +157,6 @@ public class GeoDistanceRangeQuery extends Query {
@Override
public boolean matches() throws IOException {
final int doc = approximation.docID();
if (acceptDocs != null && acceptDocs.get(doc) == false) {
return false;
}
values.setDocument(doc);
final int length = values.count();
for (int i = 0; i < length; i++) {

@ -107,8 +107,8 @@ public class IncludeNestedDocsQuery extends Query {
}
@Override
public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
final Scorer parentScorer = parentWeight.scorer(context, acceptDocs);
public Scorer scorer(LeafReaderContext context) throws IOException {
final Scorer parentScorer = parentWeight.scorer(context);
// no matches
if (parentScorer == null) {

@ -251,7 +251,7 @@ public class IndexShard extends AbstractIndexShardComponent {
if (indexSettings.getAsBoolean(IndexCacheModule.QUERY_CACHE_EVERYTHING, false)) {
cachingPolicy = QueryCachingPolicy.ALWAYS_CACHE;
} else {
assert Version.CURRENT.luceneVersion == org.apache.lucene.util.Version.LUCENE_5_2_1;
assert Version.CURRENT.luceneVersion == org.apache.lucene.util.Version.LUCENE_5_3_0;
// TODO: remove this hack in Lucene 5.4, use UsageTrackingQueryCachingPolicy directly
// See https://issues.apache.org/jira/browse/LUCENE-6748
// cachingPolicy = new UsageTrackingQueryCachingPolicy();

@ -133,9 +133,13 @@ class VersionFieldUpgrader extends FilterCodecReader {
final GrowableWriter versions = new GrowableWriter(2, reader.maxDoc(), PackedInts.COMPACT);
PostingsEnum dpe = null;
for (BytesRef uid = uids.next(); uid != null; uid = uids.next()) {
dpe = uids.postings(reader.getLiveDocs(), dpe, PostingsEnum.PAYLOADS);
dpe = uids.postings(dpe, PostingsEnum.PAYLOADS);
assert terms.hasPayloads() : "field has payloads";
final Bits liveDocs = reader.getLiveDocs();
for (int doc = dpe.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = dpe.nextDoc()) {
if (liveDocs != null && liveDocs.get(doc) == false) {
continue;
}
dpe.nextPosition();
final BytesRef payload = dpe.getPayload();
if (payload != null && payload.length == 8) {

@ -22,7 +22,6 @@ package org.elasticsearch.index.store;
import com.google.common.collect.Sets;
import org.apache.lucene.store.*;
import org.apache.lucene.util.Constants;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.metrics.CounterMetric;
import org.elasticsearch.common.settings.Settings;
@ -94,11 +93,11 @@ public class FsDirectoryService extends DirectoryService implements StoreRateLim
}
/*
* We are mmapping docvalues as well as term dictionaries, all other files are served through NIOFS
* We are mmapping norms, docvalues as well as term dictionaries, all other files are served through NIOFS
* this provides good random access performance while not creating unnecessary mmaps for files like stored
* fields etc.
*/
private static final Set<String> PRIMARY_EXTENSIONS = Collections.unmodifiableSet(Sets.newHashSet("dvd", "tim"));
private static final Set<String> PRIMARY_EXTENSIONS = Collections.unmodifiableSet(Sets.newHashSet("nvd", "dvd", "tim"));
protected Directory newFSDirectory(Path location, LockFactory lockFactory) throws IOException {

@ -258,7 +258,7 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref
metadataLock.writeLock().lock();
// we make sure that nobody fetches the metadata while we do this rename operation here to ensure we don't
// get exceptions if files are still open.
try (Lock writeLock = Lucene.acquireWriteLock(directory())) {
try (Lock writeLock = directory().obtainLock(IndexWriter.WRITE_LOCK_NAME)) {
for (Map.Entry<String, String> entry : entries) {
String tempFile = entry.getKey();
String origFile = entry.getValue();
@ -593,7 +593,7 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref
*/
public void cleanupAndVerify(String reason, MetadataSnapshot sourceMetaData) throws IOException {
metadataLock.writeLock().lock();
try (Lock writeLock = Lucene.acquireWriteLock(directory)) {
try (Lock writeLock = directory.obtainLock(IndexWriter.WRITE_LOCK_NAME)) {
final StoreDirectory dir = directory;
for (String existingFile : dir.listAll()) {
if (Store.isAutogenerated(existingFile) || sourceMetaData.contains(existingFile)) {

@ -28,7 +28,6 @@ import org.apache.lucene.search.QueryCache;
import org.apache.lucene.search.QueryCachingPolicy;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Weight;
import org.apache.lucene.util.Bits;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.ShardCoreKeyMap;
@ -253,9 +252,9 @@ public class IndicesQueryCache extends AbstractComponent implements QueryCache,
}
@Override
public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
public Scorer scorer(LeafReaderContext context) throws IOException {
shardKeyMap.add(context.reader());
return in.scorer(context, acceptDocs);
return in.scorer(context);
}
}

@ -109,9 +109,9 @@ public class ParentToChildrenAggregator extends SingleBucketAggregator {
final SortedDocValues globalOrdinals = valuesSource.globalOrdinalsValues(parentType, ctx);
assert globalOrdinals != null;
Scorer parentScorer = parentFilter.scorer(ctx, null);
Scorer parentScorer = parentFilter.scorer(ctx);
final Bits parentDocs = Lucene.asSequentialAccessBits(ctx.reader().maxDoc(), parentScorer);
if (childFilter.scorer(ctx, null) != null) {
if (childFilter.scorer(ctx) != null) {
replay.add(ctx);
}
return new LeafBucketCollector() {
@ -146,7 +146,7 @@ public class ParentToChildrenAggregator extends SingleBucketAggregator {
this.replay = null;
for (LeafReaderContext ctx : replay) {
DocIdSetIterator childDocsIter = childFilter.scorer(ctx, ctx.reader().getLiveDocs());
DocIdSetIterator childDocsIter = childFilter.scorer(ctx);
if (childDocsIter == null) {
continue;
}
@ -157,7 +157,11 @@ public class ParentToChildrenAggregator extends SingleBucketAggregator {
// Set the scorer, since we now replay only the child docIds
sub.setScorer(ConstantScorer.create(childDocsIter, null, 1f));
final Bits liveDocs = ctx.reader().getLiveDocs();
for (int docId = childDocsIter.nextDoc(); docId != DocIdSetIterator.NO_MORE_DOCS; docId = childDocsIter.nextDoc()) {
if (liveDocs != null && liveDocs.get(docId) == false) {
continue;
}
long globalOrdinal = globalOrdinals.getOrd(docId);
if (globalOrdinal != -1) {
long bucketOrd = parentOrdToBuckets.get(globalOrdinal);

@ -58,7 +58,7 @@ public class FilterAggregator extends SingleBucketAggregator {
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
final LeafBucketCollector sub) throws IOException {
// no need to provide deleted docs to the filter
final Bits bits = Lucene.asSequentialAccessBits(ctx.reader().maxDoc(), filter.scorer(ctx, null));
final Bits bits = Lucene.asSequentialAccessBits(ctx.reader().maxDoc(), filter.scorer(ctx));
return new LeafBucketCollectorBase(sub, null) {
@Override
public void collect(int doc, long bucket) throws IOException {

@ -91,7 +91,7 @@ public class FiltersAggregator extends BucketsAggregator {
// no need to provide deleted docs to the filter
final Bits[] bits = new Bits[filters.length];
for (int i = 0; i < filters.length; ++i) {
bits[i] = Lucene.asSequentialAccessBits(ctx.reader().maxDoc(), filters[i].scorer(ctx, null));
bits[i] = Lucene.asSequentialAccessBits(ctx.reader().maxDoc(), filters[i].scorer(ctx));
}
return new LeafBucketCollectorBase(sub, null) {
@Override

@ -190,7 +190,7 @@ public final class InnerHitsContext {
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
return new ConstantScoreWeight(this) {
@Override
public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
public Scorer scorer(LeafReaderContext context) throws IOException {
// Nested docs only reside in a single segment, so no need to evaluate all segments
if (!context.reader().getCoreCacheKey().equals(leafReader.getCoreCacheKey())) {
return null;
@ -209,7 +209,7 @@ public final class InnerHitsContext {
return null;
}
final DocIdSet children = childFilter.getDocIdSet(context, acceptDocs);
final DocIdSet children = childFilter.getDocIdSet(context, null);
if (children == null) {
return null;
}

@ -85,7 +85,7 @@ public class MatchedQueriesFetchSubPhase implements FetchSubPhase {
Query filter = entry.getValue();
final Weight weight = hitContext.topLevelSearcher().createNormalizedWeight(filter, false);
final Scorer scorer = weight.scorer(hitContext.readerContext(), null);
final Scorer scorer = weight.scorer(hitContext.readerContext());
if (scorer == null) {
continue;
}

@ -20,7 +20,6 @@
package org.elasticsearch.search.highlight;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queries.BlendedTermQuery;
import org.apache.lucene.search.FilteredQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.highlight.QueryScorer;
@ -87,7 +86,7 @@ public final class CustomQueryScorer extends QueryScorer {
} else if (query instanceof FilteredQuery) {
query = ((FilteredQuery) query).getQuery();
extract(query, terms);
} else if (query instanceof BlendedTermQuery) {
} else {
extractWeightedTerms(terms, query);
}
}

@ -19,12 +19,19 @@
package org.elasticsearch.search.lookup;
import org.apache.lucene.index.*;
import org.apache.lucene.index.Fields;
import org.apache.lucene.index.FilterLeafReader.FilterPostingsEnum;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermContext;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.TermStatistics;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.lucene.search.EmptyScorer;
import java.io.IOException;
import java.util.Iterator;
@ -144,7 +151,28 @@ public class IndexFieldTerm implements Iterable<TermPosition> {
if (terms != null) {
TermsEnum termsEnum = terms.iterator();
if (termsEnum.seekExact(identifier.bytes())) {
newPostings = termsEnum.postings(reader.getLiveDocs(), postings, luceneFlags);
newPostings = termsEnum.postings(postings, luceneFlags);
final Bits liveDocs = reader.getLiveDocs();
if (liveDocs != null) {
newPostings = new FilterPostingsEnum(newPostings) {
private int doNext(int d) throws IOException {
for (; d != NO_MORE_DOCS; d = super.nextDoc()) {
if (liveDocs.get(d)) {
return d;
}
}
return NO_MORE_DOCS;
}
@Override
public int nextDoc() throws IOException {
return doNext(super.nextDoc());
}
@Override
public int advance(int target) throws IOException {
return doNext(super.advance(target));
}
};
}
}
}
}

@ -22,6 +22,7 @@ package org.elasticsearch.search.suggest.completion;
import com.carrotsearch.hppc.ObjectLongHashMap;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.TokenStreamToAutomaton;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.FieldsConsumer;
import org.apache.lucene.index.PostingsEnum;
@ -40,6 +41,7 @@ import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.IntsRef;
import org.apache.lucene.util.automaton.Automaton;
import org.apache.lucene.util.automaton.LimitedFiniteStringsIterator;
import org.apache.lucene.util.fst.ByteSequenceOutputs;
import org.apache.lucene.util.fst.FST;
import org.apache.lucene.util.fst.PairOutputs;
@ -56,6 +58,7 @@ import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
@ -156,7 +159,7 @@ public class AnalyzingCompletionLookupProvider extends CompletionLookupProvider
if (term == null) {
break;
}
docsEnum = termsEnum.postings(null, docsEnum, PostingsEnum.PAYLOADS);
docsEnum = termsEnum.postings(docsEnum, PostingsEnum.PAYLOADS);
builder.startTerm(term);
int docFreq = 0;
while (docsEnum.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
@ -397,6 +400,8 @@ public class AnalyzingCompletionLookupProvider extends CompletionLookupProvider
@Override
public Set<IntsRef> toFiniteStrings(TokenStream stream) throws IOException {
return prototype.toFiniteStrings(prototype.getTokenStreamToAutomaton(), stream);
return prototype.toFiniteStrings(stream);
}
}

@ -135,11 +135,6 @@ public final class CompletionTokenStream extends TokenStream {
private final BytesRefBuilder bytes = new BytesRefBuilder();
private CharsRefBuilder charsRef;
@Override
public void fillBytesRef() {
// does nothing - we change in place
}
@Override
public BytesRefBuilder builder() {
return bytes;

@ -346,8 +346,8 @@ public abstract class AbstractTermVectorsTestCase extends ESIntegTestCase {
assertNotNull(luceneTermEnum.next());
assertThat(esTermEnum.totalTermFreq(), equalTo(luceneTermEnum.totalTermFreq()));
PostingsEnum esDocsPosEnum = esTermEnum.postings(null, null, PostingsEnum.POSITIONS);
PostingsEnum luceneDocsPosEnum = luceneTermEnum.postings(null, null, PostingsEnum.POSITIONS);
PostingsEnum esDocsPosEnum = esTermEnum.postings(null, PostingsEnum.POSITIONS);
PostingsEnum luceneDocsPosEnum = luceneTermEnum.postings(null, PostingsEnum.POSITIONS);
if (luceneDocsPosEnum == null) {
// test we expect that...
assertFalse(field.storedOffset);

@ -119,7 +119,7 @@ public class GetTermVectorsCheckDocFreqIT extends ESIntegTestCase {
assertThat("expected ttf of " + string, numDocs, equalTo((int) iterator.totalTermFreq()));
}
PostingsEnum docsAndPositions = iterator.postings(null, null, PostingsEnum.ALL);
PostingsEnum docsAndPositions = iterator.postings(null, PostingsEnum.ALL);
assertThat(docsAndPositions.nextDoc(), equalTo(0));
assertThat(freq[j], equalTo(docsAndPositions.freq()));
assertThat(iterator.docFreq(), equalTo(numDocs));
@ -176,7 +176,7 @@ public class GetTermVectorsCheckDocFreqIT extends ESIntegTestCase {
assertThat("expected ttf of " + string, -1, equalTo((int) iterator.totalTermFreq()));
PostingsEnum docsAndPositions = iterator.postings(null, null, PostingsEnum.ALL);
PostingsEnum docsAndPositions = iterator.postings(null, PostingsEnum.ALL);
assertThat(docsAndPositions.nextDoc(), equalTo(0));
assertThat(freq[j], equalTo(docsAndPositions.freq()));
assertThat(iterator.docFreq(), equalTo(-1));
@ -236,7 +236,7 @@ public class GetTermVectorsCheckDocFreqIT extends ESIntegTestCase {
assertThat("expected ttf of " + string, numDocs, equalTo((int) iterator.totalTermFreq()));
}
PostingsEnum docsAndPositions = iterator.postings(null, null, PostingsEnum.ALL);
PostingsEnum docsAndPositions = iterator.postings(null, PostingsEnum.ALL);
assertThat(docsAndPositions.nextDoc(), equalTo(0));
assertThat(freq[j], equalTo(docsAndPositions.freq()));
assertThat(iterator.docFreq(), equalTo(numDocs));

@ -335,7 +335,7 @@ public class GetTermVectorsIT extends AbstractTermVectorsTestCase {
assertThat(infoString, next, notNullValue());
// do not test ttf or doc frequency, because here we have
// many shards and do not know how documents are distributed
PostingsEnum docsAndPositions = iterator.postings(null, null, PostingsEnum.ALL);
PostingsEnum docsAndPositions = iterator.postings(null, PostingsEnum.ALL);
// docs and pos only returns something if positions or
// payloads or offsets are stored / requestd Otherwise use
// DocsEnum?
@ -464,7 +464,7 @@ public class GetTermVectorsIT extends AbstractTermVectorsTestCase {
TermsEnum iterator = terms.iterator();
while (iterator.next() != null) {
String term = iterator.term().utf8ToString();
PostingsEnum docsAndPositions = iterator.postings(null, null, PostingsEnum.ALL);
PostingsEnum docsAndPositions = iterator.postings(null, PostingsEnum.ALL);
assertThat(docsAndPositions.nextDoc(), equalTo(0));
List<BytesRef> curPayloads = payloads.get(term);
assertThat(term, curPayloads, notNullValue());
@ -658,7 +658,7 @@ public class GetTermVectorsIT extends AbstractTermVectorsTestCase {
assertThat(next, notNullValue());
// do not test ttf or doc frequency, because here we have many
// shards and do not know how documents are distributed
PostingsEnum docsAndPositions = iterator.postings(null, null, PostingsEnum.ALL);
PostingsEnum docsAndPositions = iterator.postings(null, PostingsEnum.ALL);
assertThat(docsAndPositions.nextDoc(), equalTo(0));
assertThat(freq[j], equalTo(docsAndPositions.freq()));
int[] termPos = pos[j];
@ -753,8 +753,8 @@ public class GetTermVectorsIT extends AbstractTermVectorsTestCase {
assertThat("term: " + string0, iter0.totalTermFreq(), equalTo(iter1.totalTermFreq()));
// compare freq and docs
PostingsEnum docsAndPositions0 = iter0.postings(null, null, PostingsEnum.ALL);
PostingsEnum docsAndPositions1 = iter1.postings(null, null, PostingsEnum.ALL);
PostingsEnum docsAndPositions0 = iter0.postings(null, PostingsEnum.ALL);
PostingsEnum docsAndPositions1 = iter1.postings(null, PostingsEnum.ALL);
assertThat("term: " + string0, docsAndPositions0.nextDoc(), equalTo(docsAndPositions1.nextDoc()));
assertThat("term: " + string0, docsAndPositions0.freq(), equalTo(docsAndPositions1.freq()));

@ -34,7 +34,6 @@ import org.apache.lucene.search.QueryUtils;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Weight;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.Version;
import org.elasticsearch.test.ESTestCase;
@ -73,7 +72,7 @@ public class IndexCacheableQueryTests extends ESTestCase {
}
@Override
public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
public Scorer scorer(LeafReaderContext context) throws IOException {
return null;
}
@ -104,10 +103,7 @@ public class IndexCacheableQueryTests extends ESTestCase {
}
IndexReader reader = writer.getReader();
// IndexReader wrapping is disabled because of LUCENE-6500.
// Add it back when we are on 5.3
assert Version.LATEST == Version.LUCENE_5_2_1;
IndexSearcher searcher = newSearcher(reader, false);
IndexSearcher searcher = newSearcher(reader);
reader = searcher.getIndexReader(); // reader might be wrapped
searcher.setQueryCache(cache);
searcher.setQueryCachingPolicy(policy);
@ -123,10 +119,7 @@ public class IndexCacheableQueryTests extends ESTestCase {
writer.addDocument(new Document());
IndexReader reader2 = writer.getReader();
// IndexReader wrapping is disabled because of LUCENE-6500.
// Add it back when we are on 5.3
assert Version.LATEST == Version.LUCENE_5_2_1;
searcher = newSearcher(reader2, false);
searcher = newSearcher(reader2);
reader2 = searcher.getIndexReader(); // reader might be wrapped
searcher.setQueryCache(cache);
searcher.setQueryCachingPolicy(policy);

@ -214,7 +214,7 @@ public class SimpleLuceneTests extends ESTestCase {
TermsEnum termsEnum = terms.iterator();
termsEnum.next();
PostingsEnum termDocs = termsEnum.postings(atomicReader.getLiveDocs(), null);
PostingsEnum termDocs = termsEnum.postings(null);
assertThat(termDocs.nextDoc(), equalTo(0));
assertThat(termDocs.docID(), equalTo(0));
assertThat(termDocs.freq(), equalTo(1));
@ -222,7 +222,7 @@ public class SimpleLuceneTests extends ESTestCase {
terms = atomicReader.terms("int2");
termsEnum = terms.iterator();
termsEnum.next();
termDocs = termsEnum.postings(atomicReader.getLiveDocs(), termDocs);
termDocs = termsEnum.postings(termDocs);
assertThat(termDocs.nextDoc(), equalTo(0));
assertThat(termDocs.docID(), equalTo(0));
assertThat(termDocs.freq(), equalTo(2));

@ -30,6 +30,7 @@ import org.apache.lucene.codecs.lucene49.Lucene49Codec;
import org.apache.lucene.codecs.lucene50.Lucene50Codec;
import org.apache.lucene.codecs.lucene50.Lucene50StoredFieldsFormat;
import org.apache.lucene.codecs.lucene50.Lucene50StoredFieldsFormat.Mode;
import org.apache.lucene.codecs.lucene53.Lucene53Codec;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter;
@ -51,7 +52,8 @@ public class CodecTests extends ESSingleNodeTestCase {
public void testResolveDefaultCodecs() throws Exception {
CodecService codecService = createCodecService();
assertThat(codecService.codec("default"), instanceOf(PerFieldMappingPostingFormatCodec.class));
assertThat(codecService.codec("default"), instanceOf(Lucene50Codec.class));
assertThat(codecService.codec("default"), instanceOf(Lucene53Codec.class));
assertThat(codecService.codec("Lucene50"), instanceOf(Lucene50Codec.class));
assertThat(codecService.codec("Lucene410"), instanceOf(Lucene410Codec.class));
assertThat(codecService.codec("Lucene49"), instanceOf(Lucene49Codec.class));
assertThat(codecService.codec("Lucene46"), instanceOf(Lucene46Codec.class));

@ -116,7 +116,6 @@ public class InternalEngineTests extends ESTestCase {
protected InternalEngine replicaEngine;
private Settings defaultSettings;
private int indexConcurrency;
private String codecName;
private Path primaryTranslogDir;
private Path replicaTranslogDir;
@ -127,7 +126,6 @@ public class InternalEngineTests extends ESTestCase {
super.setUp();
CodecService codecService = new CodecService(shardId.index());
indexConcurrency = randomIntBetween(1, 20);
String name = Codec.getDefault().getName();
if (Arrays.asList(codecService.availableCodecs()).contains(name)) {
// some codecs are read only so we only take the ones that we have in the service and randomly
@ -140,7 +138,6 @@ public class InternalEngineTests extends ESTestCase {
.put(EngineConfig.INDEX_COMPOUND_ON_FLUSH, randomBoolean())
.put(EngineConfig.INDEX_GC_DELETES_SETTING, "1h") // make sure this doesn't kick in on us
.put(EngineConfig.INDEX_CODEC_SETTING, codecName)
.put(EngineConfig.INDEX_CONCURRENCY_SETTING, indexConcurrency)
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.build(); // TODO randomize more settings
threadPool = new ThreadPool(getClass().getName());
@ -1507,8 +1504,6 @@ public class InternalEngineTests extends ESTestCase {
assertEquals(engine.config().getCodec().getName(), codecService.codec(codecName).getName());
assertEquals(currentIndexWriterConfig.getCodec().getName(), codecService.codec(codecName).getName());
assertEquals(engine.config().getIndexConcurrency(), indexConcurrency);
assertEquals(currentIndexWriterConfig.getMaxThreadStates(), indexConcurrency);
}
@Test

@ -91,7 +91,6 @@ public class ShadowEngineTests extends ESTestCase {
protected Engine replicaEngine;
private Settings defaultSettings;
private int indexConcurrency;
private String codecName;
private Path dirPath;
@ -100,7 +99,6 @@ public class ShadowEngineTests extends ESTestCase {
public void setUp() throws Exception {
super.setUp();
CodecService codecService = new CodecService(shardId.index());
indexConcurrency = randomIntBetween(1, 20);
String name = Codec.getDefault().getName();
if (Arrays.asList(codecService.availableCodecs()).contains(name)) {
// some codecs are read only so we only take the ones that we have in the service and randomly
@ -113,7 +111,6 @@ public class ShadowEngineTests extends ESTestCase {
.put(EngineConfig.INDEX_COMPOUND_ON_FLUSH, randomBoolean())
.put(EngineConfig.INDEX_GC_DELETES_SETTING, "1h") // make sure this doesn't kick in on us
.put(EngineConfig.INDEX_CODEC_SETTING, codecName)
.put(EngineConfig.INDEX_CONCURRENCY_SETTING, indexConcurrency)
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.build(); // TODO randomize more settings
threadPool = new ThreadPool(getClass().getName());
@ -921,7 +918,6 @@ public class ShadowEngineTests extends ESTestCase {
public void testSettings() {
CodecService codecService = new CodecService(shardId.index());
assertEquals(replicaEngine.config().getCodec().getName(), codecService.codec(codecName).getName());
assertEquals(replicaEngine.config().getIndexConcurrency(), indexConcurrency);
}
@Test

@ -59,7 +59,7 @@ public class ParentChildFilteredTermsEnumTests extends ESTestCase {
for (BytesRef term = termsEnum.next(); term != null; term = termsEnum.next()) {
++expected;
assertThat(term.utf8ToString(), equalTo(format(expected)));
PostingsEnum docsEnum = termsEnum.postings(null, null);
PostingsEnum docsEnum = termsEnum.postings(null);
assertThat(docsEnum, notNullValue());
int docId = docsEnum.nextDoc();
assertThat(docId, not(equalTo(-1)));
@ -98,7 +98,7 @@ public class ParentChildFilteredTermsEnumTests extends ESTestCase {
for (BytesRef term = termsEnum.next(); term != null; term = termsEnum.next()) {
++expected;
assertThat(term.utf8ToString(), equalTo(format(expected)));
PostingsEnum docsEnum = termsEnum.postings(null, null);
PostingsEnum docsEnum = termsEnum.postings(null);
assertThat(docsEnum, notNullValue());
int numDocs = 0;
for (int docId = docsEnum.nextDoc(); docId != DocIdSetIterator.NO_MORE_DOCS; docId = docsEnum.nextDoc()) {

@ -28,6 +28,7 @@ import org.apache.lucene.index.*;
import org.apache.lucene.search.*;
import org.apache.lucene.search.join.BitDocIdSetFilter;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.common.lease.Releasables;
@ -258,8 +259,14 @@ public class ChildrenConstantScoreQueryTests extends AbstractChildTestCase {
for (String id : parentIds) {
TermsEnum.SeekStatus seekStatus = termsEnum.seekCeil(Uid.createUidAsBytes("parent", id));
if (seekStatus == TermsEnum.SeekStatus.FOUND) {
docsEnum = termsEnum.postings(slowLeafReader.getLiveDocs(), docsEnum, PostingsEnum.NONE);
expectedResult.set(docsEnum.nextDoc());
docsEnum = termsEnum.postings(docsEnum, PostingsEnum.NONE);
final Bits liveDocs = slowLeafReader.getLiveDocs();
for (int doc = docsEnum.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = docsEnum.nextDoc()) {
if (liveDocs == null || liveDocs.get(doc)) {
break;
}
}
expectedResult.set(docsEnum.docID());
} else if (seekStatus == TermsEnum.SeekStatus.END) {
break;
}

@ -31,6 +31,7 @@ import org.apache.lucene.index.*;
import org.apache.lucene.search.*;
import org.apache.lucene.search.join.BitDocIdSetFilter;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.common.lease.Releasables;
@ -231,8 +232,14 @@ public class ChildrenQueryTests extends AbstractChildTestCase {
if (count >= minChildren && (maxChildren == 0 || count <= maxChildren)) {
TermsEnum.SeekStatus seekStatus = termsEnum.seekCeil(Uid.createUidAsBytes("parent", entry.getKey()));
if (seekStatus == TermsEnum.SeekStatus.FOUND) {
docsEnum = termsEnum.postings(slowLeafReader.getLiveDocs(), docsEnum, PostingsEnum.NONE);
expectedResult.set(docsEnum.nextDoc());
docsEnum = termsEnum.postings(docsEnum, PostingsEnum.NONE);
final Bits liveDocs = slowLeafReader.getLiveDocs();
for (int doc = docsEnum.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = docsEnum.nextDoc()) {
if (liveDocs == null || liveDocs.get(doc)) {
break;
}
}
expectedResult.set(docsEnum.docID());
scores[docsEnum.docID()] = new FloatArrayList(entry.getValue());
} else if (seekStatus == TermsEnum.SeekStatus.END) {
break;

@ -28,6 +28,7 @@ import org.apache.lucene.index.*;
import org.apache.lucene.search.*;
import org.apache.lucene.search.join.BitDocIdSetFilter;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.common.lease.Releasables;
@ -209,8 +210,14 @@ public class ParentConstantScoreQueryTests extends AbstractChildTestCase {
for (String id : childIds) {
TermsEnum.SeekStatus seekStatus = termsEnum.seekCeil(Uid.createUidAsBytes("child", id));
if (seekStatus == TermsEnum.SeekStatus.FOUND) {
docsEnum = termsEnum.postings(slowLeafReader.getLiveDocs(), docsEnum, PostingsEnum.NONE);
expectedResult.set(docsEnum.nextDoc());
docsEnum = termsEnum.postings(docsEnum, PostingsEnum.NONE);
final Bits liveDocs = slowLeafReader.getLiveDocs();
for (int doc = docsEnum.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = docsEnum.nextDoc()) {
if (liveDocs == null || liveDocs.get(doc)) {
break;
}
}
expectedResult.set(docsEnum.docID());
} else if (seekStatus == TermsEnum.SeekStatus.END) {
break;
}

@ -29,6 +29,7 @@ import org.apache.lucene.index.*;
import org.apache.lucene.search.*;
import org.apache.lucene.search.join.BitDocIdSetFilter;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.common.lease.Releasables;
@ -207,8 +208,14 @@ public class ParentQueryTests extends AbstractChildTestCase {
for (Map.Entry<String, Float> entry : childIdsAndScore.entrySet()) {
TermsEnum.SeekStatus seekStatus = termsEnum.seekCeil(Uid.createUidAsBytes("child", entry.getKey()));
if (seekStatus == TermsEnum.SeekStatus.FOUND) {
docsEnum = termsEnum.postings(slowLeafReader.getLiveDocs(), docsEnum, PostingsEnum.NONE);
expectedResult.set(docsEnum.nextDoc());
docsEnum = termsEnum.postings(docsEnum, PostingsEnum.NONE);
final Bits liveDocs = slowLeafReader.getLiveDocs();
for (int doc = docsEnum.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = docsEnum.nextDoc()) {
if (liveDocs == null || liveDocs.get(doc)) {
break;
}
}
expectedResult.set(docsEnum.docID());
FloatArrayList s = scores[docsEnum.docID()];
if (s == null) {
scores[docsEnum.docID()] = s = new FloatArrayList(2);

@ -22,8 +22,8 @@ import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.FilterCodec;
import org.apache.lucene.codecs.SegmentInfoFormat;
import org.apache.lucene.codecs.lucene50.Lucene50Codec;
import org.apache.lucene.codecs.lucene50.Lucene50SegmentInfoFormat;
import org.apache.lucene.codecs.lucene53.Lucene53Codec;
import org.apache.lucene.document.*;
import org.apache.lucene.index.*;
import org.apache.lucene.store.*;
@ -181,7 +181,7 @@ public class StoreTest extends ESTestCase {
private static final class OldSIMockingCodec extends FilterCodec {
protected OldSIMockingCodec() {
super(new Lucene50Codec().getName(), new Lucene50Codec());
super(new Lucene53Codec().getName(), new Lucene53Codec());
}
@Override
@ -239,6 +239,10 @@ public class StoreTest extends ESTestCase {
}
// IF THIS TEST FAILS ON UPGRADE GO LOOK AT THE OldSIMockingCodec!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@AwaitsFix(bugUrl="Fails with seed E1394B038144F6E")
// The test currently fails because the segment infos and the index don't
// agree on the oldest version of a segment. We should fix this test by
// switching to a static bw index
@Test
public void testWriteLegacyChecksums() throws IOException {
final ShardId shardId = new ShardId(new Index("index"), 1);
@ -754,7 +758,6 @@ public class StoreTest extends ESTestCase {
IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random)).setCodec(TestUtil.getDefaultCodec());
iwc.setMergePolicy(NoMergePolicy.INSTANCE);
iwc.setUseCompoundFile(random.nextBoolean());
iwc.setMaxThreadStates(1);
final ShardId shardId = new ShardId(new Index("index"), 1);
DirectoryService directoryService = new LuceneManagedDirectoryService(random);
Store store = new Store(shardId, Settings.EMPTY, directoryService, new DummyShardLock(shardId));
@ -785,7 +788,6 @@ public class StoreTest extends ESTestCase {
IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random)).setCodec(TestUtil.getDefaultCodec());
iwc.setMergePolicy(NoMergePolicy.INSTANCE);
iwc.setUseCompoundFile(random.nextBoolean());
iwc.setMaxThreadStates(1);
final ShardId shardId = new ShardId(new Index("index"), 1);
DirectoryService directoryService = new LuceneManagedDirectoryService(random);
store = new Store(shardId, Settings.EMPTY, directoryService, new DummyShardLock(shardId));
@ -826,7 +828,6 @@ public class StoreTest extends ESTestCase {
IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random)).setCodec(TestUtil.getDefaultCodec());
iwc.setMergePolicy(NoMergePolicy.INSTANCE);
iwc.setUseCompoundFile(random.nextBoolean());
iwc.setMaxThreadStates(1);
iwc.setOpenMode(IndexWriterConfig.OpenMode.APPEND);
IndexWriter writer = new IndexWriter(store.directory(), iwc);
writer.deleteDocuments(new Term("id", Integer.toString(random().nextInt(numDocs))));
@ -862,7 +863,6 @@ public class StoreTest extends ESTestCase {
iwc = new IndexWriterConfig(new MockAnalyzer(random)).setCodec(TestUtil.getDefaultCodec());
iwc.setMergePolicy(NoMergePolicy.INSTANCE);
iwc.setUseCompoundFile(true); // force CFS - easier to test here since we know it will add 3 files
iwc.setMaxThreadStates(1);
iwc.setOpenMode(IndexWriterConfig.OpenMode.APPEND);
writer = new IndexWriter(store.directory(), iwc);
writer.addDocument(docs.get(0));

@ -20,24 +20,15 @@
package org.elasticsearch.indices.warmer;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.segments.IndexSegments;
import org.elasticsearch.action.admin.indices.segments.IndexShardSegments;
import org.elasticsearch.action.admin.indices.segments.IndicesSegmentResponse;
import org.elasticsearch.action.admin.indices.segments.ShardSegments;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerResponse;
import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersResponse;
import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerResponse;
import org.elasticsearch.client.Requests;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.engine.Segment;
import org.elasticsearch.index.mapper.MappedFieldType.Loading;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.indices.cache.request.IndicesRequestCache;
import org.elasticsearch.search.SearchService;
import org.elasticsearch.search.warmer.IndexWarmerMissingException;
import org.elasticsearch.search.warmer.IndexWarmersMetaData;
import org.elasticsearch.test.ESIntegTestCase;
@ -45,10 +36,12 @@ import org.hamcrest.Matchers;
import org.junit.Test;
import java.util.List;
import java.util.Locale;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
public class SimpleIndicesWarmerIT extends ESIntegTestCase {
@ -264,94 +257,6 @@ public class SimpleIndicesWarmerIT extends ESIntegTestCase {
return indicesStatsResponse.getIndex("test").getPrimaries().warmer.total();
}
private long getSegmentsMemoryUsage(String idx) {
IndicesSegmentResponse response = client().admin().indices().segments(Requests.indicesSegmentsRequest(idx)).actionGet();
IndexSegments indicesSegments = response.getIndices().get(idx);
long total = 0;
for (IndexShardSegments indexShardSegments : indicesSegments) {
for (ShardSegments shardSegments : indexShardSegments) {
for (Segment segment : shardSegments) {
logger.debug("+=" + segment.memoryInBytes + " " + indexShardSegments.getShardId() + " " + shardSegments.getShardRouting().getIndex());
total += segment.memoryInBytes;
}
}
}
return total;
}
private enum LoadingMethod {
LAZY {
@Override
CreateIndexRequestBuilder createIndex(String indexName, String type, String fieldName) {
return client().admin().indices().prepareCreate(indexName).setSettings(Settings.builder().put(SINGLE_SHARD_NO_REPLICA).put(SearchService.NORMS_LOADING_KEY, Loading.LAZY_VALUE));
}
},
EAGER {
@Override
CreateIndexRequestBuilder createIndex(String indexName, String type, String fieldName) {
return client().admin().indices().prepareCreate(indexName).setSettings(Settings.builder().put(SINGLE_SHARD_NO_REPLICA).put(SearchService.NORMS_LOADING_KEY, Loading.EAGER_VALUE));
}
@Override
boolean isLazy() {
return false;
}
},
EAGER_PER_FIELD {
@Override
CreateIndexRequestBuilder createIndex(String indexName, String type, String fieldName) throws Exception {
return client().admin().indices().prepareCreate(indexName).setSettings(Settings.builder().put(SINGLE_SHARD_NO_REPLICA).put(SearchService.NORMS_LOADING_KEY, Loading.LAZY_VALUE)).addMapping(type, JsonXContent.contentBuilder()
.startObject()
.startObject(type)
.startObject("properties")
.startObject(fieldName)
.field("type", "string")
.startObject("norms")
.field("loading", Loading.EAGER_VALUE)
.endObject()
.endObject()
.endObject()
.endObject()
.endObject()
);
}
@Override
boolean isLazy() {
return false;
}
};
private static Settings SINGLE_SHARD_NO_REPLICA = Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).build();
abstract CreateIndexRequestBuilder createIndex(String indexName, String type, String fieldName) throws Exception;
boolean isLazy() {
return true;
}
}
// NOTE: we have to ensure we defeat compression strategies of the default codec...
public void testEagerLoading() throws Exception {
for (LoadingMethod method : LoadingMethod.values()) {
logger.debug("METHOD " + method);
String indexName = method.name().toLowerCase(Locale.ROOT);
assertAcked(method.createIndex(indexName, "t", "foo"));
// index a doc with 1 token, and one with 3 tokens so we dont get CONST compressed (otherwise norms take zero memory usage)
client().prepareIndex(indexName, "t", "1").setSource("foo", "bar").execute().actionGet();
client().prepareIndex(indexName, "t", "2").setSource("foo", "bar baz foo").setRefresh(true).execute().actionGet();
ensureGreen(indexName);
long memoryUsage0 = getSegmentsMemoryUsage(indexName);
// queries load norms if they were not loaded before
client().prepareSearch(indexName).setQuery(QueryBuilders.matchQuery("foo", "bar")).execute().actionGet();
long memoryUsage1 = getSegmentsMemoryUsage(indexName);
if (method.isLazy()) {
assertThat(memoryUsage1, greaterThan(memoryUsage0));
} else {
assertThat(memoryUsage1, equalTo(memoryUsage0));
}
}
}
public void testQueryCacheOnWarmer() {
createIndex("test");
ensureGreen();

@ -171,7 +171,7 @@ public class FetchSubPhasePluginIT extends ESIntegTestCase {
TermsEnum terms = termVector.getFields().terms(field).iterator();
BytesRef term;
while ((term = terms.next()) != null) {
tv.put(term.utf8ToString(), terms.postings(null, null, PostingsEnum.ALL).freq());
tv.put(term.utf8ToString(), terms.postings(null, PostingsEnum.ALL).freq());
}
hitField.values().add(tv);
} catch (IOException e) {

@ -1406,6 +1406,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
}
@Test
@AwaitsFix(bugUrl="Broken now that BoostingQuery does not extend BooleanQuery anymore")
public void testBoostingQueryTermVector() throws IOException {
assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping()));
ensureGreen();
@ -1546,7 +1547,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
.fragmentSize(-1).numOfFragments(2).fragmenter("simple")).get();
assertHighlight(response, 0, "tags", 0, equalTo("this is a really <em>long</em> <em>tag</em> i would like to highlight"));
assertHighlight(response, 0, "tags", 1, 2, equalTo("here is another one that is very <em>long</em> <em>tag</em> and has the tag token near the end"));
assertHighlight(response, 0, "tags", 1, 2, equalTo("here is another one that is very <em>long</em> <em>tag</em> and has the <em>tag</em> token near the end"));
response = client().prepareSearch("test")
.setQuery(QueryBuilders.matchQuery("tags", "long tag").type(MatchQueryBuilder.Type.PHRASE))
@ -1554,7 +1555,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
.fragmentSize(-1).numOfFragments(2).fragmenter("span")).get();
assertHighlight(response, 0, "tags", 0, equalTo("this is a really <em>long</em> <em>tag</em> i would like to highlight"));
assertHighlight(response, 0, "tags", 1, 2, equalTo("here is another one that is very <em>long</em> <em>tag</em> and has the tag token near the end"));
assertHighlight(response, 0, "tags", 1, 2, equalTo("here is another one that is very <em>long</em> <em>tag</em> and has the <em>tag</em> token near the end"));
assertFailures(client().prepareSearch("test")
.setQuery(QueryBuilders.matchQuery("tags", "long tag").type(MatchQueryBuilder.Type.PHRASE))
@ -2054,7 +2055,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <xxx>quick</xxx> <xxx>brown</xxx> fox jumps over the lazy quick dog"));
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <xxx>quick</xxx> <xxx>brown</xxx> fox jumps over the lazy <xxx>quick</xxx> dog"));
}
@Test
@ -2561,6 +2562,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
}
@Test
@AwaitsFix(bugUrl="Broken now that BoostingQuery does not extend BooleanQuery anymore")
public void testFastVectorHighlighterPhraseBoost() throws Exception {
assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping()));
phraseBoostTestCase("fvh");

@ -54,7 +54,7 @@ public class CompletionTokenStreamTest extends ESTokenStreamTestCase {
TokenStream suggestTokenStream = new ByteTermAttrToCharTermAttrFilter(new CompletionTokenStream(tokenStream, payload, new CompletionTokenStream.ToFiniteStrings() {
@Override
public Set<IntsRef> toFiniteStrings(TokenStream stream) throws IOException {
return suggester.toFiniteStrings(suggester.getTokenStreamToAutomaton(), stream);
return suggester.toFiniteStrings(stream);
}
}));
assertTokenStreamContents(suggestTokenStream, new String[] {"mykeyword"}, null, null, new String[] {"Surface keyword|friggin payload|10"}, new int[] { 1 }, null, null);
@ -73,7 +73,7 @@ public class CompletionTokenStreamTest extends ESTokenStreamTestCase {
TokenStream suggestTokenStream = new ByteTermAttrToCharTermAttrFilter(new CompletionTokenStream(filter, payload, new CompletionTokenStream.ToFiniteStrings() {
@Override
public Set<IntsRef> toFiniteStrings(TokenStream stream) throws IOException {
return suggester.toFiniteStrings(suggester.getTokenStreamToAutomaton(), stream);
return suggester.toFiniteStrings(stream);
}
}));
assertTokenStreamContents(suggestTokenStream, new String[] {"mysynonym", "mykeyword"}, null, null, new String[] {"Surface keyword|friggin payload|10", "Surface keyword|friggin payload|10"}, new int[] { 2, 0 }, null, null);
@ -97,7 +97,7 @@ public class CompletionTokenStreamTest extends ESTokenStreamTestCase {
TokenStream suggestTokenStream = new CompletionTokenStream(filter, new BytesRef("Surface keyword|friggin payload|10"), new CompletionTokenStream.ToFiniteStrings() {
@Override
public Set<IntsRef> toFiniteStrings(TokenStream stream) throws IOException {
Set<IntsRef> finiteStrings = suggester.toFiniteStrings(suggester.getTokenStreamToAutomaton(), stream);
Set<IntsRef> finiteStrings = suggester.toFiniteStrings(stream);
return finiteStrings;
}
});
@ -137,7 +137,7 @@ public class CompletionTokenStreamTest extends ESTokenStreamTestCase {
TokenStream suggestTokenStream = new CompletionTokenStream(filter, new BytesRef("Surface keyword|friggin payload|10"), new CompletionTokenStream.ToFiniteStrings() {
@Override
public Set<IntsRef> toFiniteStrings(TokenStream stream) throws IOException {
Set<IntsRef> finiteStrings = suggester.toFiniteStrings(suggester.getTokenStreamToAutomaton(), stream);
Set<IntsRef> finiteStrings = suggester.toFiniteStrings(stream);
return finiteStrings;
}
});
@ -156,17 +156,15 @@ public class CompletionTokenStreamTest extends ESTokenStreamTestCase {
TokenStream suggestTokenStream = new ByteTermAttrToCharTermAttrFilter(new CompletionTokenStream(tokenizer, payload, new CompletionTokenStream.ToFiniteStrings() {
@Override
public Set<IntsRef> toFiniteStrings(TokenStream stream) throws IOException {
return suggester.toFiniteStrings(suggester.getTokenStreamToAutomaton(), stream);
return suggester.toFiniteStrings(stream);
}
}));
TermToBytesRefAttribute termAtt = suggestTokenStream.getAttribute(TermToBytesRefAttribute.class);
BytesRef ref = termAtt.getBytesRef();
assertNotNull(ref);
assertNotNull(termAtt.getBytesRef());
suggestTokenStream.reset();
while (suggestTokenStream.incrementToken()) {
termAtt.fillBytesRef();
assertThat(ref.utf8ToString(), equalTo("mykeyword"));
assertThat(termAtt.getBytesRef().utf8ToString(), equalTo("mykeyword"));
}
suggestTokenStream.end();
suggestTokenStream.close();

@ -154,7 +154,7 @@ public class AnalyzingCompletionLookupProviderV1 extends CompletionLookupProvide
if (term == null) {
break;
}
docsEnum = termsEnum.postings(null, docsEnum, PostingsEnum.PAYLOADS);
docsEnum = termsEnum.postings(docsEnum, PostingsEnum.PAYLOADS);
builder.startTerm(term);
int docFreq = 0;
while (docsEnum.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
@ -330,6 +330,6 @@ public class AnalyzingCompletionLookupProviderV1 extends CompletionLookupProvide
@Override
public Set<IntsRef> toFiniteStrings(TokenStream stream) throws IOException {
return prototype.toFiniteStrings(prototype.getTokenStreamToAutomaton(), stream);
return prototype.toFiniteStrings(stream);
}
}

@ -23,7 +23,7 @@ import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.FieldsConsumer;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.codecs.lucene50.Lucene50Codec;
import org.apache.lucene.codecs.lucene53.Lucene53Codec;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.Fields;
@ -44,7 +44,6 @@ import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LineFileDocs;
import org.elasticsearch.Version;
@ -282,7 +281,7 @@ public class CompletionPostingsFormatTest extends ESTestCase {
public Lookup buildAnalyzingLookup(final CompletionFieldMapper mapper, String[] terms, String[] surfaces, long[] weights)
throws IOException {
RAMDirectory dir = new RAMDirectory();
Codec codec = new Lucene50Codec() {
Codec codec = new Lucene53Codec() {
public PostingsFormat getPostingsFormatForField(String field) {
final PostingsFormat in = super.getPostingsFormatForField(field);
return mapper.fieldType().postingsFormat(in);
@ -401,13 +400,13 @@ public class CompletionPostingsFormatTest extends ESTestCase {
}
@Override
public PostingsEnum postings(Bits liveDocs, PostingsEnum reuse, int flags) throws IOException {
public PostingsEnum postings(PostingsEnum reuse, int flags) throws IOException {
final TermPosAndPayload data = current;
return new PostingsEnum() {
boolean done = false;
@Override
public int nextPosition() throws IOException {
return current.pos;
return data.pos;
}
@Override
@ -422,7 +421,7 @@ public class CompletionPostingsFormatTest extends ESTestCase {
@Override
public BytesRef getPayload() throws IOException {
return current.payload;
return data.payload;
}
@Override

@ -21,7 +21,6 @@ package org.elasticsearch.test;
import com.carrotsearch.randomizedtesting.RandomizedContext;
import com.carrotsearch.randomizedtesting.RandomizedTest;
import com.carrotsearch.randomizedtesting.annotations.Listeners;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
@ -92,10 +91,6 @@ import static org.hamcrest.Matchers.equalTo;
LoggingListener.class,
AssertionErrorThreadDumpPrinter.class
})
// remove this entire annotation on upgrade to 5.3!
@ThreadLeakFilters(defaultFilters = true, filters = {
IBMJ9HackThreadFilters.class,
})
@ThreadLeakScope(Scope.SUITE)
@ThreadLeakLingering(linger = 5000) // 5 sec lingering
@TimeoutSuite(millis = 20 * TimeUnits.MINUTE)

@ -20,7 +20,6 @@
package org.elasticsearch.test;
import com.carrotsearch.randomizedtesting.annotations.Listeners;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
@ -35,10 +34,6 @@ import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter;
@Listeners({
ReproduceInfoPrinter.class
})
//remove this entire annotation on upgrade to 5.3!
@ThreadLeakFilters(defaultFilters = true, filters = {
IBMJ9HackThreadFilters.class,
})
@TimeoutSuite(millis = TimeUnits.HOUR)
@LuceneTestCase.SuppressReproduceLine
@LuceneTestCase.SuppressSysoutChecks(bugUrl = "we log a lot on purpose")

@ -1,53 +0,0 @@
package org.elasticsearch.test;
/*
* Licensed to Elasticsearch 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.
*/
import com.carrotsearch.randomizedtesting.ThreadFilter;
import org.apache.lucene.util.Constants;
import org.apache.lucene.util.Version;
/** temporary workaround for https://issues.apache.org/jira/browse/LUCENE-6518
* remove me on upgrade to 5.3! I am just an updated version of QuickPatchThreadFilters from lucene */
public class IBMJ9HackThreadFilters implements ThreadFilter {
static final boolean isJ9;
static {
assert Version.LATEST.equals(Version.LUCENE_5_2_1) : "please remove this entire class for 5.3";
isJ9 = Constants.JAVA_VENDOR.startsWith("IBM");
}
@Override
public boolean reject(Thread t) {
if (isJ9) {
// LUCENE-6518
if ("ClassCache Reaper".equals(t.getName())) {
return true;
}
// LUCENE-4736
StackTraceElement [] stack = t.getStackTrace();
if (stack.length > 0 && stack[stack.length - 1].getClassName().equals("java.util.Timer$TimerImpl")) {
return true;
}
}
return false;
}
}

@ -146,13 +146,13 @@ public class ThrowingLeafReaderWrapper extends FilterLeafReader {
}
@Override
public PostingsEnum postings(Bits liveDocs, PostingsEnum reuse, int flags) throws IOException {
public PostingsEnum postings(PostingsEnum reuse, int flags) throws IOException {
if ((flags & PostingsEnum.POSITIONS) != 0) {
thrower.maybeThrow(Flags.DocsAndPositionsEnum);
} else {
thrower.maybeThrow(Flags.DocsEnum);
}
return super.postings(liveDocs, reuse, flags);
return super.postings(reuse, flags);
}
}

@ -233,13 +233,13 @@ public class SimpleValidateQueryIT extends ESIntegTestCase {
// common terms queries
assertExplanation(QueryBuilders.commonTermsQuery("field", "huge brown pidgin").cutoffFrequency(1),
containsString("(field:huge field:brown) +field:pidgin"), true);
containsString("+field:pidgin (field:huge field:brown)"), true);
assertExplanation(QueryBuilders.commonTermsQuery("field", "the brown").analyzer("stop"),
containsString("field:brown"), true);
// match queries with cutoff frequency
assertExplanation(QueryBuilders.matchQuery("field", "huge brown pidgin").cutoffFrequency(1),
containsString("(field:huge field:brown) +field:pidgin"), true);
containsString("+field:pidgin (field:huge field:brown)"), true);
assertExplanation(QueryBuilders.matchQuery("field", "the brown").analyzer("stop"),
containsString("field:brown"), true);

@ -1 +0,0 @@
33b7cc17d5a7c939af6fe3f67563f4709926d7f5

@ -0,0 +1 @@
1502beac94cf437baff848ffbbb8f76172befa6b

@ -1 +0,0 @@
603d1f06b133449272799d698e5118db65e523ba

@ -0,0 +1 @@
f654901e55fe56bdbe4be202767296929c2f8d9e

@ -1 +0,0 @@
a175590aa8b04e079eb1a136fd159f9163482ba4

@ -0,0 +1 @@
9e12bb7c39e964a544e3a23b9c8ffa9599d38f10

@ -1 +0,0 @@
b966460caa7a91be5969dc5c0053d8de4e861fd6

@ -0,0 +1 @@
dc6f5e352f787d71a7896025c0cdd0eb665b2985

@ -1 +0,0 @@
5682a9820d4f8ef99150b80dcc260919e68ebf39

@ -0,0 +1 @@
2d27582889b8676dfed6880a920148f3e32c9b42

@ -1 +0,0 @@
dd9bba952e362970a1084201fe4858e08f1ceb1f

@ -0,0 +1 @@
3b9d67c0f93e107a9ad8c179505df56a85e3f027

@ -1 +0,0 @@
168e9c9b826faf60489a25645e4322fb8d130574

@ -0,0 +1 @@
95ddffcd889af106136704ecb7dc7173b3e9cdb3

@ -1 +0,0 @@
601f5404c137600488f5b2f2ca635db4ac9fd0cb

Some files were not shown because too many files have changed in this diff Show More