query parser with explicit fields values would not get analyzed

This commit is contained in:
kimchy 2010-02-23 22:16:12 +02:00
parent 07d4166715
commit 54f325ee1a
4 changed files with 22 additions and 3 deletions

View File

@ -137,6 +137,8 @@ public interface FieldMapper<T> {
*/ */
String indexedValue(T value); String indexedValue(T value);
boolean useFieldQueryWithQueryString();
Query fieldQuery(String value); Query fieldQuery(String value);
Filter fieldFilter(String value); Filter fieldFilter(String value);

View File

@ -291,6 +291,10 @@ public abstract class JsonFieldMapper<T> implements FieldMapper<T>, JsonMapper {
return value.toString(); return value.toString();
} }
@Override public boolean useFieldQueryWithQueryString() {
return false;
}
@Override public Query fieldQuery(String value) { @Override public Query fieldQuery(String value) {
return new TermQuery(new Term(names.indexName(), indexedValue(value))); return new TermQuery(new Term(names.indexName(), indexedValue(value)));
} }

View File

@ -99,6 +99,13 @@ public abstract class JsonNumberFieldMapper<T extends Number> extends JsonFieldM
return this.precisionStep; return this.precisionStep;
} }
/**
* Use the field query created here when matching on numbers.
*/
@Override public boolean useFieldQueryWithQueryString() {
return true;
}
/** /**
* Override the default behavior (to return the string, and return the actual Number instance). * Override the default behavior (to return the string, and return the actual Number instance).
*/ */

View File

@ -61,8 +61,14 @@ public class MapperQueryParser extends QueryParser {
if (mapperService != null) { if (mapperService != null) {
MapperService.SmartNameFieldMappers fieldMappers = mapperService.smartName(field); MapperService.SmartNameFieldMappers fieldMappers = mapperService.smartName(field);
if (fieldMappers != null) { if (fieldMappers != null) {
if (fieldMappers.fieldMappers().mapper() != null) { FieldMapper mapper = fieldMappers.fieldMappers().mapper();
Query query = fieldMappers.fieldMappers().mapper().fieldQuery(queryText); if (mapper != null) {
Query query;
if (mapper.useFieldQueryWithQueryString()) {
query = fieldMappers.fieldMappers().mapper().fieldQuery(queryText);
} else {
query = super.getFieldQuery(mapper.names().indexName(), queryText);
}
return wrapSmartNameQuery(query, fieldMappers, filterCache); return wrapSmartNameQuery(query, fieldMappers, filterCache);
} }
} }
@ -80,7 +86,7 @@ public class MapperQueryParser extends QueryParser {
} }
} }
} }
return super.getRangeQuery(field, part1, part2, inclusive); return newRangeQuery(field, part1, part2, inclusive);
} }
@Override protected Query getPrefixQuery(String field, String termStr) throws ParseException { @Override protected Query getPrefixQuery(String field, String termStr) throws ParseException {