From faa9e88d2398c545b308600babe01d9d9def04e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20K=C3=BCblb=C3=B6ck?= Date: Wed, 29 Jul 2015 14:29:58 +0200 Subject: [PATCH 1/3] Allow transforming nested fields. --- lib/client.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index 3963ab8..a0fa67e 100644 --- a/lib/client.js +++ b/lib/client.js @@ -128,11 +128,27 @@ SearchSource.prototype.getData = function(options, getCursor) { selector = {}; } + function pick(doc, field) { + if (_.isString(field)) field = field.split('.'); + if (!_.isArray(field)) return doc[field]; + var tmp = doc; + while (i = field.shift()) + tmp = tmp[i]; + return tmp; + }; + + function put(doc, field, value) { + if (_.isString(field)) field = field.split('.'); + if (!_.isArray(field)) doc[field] = value; + pick(doc, _.initial(field))[_.last(field)] = value; + }; + function transform(doc) { if(options.transform) { self.searchFields.forEach(function(field) { - if(self.currentQuery && doc[field]) { - doc[field] = options.transform(doc[field], regExp, field, self.currentQuery); + var property = pick(doc, field); + if(self.currentQuery && property) { + put(doc, field, options.transform(property, regExp, field, self.currentQuery)); } }); } From 6226c9a372761f8ea8a273e7b8b6fdf2ae698795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20K=C3=BCblb=C3=B6ck?= Date: Wed, 19 Aug 2015 11:48:52 +0200 Subject: [PATCH 2/3] Don't try to handle data when payload is empty. --- lib/client.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/client.js b/lib/client.js index a0fa67e..79de745 100644 --- a/lib/client.js +++ b/lib/client.js @@ -30,6 +30,9 @@ SearchSource.prototype._loadData = function(query, options) { } function handleData(err, payload) { + if (!payload) { + return; + } if(err) { self.status.set({error: err}); throw err; From 005268a7daf25a143f5f723d9e81e05eb6cece73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20K=C3=BCblb=C3=B6ck?= Date: Wed, 19 Aug 2015 11:51:22 +0200 Subject: [PATCH 3/3] Add gitignore file. --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6450084 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.npm