Sotaro KARASAWA 10 лет назад
Родитель
Сommit
a282b767f8
2 измененных файлов с 33 добавлено и 9 удалено
  1. 33 7
      bin/search.js
  2. 0 2
      lib/util/search.js

+ 33 - 7
bin/search.js

@@ -1,5 +1,6 @@
 
 var program = require('commander')
+  , sprintf = require('sprintf')
   , debug = require('debug')('debug:console:search-util')
   , crowi = new (require('../lib/crowi'))(__dirname + '/../', process.env)
   ;
@@ -18,9 +19,13 @@ crowi.init()
           .then(function(data) {
             console.log(data);
           })
+          .then(function() {
+            process.exit();
+          })
           .catch(function(err) {
             console.log("Error", err);
-          });
+
+          })
       });
 
     program
@@ -30,7 +35,13 @@ crowi.init()
 
         search.addAllPages()
           .then(function(data) {
-            console.log(data);
+            if (data.errors) {
+              console.error(data);
+              console.error('Failed to index.');
+            } else {
+              console.log('Data is successfully indexed.');
+            }
+            process.exit(0);
           })
           .catch(function(err) {
             console.log("Error", err);
@@ -38,16 +49,31 @@ crowi.init()
       });
 
     program
-      .command('rebuild-index [name]')
+      .command('rebuild-index')
       .action(function (cmd, env) {
+        var search = crowi.getSearcher();
 
-        search.rebuildIndex()
+        search.deleteIndex()
+          .then(function(data) {
+            if (!data.errors) {
+              console.log('Index deleted.');
+            }
+            return search.buildIndex();
+          })
+          .then(function(data) {
+            if (!data.errors) {
+              console.log('Index created.');
+            }
+            return search.addAllPages();
+          })
           .then(function(data) {
-            console.log('rebuildIndex:', data);
-            search.addAllPages();
+            if (!data.errors) {
+              console.log('Data is successfully indexed.');
+            }
+            process.exit(0);
           })
           .catch(function(err) {
-            debug('Error', err);
+            console.error('Error', err);
           });
       });
 

+ 0 - 2
lib/util/search.js

@@ -143,7 +143,6 @@ SearchClient.prototype.addAllPages = function()
         return ;
       }
 
-      debug('Prepare', doc);
       self.prepareBodyForCreate(body, doc);
     }).on('error', function (err) {
       // TODO: handle err
@@ -151,7 +150,6 @@ SearchClient.prototype.addAllPages = function()
     }).on('close', function () {
       // all done
 
-      debug('Send', body);
       // 最後に送信
       self.client.bulk({ body: body, })
       .then(function(res) {