Suggest API - bugs with encoding multiple levels of geo precision.
1) One issue reported by a user is due to the truncation of the geohash string. Added Junit test for this scenario 2) Another suspect piece of code was the “toAutomaton” method that only merged the first of possibly many precisions into the result. Closes #7368
This commit is contained in:
parent
8e1d3d56b3
commit
c0aef4adc4
|
@ -651,11 +651,11 @@ public class GeolocationContextMapping extends ContextMapping {
|
|||
for (String geohash : geohashes) {
|
||||
for (int p : mapping.precision) {
|
||||
int precision = Math.min(p, geohash.length());
|
||||
geohash = geohash.substring(0, precision);
|
||||
String truncatedGeohash = geohash.substring(0, precision);
|
||||
if(mapping.neighbors) {
|
||||
GeoHashUtils.addNeighbors(geohash, precision, locations);
|
||||
GeoHashUtils.addNeighbors(truncatedGeohash, precision, locations);
|
||||
}
|
||||
locations.add(geohash);
|
||||
locations.add(truncatedGeohash);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -693,7 +693,7 @@ public class GeolocationContextMapping extends ContextMapping {
|
|||
} else {
|
||||
automaton = BasicAutomata.makeString(location.substring(0, Math.max(1, Math.min(location.length(), precisions[0]))));
|
||||
for (int i = 1; i < precisions.length; i++) {
|
||||
final String cell = location.substring(0, Math.max(1, Math.min(location.length(), precisions[0])));
|
||||
final String cell = location.substring(0, Math.max(1, Math.min(location.length(), precisions[i])));
|
||||
automaton = BasicOperations.union(automaton, BasicAutomata.makeString(cell));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,6 +111,49 @@ public class ContextSuggestSearchTests extends ElasticsearchIntegrationTest {
|
|||
assertEquals(suggestResponse.getSuggest().size(), 1);
|
||||
assertEquals("Hotel Amsterdam in Berlin", suggestResponse.getSuggest().getSuggestion(suggestionName).iterator().next().getOptions().iterator().next().getText().string());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiLevelGeo() throws Exception {
|
||||
assertAcked(prepareCreate(INDEX).addMapping(TYPE, createMapping(TYPE, ContextBuilder.location("st")
|
||||
.precision(1)
|
||||
.precision(2)
|
||||
.precision(3)
|
||||
.precision(4)
|
||||
.precision(5)
|
||||
.precision(6)
|
||||
.precision(7)
|
||||
.precision(8)
|
||||
.precision(9)
|
||||
.precision(10)
|
||||
.precision(11)
|
||||
.precision(12)
|
||||
.neighbors(true))));
|
||||
ensureYellow();
|
||||
|
||||
XContentBuilder source1 = jsonBuilder()
|
||||
.startObject()
|
||||
.startObject(FIELD)
|
||||
.array("input", "Hotel Amsterdam", "Amsterdam")
|
||||
.field("output", "Hotel Amsterdam in Berlin")
|
||||
.startObject("context").latlon("st", 52.529172, 13.407333).endObject()
|
||||
.endObject()
|
||||
.endObject();
|
||||
client().prepareIndex(INDEX, TYPE, "1").setSource(source1).execute().actionGet();
|
||||
|
||||
client().admin().indices().prepareRefresh(INDEX).get();
|
||||
|
||||
for (int precision = 1; precision <= 12; precision++) {
|
||||
String suggestionName = randomAsciiOfLength(10);
|
||||
CompletionSuggestionBuilder context = new CompletionSuggestionBuilder(suggestionName).field(FIELD).text("h").size(10)
|
||||
.addGeoLocation("st", 52.529172, 13.407333, precision);
|
||||
|
||||
SuggestRequestBuilder suggestionRequest = client().prepareSuggest(INDEX).addSuggestion(context);
|
||||
SuggestResponse suggestResponse = suggestionRequest.execute().actionGet();
|
||||
assertEquals(suggestResponse.getSuggest().size(), 1);
|
||||
assertEquals("Hotel Amsterdam in Berlin", suggestResponse.getSuggest().getSuggestion(suggestionName).iterator().next()
|
||||
.getOptions().iterator().next().getText().string());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeoField() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue