From c51cf423e3cc965e3f76c413f07df4fb3baaf587 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 25 Mar 2021 19:12:17 +0000 Subject: [PATCH] Creating CouchDB 3.0 indexes. --- hosting/docker-compose.dev.yaml | 32 ++----------------- hosting/hosting.properties | 1 - packages/server/src/db/views/staticViews.js | 34 ++++++++------------- 3 files changed, 16 insertions(+), 51 deletions(-) diff --git a/hosting/docker-compose.dev.yaml b/hosting/docker-compose.dev.yaml index 2cbba5771f..8ee1753e11 100644 --- a/hosting/docker-compose.dev.yaml +++ b/hosting/docker-compose.dev.yaml @@ -34,37 +34,17 @@ services: - minio-service - couchdb-service - couchdb-lucene: - container_name: budi-couchdb-lucene-dev - build: - context: lucene - dockerfile: Dockerfile - ports: - - "${COUCH_LUCENE_PORT}:5985" - volumes: - - couchdb_lucene:/opt/couchdb-lucene - networks: - dbs: - aliases: - - couchdb-lucene - couchdb-service: container_name: budi-couchdb-dev restart: always - build: - context: couch - dockerfile: Dockerfile + image: ibmcom/couchdb3 environment: - COUCHDB_PASSWORD=${COUCH_DB_PASSWORD} - COUCHDB_USER=${COUCH_DB_USER} ports: - "${COUCH_DB_PORT}:5984" volumes: - - couchdb_data:/opt/couchdb/data -# networks: -# dbs: -# aliases: -# - couchdb + - couchdb3_data:/opt/couchdb/data couch-init: container_name: budi-couchdb-init-dev @@ -84,16 +64,10 @@ services: volumes: - redis_data:/data -networks: - dbs: - driver: bridge - volumes: - couchdb_data: + couchdb3_data: driver: local minio_data: driver: local redis_data: driver: local - couchdb_lucene: - driver: local diff --git a/hosting/hosting.properties b/hosting/hosting.properties index 5b80a844dd..138e66d629 100644 --- a/hosting/hosting.properties +++ b/hosting/hosting.properties @@ -18,6 +18,5 @@ APP_PORT=4002 WORKER_PORT=4003 MINIO_PORT=4004 COUCH_DB_PORT=4005 -COUCH_LUCENE_PORT=4006 REDIS_PORT=6379 BUDIBASE_ENVIRONMENT=PRODUCTION diff --git a/packages/server/src/db/views/staticViews.js b/packages/server/src/db/views/staticViews.js index 50e3a4a1a9..ae6496bb4a 100644 --- a/packages/server/src/db/views/staticViews.js +++ b/packages/server/src/db/views/staticViews.js @@ -76,33 +76,25 @@ exports.createRoutingView = async appId => { exports.createFulltextSearchIndex = async appId => { const db = new CouchDB(appId) const designDoc = await db.get("_design/database") - designDoc.fulltext = { - everything: { + designDoc.indexes = { + rows: { index: function(doc) { - let ret = new Document() - - function idx(obj) { + // eslint-disable-next-line no-undef + index("id", doc._id) + function idx(obj, prev = "") { for (let key of Object.keys(obj)) { - switch (typeof obj[key]) { - case "object": - idx(obj[key]) - break - case "function": - break - default: - ret.add(obj[key]) - break + let prevKey = prev !== "" ? `${prev}.${key}` : key + if (typeof obj[key] !== "object") { + // eslint-disable-next-line no-undef + index(prevKey, obj[key], { store: true }) + } else { + idx(obj[key], prevKey) } } } - - idx(doc) - if (doc._attachments) { - for (let i in Object.keys(doc._attachments)) { - ret.attachment("default", i) - } + if (doc._id.startsWith("ro_")) { + idx(doc) } - return ret }.toString(), }, }