summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2010-04-22 15:08:08 +0000
committerJohn Christopher Anderson <jchris@apache.org>2010-04-22 15:08:08 +0000
commit3143d4eba8b40b33c3dbe5897d6fdb7ec7377f71 (patch)
tree976dba9dbe5f555f60eb77cf0f52e63242232608
parent5c758e7f2ca47b1285d08f170b5105b618fb956e (diff)
fix erlang filter funs and normalize filter fun api. thanks fdmanana. closes COUCHDB-740
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@936889 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--share/server/filter.js3
-rw-r--r--share/www/script/test/changes.js39
-rw-r--r--src/couchdb/couch_query_servers.erl3
3 files changed, 41 insertions, 4 deletions
diff --git a/share/server/filter.js b/share/server/filter.js
index 8ba77e64..1e8556a4 100644
--- a/share/server/filter.js
+++ b/share/server/filter.js
@@ -15,9 +15,8 @@ var Filter = {
var results = [];
var docs = args[0];
var req = args[1];
- var userCtx = args[2];
for (var i=0; i < docs.length; i++) {
- results.push((fun.apply(ddoc, [docs[i], req, userCtx]) && true) || false);
+ results.push((fun.apply(ddoc, [docs[i], req]) && true) || false);
};
respond([true, results]);
}
diff --git a/share/www/script/test/changes.js b/share/www/script/test/changes.js
index 1240712f..72ec0279 100644
--- a/share/www/script/test/changes.js
+++ b/share/www/script/test/changes.js
@@ -347,5 +347,44 @@ couchTests.changes = function(debug) {
req = CouchDB.request("GET", "/test_suite_db/_changes?filter=changes_filter/conflicted");
resp = JSON.parse(req.responseText);
T(resp.results.length == 1);
+
+ // test with erlang filter function
+ run_on_modified_server([{
+ section: "native_query_servers",
+ key: "erlang",
+ value: "{couch_native_process, start_link, []}"
+ }], function() {
+ var erl_ddoc = {
+ _id: "_design/erlang",
+ language: "erlang",
+ filters: {
+ foo:
+ 'fun({Doc}, Req) -> ' +
+ ' Value = proplists:get_value(<<"value">>, Doc),' +
+ ' (Value rem 2) =:= 0' +
+ 'end.'
+ }
+ };
+
+ db.deleteDb();
+ db.createDb();
+ T(db.save(erl_ddoc).ok);
+
+ var req = CouchDB.request("GET", "/test_suite_db/_changes?filter=erlang/foo");
+ var resp = JSON.parse(req.responseText);
+ T(resp.results.length === 0);
+
+ T(db.save({_id: "doc1", value : 1}).ok);
+ T(db.save({_id: "doc2", value : 2}).ok);
+ T(db.save({_id: "doc3", value : 3}).ok);
+ T(db.save({_id: "doc4", value : 4}).ok);
+
+ var req = CouchDB.request("GET", "/test_suite_db/_changes?filter=erlang/foo");
+ var resp = JSON.parse(req.responseText);
+ T(resp.results.length === 2);
+ T(resp.results[0].id === "doc2");
+ T(resp.results[1].id === "doc4");
+ });
+
};
diff --git a/src/couchdb/couch_query_servers.erl b/src/couchdb/couch_query_servers.erl
index cb760a10..cfed30b9 100644
--- a/src/couchdb/couch_query_servers.erl
+++ b/src/couchdb/couch_query_servers.erl
@@ -208,8 +208,7 @@ filter_docs(Req, Db, DDoc, FName, Docs) ->
couch_httpd_external:json_req_obj(HttpReq, Db)
end,
JsonDocs = [couch_doc:to_json_obj(Doc, [revs]) || Doc <- Docs],
- JsonCtx = couch_util:json_user_ctx(Db),
- [true, Passes] = ddoc_prompt(DDoc, [<<"filters">>, FName], [JsonDocs, JsonReq, JsonCtx]),
+ [true, Passes] = ddoc_prompt(DDoc, [<<"filters">>, FName], [JsonDocs, JsonReq]),
{ok, Passes}.
ddoc_proc_prompt({Proc, DDocId}, FunPath, Args) ->