more small optimizations to term creation

This commit is contained in:
Shay Banon 2011-09-26 12:05:48 +03:00
parent 8658856b48
commit e33dbcd93e
14 changed files with 35 additions and 27 deletions

View File

@ -47,6 +47,8 @@ public interface FieldMapper<T> {
private final String fullName;
private final Term indexNameTermFactory;
public Names(String name) {
this(name, name, name, name);
}
@ -56,6 +58,7 @@ public interface FieldMapper<T> {
this.indexName = indexName.intern();
this.indexNameClean = indexNameClean.intern();
this.fullName = fullName.intern();
this.indexNameTermFactory = new Term(indexName, "");
}
/**
@ -86,6 +89,10 @@ public interface FieldMapper<T> {
public String fullName() {
return fullName;
}
public Term createIndexNameTerm(String value) {
return indexNameTermFactory.createTerm(value);
}
}
Names names();

View File

@ -216,8 +216,6 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
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;
@ -238,8 +236,6 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
} else {
this.searchAnalyzer = searchAnalyzer;
}
this.termFactory = new Term(names.indexName(), "");
}
@Override public String name() {
@ -347,19 +343,19 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
}
@Override public Query fieldQuery(String value, QueryParseContext context) {
return new TermQuery(termFactory.createTerm(indexedValue(value)));
return new TermQuery(names().createIndexNameTerm(indexedValue(value)));
}
@Override public Query fuzzyQuery(String value, String minSim, int prefixLength, int maxExpansions) {
return new FuzzyQuery(termFactory.createTerm(indexedValue(value)), Float.parseFloat(minSim), prefixLength, maxExpansions);
return new FuzzyQuery(names().createIndexNameTerm(indexedValue(value)), Float.parseFloat(minSim), prefixLength, maxExpansions);
}
@Override public Query fuzzyQuery(String value, double minSim, int prefixLength, int maxExpansions) {
return new FuzzyQuery(termFactory.createTerm(value), (float) minSim, prefixLength, maxExpansions);
return new FuzzyQuery(names().createIndexNameTerm(value), (float) minSim, prefixLength, maxExpansions);
}
@Override public Filter fieldFilter(String value) {
return new TermFilter(termFactory.createTerm(indexedValue(value)));
return new TermFilter(names().createIndexNameTerm(indexedValue(value)));
}
@Override public Query rangeQuery(String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {

View File

@ -144,7 +144,7 @@ public class AllFieldMapper extends AbstractFieldMapper<Void> implements Interna
}
@Override public Query fieldQuery(String value, QueryParseContext context) {
return new AllTermQuery(termFactory.createTerm(value));
return new AllTermQuery(names().createIndexNameTerm(value));
}
@Override public void preParse(ParseContext context) throws IOException {

View File

@ -144,7 +144,7 @@ public class IndexFieldMapper extends AbstractFieldMapper<String> implements Int
}
public Term term(String value) {
return termFactory.createTerm(value);
return names().createIndexNameTerm(value);
}
@Override public void preParse(ParseContext context) throws IOException {

View File

@ -179,7 +179,7 @@ public class ParentFieldMapper extends AbstractFieldMapper<Uid> implements Inter
}
public Term term(String uid) {
return termFactory.createTerm(uid);
return names().createIndexNameTerm(uid);
}
@Override protected String contentType() {

View File

@ -129,14 +129,14 @@ public class TypeFieldMapper extends AbstractFieldMapper<String> implements Inte
}
public Term term(String value) {
return termFactory.createTerm(value);
return names().createIndexNameTerm(value);
}
@Override public Filter fieldFilter(String value) {
if (index == Field.Index.NO) {
return new PrefixFilter(UidFieldMapper.TERM_FACTORY.createTerm(Uid.typePrefix(value)));
}
return new TermFilter(termFactory.createTerm(value));
return new TermFilter(names().createIndexNameTerm(value));
}
@Override public Query fieldQuery(String value, QueryParseContext context) {

View File

@ -169,7 +169,7 @@ public class UidFieldMapper extends AbstractFieldMapper<Uid> implements Internal
}
public Term term(String uid) {
return termFactory.createTerm(uid);
return names().createIndexNameTerm(uid);
}
@Override public void close() {

View File

@ -195,7 +195,7 @@ public class IpFieldMapper extends NumberFieldMapper<Long> {
}
@Override public Query fuzzyQuery(String value, double minSim, int prefixLength, int maxExpansions) {
return new FuzzyQuery(termFactory.createTerm(value), (float) minSim, prefixLength, maxExpansions);
return new FuzzyQuery(names().createIndexNameTerm(value), (float) minSim, prefixLength, maxExpansions);
}
@Override public Query rangeQuery(String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {

View File

@ -21,7 +21,6 @@ package org.elasticsearch.index.percolator;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.DeletionAwareConstantScoreQuery;
import org.apache.lucene.search.Filter;
@ -138,7 +137,7 @@ public class PercolatorService extends AbstractIndexComponent {
}
private Filter indexQueriesFilter(String indexName) {
return percolatorIndexService().cache().filter().cache(new TermFilter(new Term(TypeFieldMapper.NAME, indexName)));
return percolatorIndexService().cache().filter().cache(new TermFilter(TypeFieldMapper.TERM_FACTORY.createTerm(indexName)));
}
private boolean percolatorAllocated() {

View File

@ -77,15 +77,18 @@ public class PrefixFilterParser implements FilterParser {
throw new QueryParsingException(parseContext.index(), "No value specified for prefix filter");
}
Filter filter = null;
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
if (smartNameFieldMappers != null) {
if (smartNameFieldMappers.hasMapper()) {
fieldName = smartNameFieldMappers.mapper().names().indexName();
value = smartNameFieldMappers.mapper().indexedValue(value);
filter = new PrefixFilter(smartNameFieldMappers.mapper().names().createIndexNameTerm(value));
}
}
Filter filter = new PrefixFilter(new Term(fieldName, value));
if (filter == null) {
filter = new PrefixFilter(new Term(fieldName, value));
}
if (cache) {
filter = parseContext.cacheFilter(filter, cacheKey);

View File

@ -83,15 +83,17 @@ public class PrefixQueryParser implements QueryParser {
throw new QueryParsingException(parseContext.index(), "No value specified for prefix query");
}
PrefixQuery query = null;
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
if (smartNameFieldMappers != null) {
if (smartNameFieldMappers.hasMapper()) {
fieldName = smartNameFieldMappers.mapper().names().indexName();
value = smartNameFieldMappers.mapper().indexedValue(value);
query = new PrefixQuery(smartNameFieldMappers.mapper().names().createIndexNameTerm(value));
}
}
PrefixQuery query = new PrefixQuery(new Term(fieldName, value));
if (query == null) {
query = new PrefixQuery(new Term(fieldName, value));
}
query.setRewriteMethod(QueryParsers.parseRewriteMethod(rewriteMethod));
query.setBoost(boost);
return wrapSmartNameQuery(query, smartNameFieldMappers, parseContext);

View File

@ -77,8 +77,10 @@ public class TermsFilterParser implements FilterParser {
}
if (fieldMapper != null) {
value = fieldMapper.indexedValue(value);
termsFilter.addTerm(fieldMapper.names().createIndexNameTerm(value));
} else {
termsFilter.addTerm(new Term(fieldName, value));
}
termsFilter.addTerm(new Term(fieldName, value));
}
} else if (token.isValue()) {
if ("_name".equals(currentFieldName)) {

View File

@ -19,7 +19,6 @@
package org.elasticsearch.index.query;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Filter;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.search.TermFilter;
@ -62,7 +61,7 @@ public class TypeFilterParser implements FilterParser {
Filter filter;
DocumentMapper documentMapper = parseContext.mapperService().documentMapper(type);
if (documentMapper == null) {
filter = new TermFilter(new Term(TypeFieldMapper.NAME, type));
filter = new TermFilter(TypeFieldMapper.TERM_FACTORY.createTerm(type));
} else {
filter = documentMapper.typeFilter();
}

View File

@ -48,7 +48,7 @@ public class UidFilter extends Filter {
this.uids = new ArrayList<Term>(types.size() * ids.size());
for (String type : types) {
for (String id : ids) {
uids.add(new Term(UidFieldMapper.NAME, Uid.createUid(type, id)));
uids.add(UidFieldMapper.TERM_FACTORY.createTerm(Uid.createUid(type, id)));
}
}
}