Răsfoiți Sursa

add SearchboxDelegator

Yuki Takei 6 ani în urmă
părinte
comite
603dc51b3a
1 a modificat fișierele cu 47 adăugiri și 0 ștergeri
  1. 47 0
      src/server/service/search-delegator/searchbox.js

+ 47 - 0
src/server/service/search-delegator/searchbox.js

@@ -0,0 +1,47 @@
+// eslint-disable-next-line no-unused-vars
+const logger = require('@alias/logger')('growi:service:search-delegator:searchbox');
+
+const ElasticsearchDelegator = require('./elasticsearch');
+
+class SearchboxDelegator extends ElasticsearchDelegator {
+
+  /**
+   * @inheritdoc
+   */
+  getConnectionInfo() {
+    const searchboxSslUrl = this.configManager.getConfig('crowi', 'app:searchboxSslUrl');
+    const url = new URL(searchboxSslUrl);
+
+    const indexName = 'crowi';
+    const host = `${url.protocol}//${url.auth}${url.hostname}:443`;
+
+    return {
+      host,
+      httpAuth: '',
+      indexName,
+    };
+  }
+
+  /**
+   * @inheritdoc
+   */
+  async buildIndex() {
+    const { client, indexName, aliasName } = this;
+
+    // flush index
+    await client.indices.delete({
+      index: indexName,
+    });
+    await this.createIndex(indexName);
+    await this.addAllPages();
+
+    // put alias
+    await client.indices.putAlias({
+      name: aliasName,
+      index: indexName,
+    });
+  }
+
+}
+
+module.exports = SearchboxDelegator;