use of org.elasticsearch.search.suggest.completion.context.GeoQueryContext in project elasticsearch by elastic.
the class ContextCompletionSuggestSearchIT method testGeoBoosting.
public void testGeoBoosting() throws Exception {
LinkedHashMap<String, ContextMapping> map = new LinkedHashMap<>();
map.put("geo", ContextBuilder.geo("geo").build());
final CompletionMappingBuilder mapping = new CompletionMappingBuilder().context(map);
createIndexAndMapping(mapping);
int numDocs = 10;
List<IndexRequestBuilder> indexRequestBuilders = new ArrayList<>();
GeoPoint[] geoPoints = new GeoPoint[] { new GeoPoint("ezs42e44yx96"), new GeoPoint("u4pruydqqvj8") };
for (int i = 0; i < numDocs; i++) {
XContentBuilder source = jsonBuilder().startObject().startObject(FIELD).field("input", "suggestion" + i).field("weight", i + 1).startObject("contexts").field("geo", (i % 2 == 0) ? geoPoints[0].getGeohash() : geoPoints[1].getGeohash()).endObject().endObject().endObject();
indexRequestBuilders.add(client().prepareIndex(INDEX, TYPE, "" + i).setSource(source));
}
indexRandom(true, indexRequestBuilders);
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg");
assertSuggestions("foo", prefix, "suggestion9", "suggestion8", "suggestion7", "suggestion6", "suggestion5");
GeoQueryContext context1 = GeoQueryContext.builder().setGeoPoint(geoPoints[0]).setBoost(2).build();
GeoQueryContext context2 = GeoQueryContext.builder().setGeoPoint(geoPoints[1]).build();
CompletionSuggestionBuilder geoBoostingPrefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg").contexts(Collections.singletonMap("geo", Arrays.asList(context1, context2)));
assertSuggestions("foo", geoBoostingPrefix, "suggestion8", "suggestion6", "suggestion4", "suggestion9", "suggestion7");
}
use of org.elasticsearch.search.suggest.completion.context.GeoQueryContext in project elasticsearch by elastic.
the class GeoQueryContextTests method randomGeoQueryContext.
public static GeoQueryContext randomGeoQueryContext() {
final GeoQueryContext.Builder builder = GeoQueryContext.builder();
builder.setGeoPoint(new GeoPoint(randomDouble(), randomDouble()));
maybeSet(builder::setBoost, randomIntBetween(1, 10));
maybeSet(builder::setPrecision, randomIntBetween(1, 12));
List<Integer> neighbours = new ArrayList<>();
for (int i = 0; i < randomIntBetween(1, 12); i++) {
neighbours.add(randomIntBetween(1, 12));
}
maybeSet(builder::setNeighbours, neighbours);
return builder.build();
}
use of org.elasticsearch.search.suggest.completion.context.GeoQueryContext in project elasticsearch by elastic.
the class GeoQueryContextTests method testNullGeoPointIsIllegal.
public void testNullGeoPointIsIllegal() {
final GeoQueryContext geoQueryContext = randomGeoQueryContext();
final GeoQueryContext.Builder builder = GeoQueryContext.builder().setNeighbours(geoQueryContext.getNeighbours()).setPrecision(geoQueryContext.getPrecision()).setBoost(geoQueryContext.getBoost());
try {
builder.build();
fail("null geo point is illegal");
} catch (NullPointerException e) {
assertThat(e.getMessage(), equalTo("geoPoint must not be null"));
}
}
Aggregations