Skip to content

Commit

Permalink
Geo search fails to find some docs when wrapping over IDL, closes ela…
Browse files Browse the repository at this point in the history
  • Loading branch information
kimchy committed Dec 10, 2010
1 parent 9d2fe16 commit 2a7f964
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/kimchy.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,18 @@ public String fieldName() {
for (int i = 0; i < lats.length; i++) {
double lat = lats[i];
double lon = lons[i];
if (lon < 0) {
if (-180.0 <= lon && bottomRight.lon >= lon
&& topLeft.lat >= lat && bottomRight.lat <= lat) {
return true;
}
} else {
if (topLeft.lon <= lon && 180 >= lon
&& topLeft.lat >= lat && bottomRight.lat <= lat) {
return true;
}
if (((topLeft.lon <= lon && 180 >= lon) || (-180 <= lon && bottomRight.lon >= lon)) &&
(topLeft.lat >= lat && bottomRight.lat <= lat)) {
return true;
}
}
} else {
double lat = fieldData.latValue(doc);
double lon = fieldData.lonValue(doc);
if (lon < 0) {
if (-180.0 <= lon && bottomRight.lon >= lon
&& topLeft.lat >= lat && bottomRight.lat <= lat) {
return true;
}
} else {
if (topLeft.lon <= lon && 180 >= lon
&& topLeft.lat >= lat && bottomRight.lat <= lat) {
return true;
}

if (((topLeft.lon <= lon && 180 >= lon) || (-180 <= lon && bottomRight.lon >= lon)) &&
(topLeft.lat >= lat && bottomRight.lat <= lat)) {
return true;
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,48 @@ protected Client getClient() {
assertThat(searchResponse.hits().hits().length, equalTo(1));
assertThat(searchResponse.hits().getAt(0).id(), equalTo("9"));
}

@Test public void limit2BoundingBoxTest() throws Exception {
try {
client.admin().indices().prepareDelete("test").execute().actionGet();
} catch (Exception e) {
// ignore
}
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties").startObject("location").field("type", "geo_point").field("lat_lon", true).endObject().endObject()
.endObject().endObject().string();
client.admin().indices().prepareCreate("test").addMapping("type1", mapping).setSettings(settingsBuilder().put("number_of_shards", "1")).execute().actionGet();
client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();

client.prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject()
.field("userid", 880)
.field("title", "Place in Stockholm")
.startObject("location").field("lat", 59.328355000000002).field("lon", 18.036842).endObject()
.endObject())
.setRefresh(true)
.execute().actionGet();

client.prepareIndex("test", "type1", "2").setSource(jsonBuilder().startObject()
.field("userid", 534)
.field("title", "Place in Montreal")
.startObject("location").field("lat", 45.509526999999999).field("lon", -73.570986000000005).endObject()
.endObject())
.setRefresh(true)
.execute().actionGet();

SearchResponse searchResponse = client.prepareSearch()
.setQuery(
filteredQuery(termQuery("userid", 880),
geoBoundingBoxFilter("location").topLeft(74.579421999999994, 143.5).bottomRight(-66.668903999999998, 113.96875))
).execute().actionGet();
assertThat(searchResponse.hits().totalHits(), equalTo(1l));

searchResponse = client.prepareSearch()
.setQuery(
filteredQuery(termQuery("userid", 534),
geoBoundingBoxFilter("location").topLeft(74.579421999999994, 143.5).bottomRight(-66.668903999999998, 113.96875))
).execute().actionGet();
assertThat(searchResponse.hits().totalHits(), equalTo(1l));
}
}

0 comments on commit 2a7f964

Please sign in to comment.