use of org.elasticsearch.search.suggest.completion.context.GeoContextMapping in project elasticsearch by elastic.
the class GeoContextMappingTests method testParsingQueryContextObjectArray.
public void testParsingQueryContextObjectArray() throws Exception {
XContentBuilder builder = jsonBuilder().startArray().startObject().startObject("context").field("lat", 23.654242).field("lon", 90.047153).endObject().field("boost", 10).array("neighbours", 1, 2, 3).endObject().startObject().startObject("context").field("lat", 22.337374).field("lon", 92.112583).endObject().field("boost", 2).array("neighbours", 5).endObject().endArray();
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
GeoContextMapping mapping = ContextBuilder.geo("geo").build();
List<ContextMapping.InternalQueryContext> internalQueryContexts = mapping.parseQueryContext(createParseContext(parser));
assertThat(internalQueryContexts.size(), equalTo(1 + 1 + 8 + 1 + 8 + 1 + 8 + 1 + 1 + 8));
Collection<String> firstLocations = new ArrayList<>();
firstLocations.add("wh0n94");
firstLocations.add("w");
addNeighbors("w", 1, firstLocations);
firstLocations.add("wh");
addNeighbors("wh", 2, firstLocations);
firstLocations.add("wh0");
addNeighbors("wh0", 3, firstLocations);
Collection<String> secondLocations = new ArrayList<>();
secondLocations.add("w5cx04");
secondLocations.add("w5cx0");
addNeighbors("w5cx0", 5, secondLocations);
for (ContextMapping.InternalQueryContext internalQueryContext : internalQueryContexts) {
if (firstLocations.contains(internalQueryContext.context)) {
assertThat(internalQueryContext.boost, equalTo(10));
} else if (secondLocations.contains(internalQueryContext.context)) {
assertThat(internalQueryContext.boost, equalTo(2));
} else {
fail(internalQueryContext.context + " was not expected");
}
assertThat(internalQueryContext.isPrefix, equalTo(internalQueryContext.context.length() < GeoContextMapping.DEFAULT_PRECISION));
}
}
use of org.elasticsearch.search.suggest.completion.context.GeoContextMapping in project elasticsearch by elastic.
the class GeoContextMappingTests method testParsingQueryContextObject.
public void testParsingQueryContextObject() throws Exception {
XContentBuilder builder = jsonBuilder().startObject().startObject("context").field("lat", 23.654242).field("lon", 90.047153).endObject().field("boost", 10).array("neighbours", 1, 2, 3).endObject();
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
GeoContextMapping mapping = ContextBuilder.geo("geo").build();
List<ContextMapping.InternalQueryContext> internalQueryContexts = mapping.parseQueryContext(createParseContext(parser));
assertThat(internalQueryContexts.size(), equalTo(1 + 1 + 8 + 1 + 8 + 1 + 8));
Collection<String> locations = new ArrayList<>();
locations.add("wh0n94");
locations.add("w");
addNeighbors("w", 1, locations);
locations.add("wh");
addNeighbors("wh", 2, locations);
locations.add("wh0");
addNeighbors("wh0", 3, locations);
for (ContextMapping.InternalQueryContext internalQueryContext : internalQueryContexts) {
assertThat(internalQueryContext.context, isIn(locations));
assertThat(internalQueryContext.boost, equalTo(10));
assertThat(internalQueryContext.isPrefix, equalTo(internalQueryContext.context.length() < GeoContextMapping.DEFAULT_PRECISION));
}
}
Aggregations