optimize term creation (reduce interning)
This commit is contained in:
parent
7cccacbcfa
commit
c05df433c6
|
@ -67,6 +67,8 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
|||
|
||||
public static final String DEFAULT_MAPPING = "_default_";
|
||||
|
||||
private final AnalysisService analysisService;
|
||||
|
||||
/**
|
||||
* Will create types automatically if they do not exists in the mapping definition yet
|
||||
*/
|
||||
|
@ -91,6 +93,7 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
|||
|
||||
@Inject public MapperService(Index index, @IndexSettings Settings indexSettings, Environment environment, AnalysisService analysisService) {
|
||||
super(index, indexSettings);
|
||||
this.analysisService = analysisService;
|
||||
this.documentParser = new XContentDocumentMapperParser(index, indexSettings, analysisService);
|
||||
this.searchAnalyzer = new SmartIndexNameSearchAnalyzer(analysisService.defaultSearchAnalyzer());
|
||||
|
||||
|
@ -136,6 +139,10 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
|||
return mappers.values().iterator();
|
||||
}
|
||||
|
||||
public AnalysisService analysisService() {
|
||||
return this.analysisService;
|
||||
}
|
||||
|
||||
public DocumentMapperParser documentMapperParser() {
|
||||
return this.documentParser;
|
||||
}
|
||||
|
@ -278,7 +285,7 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
|||
if (useTermsFilter) {
|
||||
PublicTermsFilter termsFilter = new PublicTermsFilter();
|
||||
for (String type : types) {
|
||||
termsFilter.addTerm(new Term(TypeFieldMapper.NAME, type));
|
||||
termsFilter.addTerm(TypeFieldMapper.TERM_FACTORY.createTerm(type));
|
||||
}
|
||||
return termsFilter;
|
||||
} else {
|
||||
|
@ -286,7 +293,7 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
|||
for (String type : types) {
|
||||
DocumentMapper docMapper = documentMapper(type);
|
||||
if (docMapper == null) {
|
||||
bool.add(new FilterClause(new TermFilter(new Term(TypeFieldMapper.NAME, type)), BooleanClause.Occur.SHOULD));
|
||||
bool.add(new FilterClause(new TermFilter(TypeFieldMapper.TERM_FACTORY.createTerm(type)), BooleanClause.Occur.SHOULD));
|
||||
} else {
|
||||
bool.add(new FilterClause(docMapper.typeFilter(), BooleanClause.Occur.SHOULD));
|
||||
}
|
||||
|
@ -311,7 +318,7 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
|||
if (!hasMapping(type)) {
|
||||
throw new TypeMissingException(index, type);
|
||||
}
|
||||
termsFilter.addTerm(new Term(TypeFieldMapper.NAME, type));
|
||||
termsFilter.addTerm(TypeFieldMapper.TERM_FACTORY.createTerm(type));
|
||||
}
|
||||
return termsFilter;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ public interface TypeFieldMapper extends FieldMapper<String>, InternalMapper {
|
|||
|
||||
public static final String NAME = "_type";
|
||||
|
||||
public static final Term TERM_FACTORY = new Term(NAME, "");
|
||||
|
||||
String value(Document document);
|
||||
|
||||
Term term(String value);
|
||||
|
|
|
@ -30,6 +30,8 @@ public interface UidFieldMapper extends FieldMapper<Uid>, InternalMapper {
|
|||
|
||||
public static final String NAME = "_uid";
|
||||
|
||||
public static final Term TERM_FACTORY = new Term(NAME, "");
|
||||
|
||||
Term term(String type, String id);
|
||||
|
||||
Term term(String uid);
|
||||
|
|
|
@ -205,6 +205,8 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, XContent
|
|||
|
||||
protected final NamedAnalyzer searchAnalyzer;
|
||||
|
||||
protected final Term termFactory;
|
||||
|
||||
protected AbstractFieldMapper(Names names, Field.Index index, Field.Store store, Field.TermVector termVector,
|
||||
float boost, boolean omitNorms, boolean omitTermFreqAndPositions, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) {
|
||||
this.names = names;
|
||||
|
@ -224,6 +226,8 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, XContent
|
|||
} else {
|
||||
this.searchAnalyzer = searchAnalyzer;
|
||||
}
|
||||
|
||||
this.termFactory = new Term(names.indexName(), "");
|
||||
}
|
||||
|
||||
@Override public String name() {
|
||||
|
@ -318,19 +322,19 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, XContent
|
|||
}
|
||||
|
||||
@Override public Query fieldQuery(String value, QueryParseContext context) {
|
||||
return new TermQuery(new Term(names.indexName(), indexedValue(value)));
|
||||
return new TermQuery(termFactory.createTerm(indexedValue(value)));
|
||||
}
|
||||
|
||||
@Override public Query fuzzyQuery(String value, String minSim, int prefixLength, int maxExpansions) {
|
||||
return new FuzzyQuery(new Term(names.indexName(), value), Float.parseFloat(minSim), prefixLength, maxExpansions);
|
||||
return new FuzzyQuery(termFactory.createTerm(indexedValue(value)), Float.parseFloat(minSim), prefixLength, maxExpansions);
|
||||
}
|
||||
|
||||
@Override public Query fuzzyQuery(String value, double minSim, int prefixLength, int maxExpansions) {
|
||||
return new FuzzyQuery(new Term(names.indexName(), value), (float) minSim, prefixLength, maxExpansions);
|
||||
return new FuzzyQuery(termFactory.createTerm(value), (float) minSim, prefixLength, maxExpansions);
|
||||
}
|
||||
|
||||
@Override public Filter fieldFilter(String value) {
|
||||
return new TermFilter(new Term(names.indexName(), indexedValue(value)));
|
||||
return new TermFilter(termFactory.createTerm(indexedValue(value)));
|
||||
}
|
||||
|
||||
@Override public Query rangeQuery(String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {
|
||||
|
|
|
@ -108,7 +108,7 @@ public class AllFieldMapper extends AbstractFieldMapper<Void> implements org.ela
|
|||
}
|
||||
|
||||
@Override public Query fieldQuery(String value, QueryParseContext context) {
|
||||
return new AllTermQuery(new Term(names.indexName(), value));
|
||||
return new AllTermQuery(termFactory.createTerm(value));
|
||||
}
|
||||
|
||||
@Override protected Fieldable parseCreateField(ParseContext context) throws IOException {
|
||||
|
|
|
@ -113,7 +113,7 @@ public class IndexFieldMapper extends AbstractFieldMapper<String> implements org
|
|||
}
|
||||
|
||||
@Override public Term term(String value) {
|
||||
return new Term(names.indexName(), value);
|
||||
return termFactory.createTerm(value);
|
||||
}
|
||||
|
||||
@Override protected Field parseCreateField(ParseContext context) throws IOException {
|
||||
|
|
|
@ -140,7 +140,7 @@ public class ParentFieldMapper extends AbstractFieldMapper<Uid> implements org.e
|
|||
}
|
||||
|
||||
@Override public Term term(String uid) {
|
||||
return new Term(names.indexName(), uid);
|
||||
return termFactory.createTerm(uid);
|
||||
}
|
||||
|
||||
@Override protected String contentType() {
|
||||
|
|
|
@ -106,14 +106,14 @@ public class TypeFieldMapper extends AbstractFieldMapper<String> implements org.
|
|||
}
|
||||
|
||||
@Override public Term term(String value) {
|
||||
return new Term(names.indexName(), value);
|
||||
return termFactory.createTerm(value);
|
||||
}
|
||||
|
||||
@Override public Filter fieldFilter(String value) {
|
||||
if (index == Field.Index.NO) {
|
||||
return new PrefixFilter(new Term(UidFieldMapper.NAME, Uid.typePrefix(value)));
|
||||
return new PrefixFilter(UidFieldMapper.TERM_FACTORY.createTerm(Uid.typePrefix(value)));
|
||||
}
|
||||
return new TermFilter(new Term(names.indexName(), value));
|
||||
return new TermFilter(termFactory.createTerm(value));
|
||||
}
|
||||
|
||||
@Override public Query fieldQuery(String value, QueryParseContext context) {
|
||||
|
|
|
@ -112,7 +112,7 @@ public class UidFieldMapper extends AbstractFieldMapper<Uid> implements org.elas
|
|||
}
|
||||
|
||||
@Override public Term term(String uid) {
|
||||
return new Term(names.indexName(), uid);
|
||||
return termFactory.createTerm(uid);
|
||||
}
|
||||
|
||||
@Override public void close() {
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.elasticsearch.index.mapper.xcontent.ip;
|
|||
import org.apache.lucene.analysis.NumericTokenStream;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.*;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||
|
@ -179,7 +178,7 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
|
|||
}
|
||||
|
||||
@Override public Query fuzzyQuery(String value, double minSim, int prefixLength, int maxExpansions) {
|
||||
return new FuzzyQuery(new Term(names.indexName(), value), (float) minSim, prefixLength, maxExpansions);
|
||||
return new FuzzyQuery(termFactory.createTerm(value), (float) minSim, prefixLength, maxExpansions);
|
||||
}
|
||||
|
||||
@Override public Query rangeQuery(String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.search.fetch.version;
|
||||
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.elasticsearch.ElasticSearchException;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.lucene.uid.UidField;
|
||||
|
@ -47,7 +46,7 @@ public class VersionSearchHitPhase implements SearchHitPhase {
|
|||
// it might make sense to cache the TermDocs on a shared fetch context and just skip here)
|
||||
// it is going to mean we work on the high level multi reader and not the lower level reader as is
|
||||
// the case below...
|
||||
long version = UidField.loadVersion(hitContext.reader(), new Term(UidFieldMapper.NAME, hitContext.doc().get(UidFieldMapper.NAME)));
|
||||
long version = UidField.loadVersion(hitContext.reader(), UidFieldMapper.TERM_FACTORY.createTerm(hitContext.doc().get(UidFieldMapper.NAME)));
|
||||
if (version < 0) {
|
||||
version = -1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue