|
|
@@ -90,33 +90,35 @@ SearchClient.prototype.addAllPages = function()
|
|
|
var stream = Page.getStreamOfFindAll();
|
|
|
var body = [];
|
|
|
|
|
|
- stream.on('data', function (doc) {
|
|
|
- if (!doc.creator || !doc.revision) {
|
|
|
- debug('Skipped', doc.path);
|
|
|
- return ;
|
|
|
- }
|
|
|
+ return new Promise(function(resolve, reject) {
|
|
|
+ stream.on('data', function (doc) {
|
|
|
+ if (!doc.creator || !doc.revision) {
|
|
|
+ debug('Skipped', doc.path);
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+
|
|
|
+ debug('Prepare', doc);
|
|
|
+ self.prepareBodyForCreate(body, doc);
|
|
|
+ //debug('Data received: ', doc.path, doc.liker.length, doc.revision.body);
|
|
|
+ }).on('error', function (err) {
|
|
|
+ debug('Error stream:', err);
|
|
|
+ // handle err
|
|
|
+ }).on('close', function () {
|
|
|
+ // all done
|
|
|
+ debug('Close');
|
|
|
|
|
|
- debug('Prepare', doc);
|
|
|
- self.prepareBodyForCreate(body, doc);
|
|
|
- //debug('Data received: ', doc.path, doc.liker.length, doc.revision.body);
|
|
|
- }).on('error', function (err) {
|
|
|
- debug('Error stream:', err);
|
|
|
- // handle err
|
|
|
- }).on('close', function () {
|
|
|
- // all done
|
|
|
- debug('Close');
|
|
|
-
|
|
|
- debug('SEnd', body);
|
|
|
- // 最後に送信
|
|
|
- self.client.bulk({ body: body, })
|
|
|
- .then(function(res) {
|
|
|
- debug('Reponse from es:', res);
|
|
|
- }).catch(function(err) {
|
|
|
- debug('Err from es:', err);
|
|
|
+ debug('SEnd', body);
|
|
|
+ // 最後に送信
|
|
|
+ self.client.bulk({ body: body, })
|
|
|
+ .then(function(res) {
|
|
|
+ debug('Reponse from es:', res);
|
|
|
+ return resolve(res);
|
|
|
+ }).catch(function(err) {
|
|
|
+ debug('Err from es:', err);
|
|
|
+ return reject(err);
|
|
|
+ });
|
|
|
});
|
|
|
});
|
|
|
-
|
|
|
- return Promise.resolve();
|
|
|
};
|
|
|
|
|
|
module.exports = SearchClient;
|