Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs with encoding multiple levels of geo precision #7369

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -650,11 +650,11 @@ protected TokenStream wrapTokenStream(Document doc, TokenStream stream) {
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);
}
}

Expand Down Expand Up @@ -692,7 +692,7 @@ public Automaton toAutomaton() {
} 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));
}
}
Expand Down
Expand Up @@ -27,9 +27,8 @@
import org.elasticsearch.common.geo.GeoHashUtils;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.common.xcontent.*;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
import org.elasticsearch.search.suggest.Suggest.Suggestion;
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry;
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry.Option;
Expand Down Expand Up @@ -112,6 +111,49 @@ public void testBasicGeo() throws Exception {
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 {
Expand Down