mirror of https://github.com/apache/lucene.git
LUCENE-7391: Fix MemoryIndex fields() perf regression
(cherry picked from commit dcc9a4b
)
This commit is contained in:
parent
3daa82c659
commit
d85a971856
|
@ -54,6 +54,9 @@ Bug Fixes
|
||||||
* LUCENE-7389: Fix FieldType.setDimensions(...) validation for the dimensionNumBytes
|
* LUCENE-7389: Fix FieldType.setDimensions(...) validation for the dimensionNumBytes
|
||||||
parameter. (Martijn van Groningen)
|
parameter. (Martijn van Groningen)
|
||||||
|
|
||||||
|
* LUCENE-7391: Fix performance regression in MemoryIndex's fields() introduced
|
||||||
|
in Lucene 6. (Steve Mason via David Smiley)
|
||||||
|
|
||||||
Improvements
|
Improvements
|
||||||
|
|
||||||
* LUCENE-7323: Compound file writing now verifies the incoming
|
* LUCENE-7323: Compound file writing now verifies the incoming
|
||||||
|
|
|
@ -21,11 +21,9 @@ import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.apache.lucene.analysis.TokenStream;
|
import org.apache.lucene.analysis.TokenStream;
|
||||||
|
@ -1045,6 +1043,7 @@ public class MemoryIndex {
|
||||||
private final class MemoryIndexReader extends LeafReader {
|
private final class MemoryIndexReader extends LeafReader {
|
||||||
|
|
||||||
private final PointValues pointValues;
|
private final PointValues pointValues;
|
||||||
|
private Fields memoryFields = new MemoryFields(fields);
|
||||||
|
|
||||||
private MemoryIndexReader() {
|
private MemoryIndexReader() {
|
||||||
super(); // avoid as much superclass baggage as possible
|
super(); // avoid as much superclass baggage as possible
|
||||||
|
@ -1198,13 +1197,7 @@ public class MemoryIndex {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Fields fields() {
|
public Fields fields() {
|
||||||
Map<String, Info> filteredFields = fields.entrySet().stream()
|
return memoryFields;
|
||||||
.filter(entry -> entry.getValue().numTokens > 0)
|
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,
|
|
||||||
(u,v) -> { throw new IllegalStateException(String.format(Locale.ROOT, "Duplicate key %s", u));},
|
|
||||||
TreeMap::new
|
|
||||||
));
|
|
||||||
return new MemoryFields(filteredFields );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MemoryFields extends Fields {
|
private class MemoryFields extends Fields {
|
||||||
|
@ -1217,13 +1210,16 @@ public class MemoryIndex {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<String> iterator() {
|
public Iterator<String> iterator() {
|
||||||
return fields.keySet().iterator();
|
return fields.entrySet().stream()
|
||||||
|
.filter(e -> e.getValue().numTokens > 0)
|
||||||
|
.map(Map.Entry::getKey)
|
||||||
|
.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Terms terms(final String field) {
|
public Terms terms(final String field) {
|
||||||
final Info info = fields.get(field);
|
final Info info = fields.get(field);
|
||||||
if (info == null) {
|
if (info == null || info.numTokens <= 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1278,7 +1274,11 @@ public class MemoryIndex {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return fields.size();
|
int size = 0;
|
||||||
|
for (String fieldName : this) {
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
return size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ import org.apache.lucene.document.TextField;
|
||||||
import org.apache.lucene.index.BinaryDocValues;
|
import org.apache.lucene.index.BinaryDocValues;
|
||||||
import org.apache.lucene.index.DocValuesType;
|
import org.apache.lucene.index.DocValuesType;
|
||||||
import org.apache.lucene.index.FieldInvertState;
|
import org.apache.lucene.index.FieldInvertState;
|
||||||
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.IndexableField;
|
import org.apache.lucene.index.IndexableField;
|
||||||
import org.apache.lucene.index.LeafReader;
|
import org.apache.lucene.index.LeafReader;
|
||||||
import org.apache.lucene.index.NumericDocValues;
|
import org.apache.lucene.index.NumericDocValues;
|
||||||
|
@ -129,6 +130,19 @@ public class TestMemoryIndex extends LuceneTestCase {
|
||||||
assertEquals("be", terms.term().utf8ToString());
|
assertEquals("be", terms.term().utf8ToString());
|
||||||
TestUtil.checkReader(reader);
|
TestUtil.checkReader(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testFieldsOnlyReturnsIndexedFields() throws IOException {
|
||||||
|
Document doc = new Document();
|
||||||
|
|
||||||
|
doc.add(new NumericDocValuesField("numeric", 29L));
|
||||||
|
doc.add(new TextField("text", "some text", Field.Store.NO));
|
||||||
|
|
||||||
|
MemoryIndex mi = MemoryIndex.fromDocument(doc, analyzer);
|
||||||
|
IndexSearcher searcher = mi.createSearcher();
|
||||||
|
IndexReader reader = searcher.getIndexReader();
|
||||||
|
|
||||||
|
assertEquals(reader.getTermVectors(0).size(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
public void testReaderConsistency() throws IOException {
|
public void testReaderConsistency() throws IOException {
|
||||||
Analyzer analyzer = new MockPayloadAnalyzer();
|
Analyzer analyzer = new MockPayloadAnalyzer();
|
||||||
|
|
Loading…
Reference in New Issue