optimize query parsing to use single field parser when executing on single field

This commit is contained in:
kimchy 2011-01-03 15:14:28 +02:00
parent 2c8c6aa22a
commit ff6d7254fe
3 changed files with 6 additions and 6 deletions

View File

@ -131,7 +131,7 @@ public class FieldQueryParser extends AbstractIndexComponent implements XContent
return query; return query;
} }
MapperQueryParser queryParser = parseContext.queryParser(qpSettings); MapperQueryParser queryParser = parseContext.singleQueryParser(qpSettings);
try { try {
query = queryParser.parse(qpSettings.queryString()); query = queryParser.parse(qpSettings.queryString());

View File

@ -104,12 +104,12 @@ public class QueryParseContext {
return indexQueryParser.indexCache; return indexQueryParser.indexCache;
} }
public MapperQueryParser queryParser(QueryParserSettings settings) { public MapperQueryParser singleQueryParser(QueryParserSettings settings) {
queryParser.reset(settings); queryParser.reset(settings);
return queryParser; return queryParser;
} }
public MultiFieldMapperQueryParser queryParser(MultiFieldQueryParserSettings settings) { public MultiFieldMapperQueryParser multiQueryParser(MultiFieldQueryParserSettings settings) {
multiFieldQueryParser.reset(settings); multiFieldQueryParser.reset(settings);
return multiFieldQueryParser; return multiFieldQueryParser;
} }

View File

@ -177,13 +177,13 @@ public class QueryStringQueryParser extends AbstractIndexComponent implements XC
if (qpSettings.fields() != null) { if (qpSettings.fields() != null) {
if (qpSettings.fields().size() == 1) { if (qpSettings.fields().size() == 1) {
qpSettings.defaultField(qpSettings.fields().get(0)); qpSettings.defaultField(qpSettings.fields().get(0));
queryParser = parseContext.queryParser(qpSettings); queryParser = parseContext.singleQueryParser(qpSettings);
} else { } else {
qpSettings.defaultField(null); // reset defaultField when using multi query parser qpSettings.defaultField(null); // reset defaultField when using multi query parser
queryParser = parseContext.queryParser(qpSettings); queryParser = parseContext.multiQueryParser(qpSettings);
} }
} else { } else {
queryParser = parseContext.queryParser(qpSettings); queryParser = parseContext.singleQueryParser(qpSettings);
} }