From 54f325ee1a628a3098c0436a8a74db5c5ddc34f3 Mon Sep 17 00:00:00 2001 From: kimchy Date: Tue, 23 Feb 2010 22:16:12 +0200 Subject: [PATCH] query parser with explicit fields values would not get analyzed --- .../org/elasticsearch/index/mapper/FieldMapper.java | 2 ++ .../index/mapper/json/JsonFieldMapper.java | 4 ++++ .../index/mapper/json/JsonNumberFieldMapper.java | 7 +++++++ .../index/query/support/MapperQueryParser.java | 12 +++++++++--- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java index fb33c458394..067768fc0ae 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java @@ -137,6 +137,8 @@ public interface FieldMapper { */ String indexedValue(T value); + boolean useFieldQueryWithQueryString(); + Query fieldQuery(String value); Filter fieldFilter(String value); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonFieldMapper.java index 1124788f1f1..bd1c7069c49 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonFieldMapper.java @@ -291,6 +291,10 @@ public abstract class JsonFieldMapper implements FieldMapper, JsonMapper { return value.toString(); } + @Override public boolean useFieldQueryWithQueryString() { + return false; + } + @Override public Query fieldQuery(String value) { return new TermQuery(new Term(names.indexName(), indexedValue(value))); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonNumberFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonNumberFieldMapper.java index 985b4a93100..985fb702869 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonNumberFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonNumberFieldMapper.java @@ -99,6 +99,13 @@ public abstract class JsonNumberFieldMapper extends JsonFieldM 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). */ diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/support/MapperQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/support/MapperQueryParser.java index c668c8971ec..a4f044b8ab2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/support/MapperQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/support/MapperQueryParser.java @@ -61,8 +61,14 @@ public class MapperQueryParser extends QueryParser { if (mapperService != null) { MapperService.SmartNameFieldMappers fieldMappers = mapperService.smartName(field); if (fieldMappers != null) { - if (fieldMappers.fieldMappers().mapper() != null) { - Query query = fieldMappers.fieldMappers().mapper().fieldQuery(queryText); + FieldMapper mapper = fieldMappers.fieldMappers().mapper(); + 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); } } @@ -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 {