Permalink
Browse files

Make geometry search work with spatial merging

Geometry search wasn't working with spatial merging. This
fixes it and it also adds a test, to prevent future regression.

Change-Id: Ib0de1f5acb03ef4252f4dcff01a6d87e67f835dd
  • Loading branch information...
1 parent 5f37ad2 commit 59c0b01c10b7f79fd689eea8cc228acd23a83e5d @vmx committed Mar 8, 2012
@@ -90,7 +90,7 @@ couchTests.spatial_merging = function(debug) {
qs = qs + String(q) + "=" + String(options[q]);
}
- qs = "?bbox=-1800,-900,1800,900&" + qs;
+ qs = "?" + qs;
var xhr = CouchDB.request("POST", "/_spatial_merge" + qs, {
headers: {
@@ -637,6 +637,29 @@ couchTests.spatial_merging = function(debug) {
TEquals(10, resp.rows.length);
+
+ // Test for a bug where the merging returned a point that isn't within
+ // the polygin
+ dbA = newDb("test_db_a");
+ dbB = newDb("test_db_b");
+ addDoc([dbA, dbB], ddoc);
+
+ var bbox = [-180, -90, 180, 90];
+ docs = [{"_id": "beff587-914", "loc": [84,65]},
+ {"_id": "withinpoly", "loc": [-7,9]}];
+
+ var poly = 'POLYGON%28%28-101.6015625+57.12890625%2C+-106.5234375+6.50390625%2C+-43.9453125+16.34765625%2C+-60.1171875+-30.76171875%2C+46.0546875+-37.08984375%2C+21.4453125+1.58203125%2C+157.1484375+-6.85546875%2C+23.5546875+30.41015625%2C+40.4296875+48.69140625%2C+-13.7109375+32.51953125%2C+-36.9140625+65.56640625%2C+-58.7109375+43.06640625%2C+-101.6015625+57.12890625%29%29';
+
+ dbA.save(docs[0]);
+ dbB.save(docs[1]);
+
+ resp = mergedQuery(dbs, "test/fun1", {geometry: poly});
+ TEquals("object", typeof resp);
+ TEquals("object", typeof resp.rows);
+ TEquals(1, resp.rows.length);
+ TEquals('withinpoly', resp.rows[0].id);
+
+
// cleanup
dbA.deleteDb();
dbB.deleteDb();
@@ -17,7 +17,7 @@
-export([handle_spatial_req/3, spatial_etag/3, spatial_etag/4,
load_index/3, handle_compact_req/3, handle_design_info_req/3,
handle_spatial_cleanup_req/2, parse_spatial_params/1,
- make_spatial_fold_funs/6]).
+ make_spatial_fold_funs/6, condition_disjoint/2]).
-import(couch_httpd,
[send_json/2, send_json/3, send_method_not_allowed/2, send_chunk/2,
@@ -114,9 +114,10 @@ spatial_folder(Db, SpatialSpec, MergeParams, _UserCtx, DDoc, Queue) ->
#spatial_query_args{
bbox = Bbox,
bounds = Bounds,
- stale = Stale
+ stale = Stale,
+ geometry = QueryGeom
} = MergeParams#index_merge.http_params,
- FoldlFun = make_spatial_fold_fun(Queue),
+ FoldlFun = make_spatial_fold_fun(Queue, QueryGeom),
{DDocDb, Index} = get_spatial_index(Db, DDocDbName, DDocId,
SpatialName, Stale),
@@ -227,10 +228,19 @@ http_spatial_fold_queue_row({Props}, Queue) ->
% Counterpart to make_map_fold_fun/4 in couch_view_merger
% Used for merges of local DBs
-make_spatial_fold_fun(Queue) ->
+make_spatial_fold_fun(Queue, nil) ->
fun({{_Bbox, _DocId}, {_Geom, _Value}}=Row, Acc) ->
ok = couch_view_merger_queue:queue(Queue, Row),
{ok, Acc}
+ end;
+make_spatial_fold_fun(Queue, QueryGeom) ->
+ QueryGeom2 = erlgeom:to_geom(QueryGeom),
+ fun({{_DocId, _Bbox}, {Geom, _Value}}=Row, Acc) ->
+ case couch_httpd_spatial:condition_disjoint(QueryGeom2, Geom) of
+ true -> ok = couch_view_merger_queue:queue(Queue, Row);
+ false -> ok
+ end,
+ {ok, Acc}
end.
% Counterpart to merge_map_views/6 in couch_view_merger

0 comments on commit 59c0b01

Please sign in to comment.