Sotaro KARASAWA 10 anni fa
parent
commit
a15a44d7d8
2 ha cambiato i file con 27 aggiunte e 24 eliminazioni
  1. 1 0
      bin/search.js
  2. 26 24
      lib/util/search.js

+ 1 - 0
bin/search.js

@@ -51,6 +51,7 @@ crowi.init()
           });
           });
       });
       });
 
 
+
     program.parse(process.argv);
     program.parse(process.argv);
 
 
   }).catch(crowi.exitOnError);
   }).catch(crowi.exitOnError);

+ 26 - 24
lib/util/search.js

@@ -90,33 +90,35 @@ SearchClient.prototype.addAllPages = function()
   var stream = Page.getStreamOfFindAll();
   var stream = Page.getStreamOfFindAll();
   var body = [];
   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;
 module.exports = SearchClient;