Upgrade to lucene-7.0.0-snapshot-ad2cb77. (elastic/x-pack-elasticsearch#1820)

Sibling of elastic/elasticsearch#25349.

Original commit: elastic/x-pack-elasticsearch@2ab35a91e5
This commit is contained in:
Adrien Grand 2017-06-22 12:35:51 +02:00 committed by GitHub
parent 2eb939842d
commit bd973aaadb
3 changed files with 32 additions and 29 deletions

View File

@ -267,8 +267,8 @@ public final class FieldSubsetReader extends FilterLeafReader {
}
@Override
public Fields fields() throws IOException {
return new FieldFilterFields(super.fields());
public Terms terms(String field) throws IOException {
return wrapTerms(super.terms(field), field);
}
@Override
@ -344,13 +344,17 @@ public final class FieldSubsetReader extends FilterLeafReader {
@Override
public Terms terms(String field) throws IOException {
return wrapTerms(super.terms(field), field);
}
}
private Terms wrapTerms(Terms terms, String field) {
if (!hasField(field)) {
return null;
} else if (FieldNamesFieldMapper.NAME.equals(field)) {
// for the _field_names field, fields for the document
// are encoded as postings, where term is the field.
// so we hide terms for fields we filter out.
Terms terms = super.terms(field);
if (terms != null) {
// check for null, in case term dictionary is not a ghostbuster
// So just because its in fieldinfos and "indexed=true" doesn't mean you can go grab a Terms for it.
@ -360,8 +364,7 @@ public final class FieldSubsetReader extends FilterLeafReader {
}
return terms;
} else {
return super.terms(field);
}
return terms;
}
}

View File

@ -100,14 +100,14 @@ public class DocumentSubsetReaderTests extends ESTestCase {
new TermQuery(new Term("field", "value1"))));
assertThat(indexSearcher.getIndexReader().numDocs(), equalTo(1));
TopDocs result = indexSearcher.search(new MatchAllDocsQuery(), 1);
assertThat(result.totalHits, equalTo(1));
assertThat(result.totalHits, equalTo(1L));
assertThat(result.scoreDocs[0].doc, equalTo(0));
indexSearcher = new IndexSearcher(DocumentSubsetReader.wrap(directoryReader, bitsetFilterCache,
new TermQuery(new Term("field", "value2"))));
assertThat(indexSearcher.getIndexReader().numDocs(), equalTo(1));
result = indexSearcher.search(new MatchAllDocsQuery(), 1);
assertThat(result.totalHits, equalTo(1));
assertThat(result.totalHits, equalTo(1L));
assertThat(result.scoreDocs[0].doc, equalTo(1));
// this doc has been marked as deleted:
@ -115,13 +115,13 @@ public class DocumentSubsetReaderTests extends ESTestCase {
new TermQuery(new Term("field", "value3"))));
assertThat(indexSearcher.getIndexReader().numDocs(), equalTo(0));
result = indexSearcher.search(new MatchAllDocsQuery(), 1);
assertThat(result.totalHits, equalTo(0));
assertThat(result.totalHits, equalTo(0L));
indexSearcher = new IndexSearcher(DocumentSubsetReader.wrap(directoryReader, bitsetFilterCache,
new TermQuery(new Term("field", "value4"))));
assertThat(indexSearcher.getIndexReader().numDocs(), equalTo(1));
result = indexSearcher.search(new MatchAllDocsQuery(), 1);
assertThat(result.totalHits, equalTo(1));
assertThat(result.totalHits, equalTo(1L));
assertThat(result.scoreDocs[0].doc, equalTo(3));
}

View File

@ -20,6 +20,7 @@ import org.apache.lucene.document.StringField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.FieldInfos;
import org.apache.lucene.index.Fields;
import org.apache.lucene.index.IndexWriter;
@ -87,8 +88,8 @@ public class FieldSubsetReaderTests extends ESTestCase {
// see only one field
LeafReader segmentReader = ir.leaves().get(0).reader();
Set<String> seenFields = new HashSet<>();
for (String field : segmentReader.fields()) {
seenFields.add(field);
for (FieldInfo info : segmentReader.getFieldInfos()) {
seenFields.add(info.name);
}
assertEquals(Collections.singleton("fieldA"), seenFields);
assertNotNull(segmentReader.terms("fieldA"));
@ -937,13 +938,12 @@ public class FieldSubsetReaderTests extends ESTestCase {
// see no fields
LeafReader segmentReader = ir.leaves().get(0).reader();
Fields f = segmentReader.fields();
assertNotNull(f); // 5.x contract
Set<String> seenFields = new HashSet<>();
for (String field : segmentReader.fields()) {
seenFields.add(field);
for (FieldInfo info : segmentReader.getFieldInfos()) {
seenFields.add(info.name);
}
assertEquals(0, seenFields.size());
assertNull(segmentReader.terms("foo"));
// see no vectors
assertNull(segmentReader.getTermVectors(0));