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

+ 23 - 1
lib/util/search.js

@@ -32,6 +32,19 @@ SearchClient.prototype.registerUpdateEvent = function() {
   pageEvent.on('update', this.syncPageUpdated.bind(this))
 };
 
+SearchClient.prototype.shouldIndexed = function(page) {
+  // FIXME: Magic Number
+  if (page.grant !== 1) {
+    return false;
+  }
+
+  if (page.redirectTo !== null) {
+    return false;
+  }
+
+  return true;
+};
+
 SearchClient.prototype.parseUri = function(uri) {
   if (!(m = uri.match(/^elasticsearch:\/\/([^:]+):([^\/]+)\/(.+)$/))) {
     throw new Error('Invalid ELASTICSEARCH_URI format. Should be elasticsearch://host:port/index_name');
@@ -152,7 +165,7 @@ SearchClient.prototype.addAllPages = function()
 
   return new Promise(function(resolve, reject) {
     stream.on('data', function (doc) {
-      if (!doc.creator || !doc.revision) {
+      if (!doc.creator || !doc.revision || !self.shouldIndexed(doc)) {
         debug('Skipped', doc.path);
         return ;
       }
@@ -334,6 +347,10 @@ SearchClient.prototype.searchKeywordUnderPath = function(keyword, path, option)
 
 SearchClient.prototype.syncPageCreated = function(page, user)
 {
+  if (!this.shouldIndexed(page)) {
+    return ;
+  }
+
   this.addPages([page])
   .then(function(res) {
     debug('ES Response', res);
@@ -345,6 +362,11 @@ SearchClient.prototype.syncPageCreated = function(page, user)
 
 SearchClient.prototype.syncPageUpdated = function(page, user)
 {
+  // TODO delete
+  if (!this.shouldIndexed(page)) {
+    return ;
+  }
+
   this.updatePages([page])
   .then(function(res) {
     debug('ES Response', res);