summaryrefslogtreecommitdiff
path: root/core/src/main/java/org/elasticsearch/search
diff options
context:
space:
mode:
authorChristoph Büscher <christoph@elastic.co>2016-04-15 18:18:15 +0200
committerChristoph Büscher <christoph@elastic.co>2016-04-15 20:51:05 +0200
commitf7e79f4981ddeb1d14e0aaa0417b3ed378d8e298 (patch)
treeb163207861ca3360ae8ae8dddba4f7c728fd3a52 /core/src/main/java/org/elasticsearch/search
parent4e77adf38e3bdec774cffee351e3c31f8b9cf25a (diff)
Pass down parse context instead of just parser in completion context suggester.
Diffstat (limited to 'core/src/main/java/org/elasticsearch/search')
-rw-r--r--core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java5
-rw-r--r--core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java5
-rw-r--r--core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java4
-rw-r--r--core/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMapping.java10
-rw-r--r--core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoContextMapping.java5
-rw-r--r--core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoQueryContext.java7
6 files changed, 21 insertions, 15 deletions
diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java
index 4afad501cb..ce75351dfb 100644
--- a/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java
@@ -20,7 +20,6 @@ package org.elasticsearch.search.suggest.completion;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseField;
-import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.ParseFieldMatcherSupplier;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.StreamInput;
@@ -265,7 +264,7 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSug
static CompletionSuggestionBuilder innerFromXContent(QueryParseContext parseContext) throws IOException {
CompletionSuggestionBuilder.InnerBuilder builder = new CompletionSuggestionBuilder.InnerBuilder();
- TLP_PARSER.parse(parseContext.parser(), builder, () -> ParseFieldMatcher.STRICT);
+ TLP_PARSER.parse(parseContext.parser(), builder, parseContext);
String field = builder.field;
// now we should have field name, check and copy fields over to the suggestion builder we return
if (field == null) {
@@ -301,7 +300,7 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSug
if (currentToken == XContentParser.Token.FIELD_NAME) {
currentFieldName = contextParser.currentName();
final ContextMapping mapping = contextMappings.get(currentFieldName);
- queryContexts.put(currentFieldName, mapping.parseQueryContext(contextParser));
+ queryContexts.put(currentFieldName, mapping.parseQueryContext(context.newParseContext(contextParser)));
}
}
suggestionContext.setQueryContexts(queryContexts);
diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java
index 1931c4a9e0..150b7bf4f9 100644
--- a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java
+++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java
@@ -27,6 +27,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParser.Token;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.ParseContext.Document;
+import org.elasticsearch.index.query.QueryParseContext;
import java.io.IOException;
import java.util.ArrayList;
@@ -139,8 +140,8 @@ public class CategoryContextMapping extends ContextMapping<CategoryQueryContext>
}
@Override
- protected CategoryQueryContext fromXContent(XContentParser parser) throws IOException {
- return CategoryQueryContext.fromXContent(parser);
+ protected CategoryQueryContext fromXContent(QueryParseContext context) throws IOException {
+ return CategoryQueryContext.fromXContent(context);
}
/**
diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java
index 1384868f0d..a17b7a87b4 100644
--- a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java
+++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java
@@ -27,6 +27,7 @@ import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.index.query.QueryParseContext;
import java.io.IOException;
import java.util.Objects;
@@ -104,7 +105,8 @@ public final class CategoryQueryContext implements ToXContent {
CATEGORY_PARSER.declareBoolean(Builder::setPrefix, new ParseField(CONTEXT_PREFIX));
}
- public static CategoryQueryContext fromXContent(XContentParser parser) throws IOException {
+ public static CategoryQueryContext fromXContent(QueryParseContext context) throws IOException {
+ XContentParser parser = context.parser();
XContentParser.Token token = parser.currentToken();
Builder builder = builder();
if (token == XContentParser.Token.START_OBJECT) {
diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMapping.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMapping.java
index cb445b1770..305a3b1afd 100644
--- a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMapping.java
+++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMapping.java
@@ -27,6 +27,7 @@ import org.elasticsearch.common.xcontent.XContentParser.Token;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.core.CompletionFieldMapper;
+import org.elasticsearch.index.query.QueryParseContext;
import java.io.IOException;
import java.util.ArrayList;
@@ -99,19 +100,20 @@ public abstract class ContextMapping<T extends ToXContent> implements ToXContent
/**
* Prototype for the query context
*/
- protected abstract T fromXContent(XContentParser parser) throws IOException;
+ protected abstract T fromXContent(QueryParseContext context) throws IOException;
/**
* Parses query contexts for this mapper
*/
- public final List<InternalQueryContext> parseQueryContext(XContentParser parser) throws IOException, ElasticsearchParseException {
+ public final List<InternalQueryContext> parseQueryContext(QueryParseContext context) throws IOException, ElasticsearchParseException {
List<T> queryContexts = new ArrayList<>();
+ XContentParser parser = context.parser();
Token token = parser.nextToken();
if (token == Token.START_OBJECT || token == Token.VALUE_STRING) {
- queryContexts.add(fromXContent(parser));
+ queryContexts.add(fromXContent(context));
} else if (token == Token.START_ARRAY) {
while (parser.nextToken() != Token.END_ARRAY) {
- queryContexts.add(fromXContent(parser));
+ queryContexts.add(fromXContent(context));
}
}
return toInternalQueryContexts(queryContexts);
diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoContextMapping.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoContextMapping.java
index 83345be24b..a9aa9d340c 100644
--- a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoContextMapping.java
+++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoContextMapping.java
@@ -33,6 +33,7 @@ import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper;
+import org.elasticsearch.index.query.QueryParseContext;
import java.io.IOException;
import java.util.ArrayList;
@@ -223,8 +224,8 @@ public class GeoContextMapping extends ContextMapping<GeoQueryContext> {
}
@Override
- protected GeoQueryContext fromXContent(XContentParser parser) throws IOException {
- return GeoQueryContext.fromXContent(parser);
+ protected GeoQueryContext fromXContent(QueryParseContext context) throws IOException {
+ return GeoQueryContext.fromXContent(context);
}
/**
diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoQueryContext.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoQueryContext.java
index dd625f252d..6ed8754c97 100644
--- a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoQueryContext.java
+++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoQueryContext.java
@@ -21,7 +21,6 @@ package org.elasticsearch.search.suggest.completion.context;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseField;
-import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.ParseFieldMatcherSupplier;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.geo.GeoUtils;
@@ -29,6 +28,7 @@ import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.index.query.QueryParseContext;
import java.io.IOException;
import java.util.Collections;
@@ -125,11 +125,12 @@ public final class GeoQueryContext implements ToXContent {
GEO_CONTEXT_PARSER.declareDouble(GeoQueryContext.Builder::setLon, new ParseField("lon"));
}
- public static GeoQueryContext fromXContent(XContentParser parser) throws IOException {
+ public static GeoQueryContext fromXContent(QueryParseContext context) throws IOException {
+ XContentParser parser = context.parser();
XContentParser.Token token = parser.currentToken();
GeoQueryContext.Builder builder = new Builder();
if (token == XContentParser.Token.START_OBJECT) {
- GEO_CONTEXT_PARSER.parse(parser, builder, () -> ParseFieldMatcher.STRICT);
+ GEO_CONTEXT_PARSER.parse(parser, builder, context);
} else if (token == XContentParser.Token.VALUE_STRING) {
builder.setGeoPoint(GeoPoint.fromGeohash(parser.text()));
} else {