From 24c63158c6c1125f56bc2ae5273cce1d7edb8ef5 Mon Sep 17 00:00:00 2001 From: Kai Weber Date: Tue, 26 Apr 2022 17:17:08 +0200 Subject: [PATCH] Adjusted schema management for copy-fields --- lib/solr.coffee | 17 ++++++++++++++--- package-lock.json | 12 ++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/solr.coffee b/lib/solr.coffee index dfa741c..dd1046f 100644 --- a/lib/solr.coffee +++ b/lib/solr.coffee @@ -110,7 +110,9 @@ SCHEMA_UPDATE_COMMANDS = [ schemaIndex = (schema, key) -> schema = schema[key] ? [] - schema.reduce ((idx, value) -> { idx..., [value.name]: value }), {} + schema.reduce ((idx, value) -> + key = value.name ? value.source + { idx..., [key]: value }), {} class Schema @@ -123,6 +125,7 @@ class Schema fieldTypes: schemaIndex schema, "fieldTypes" fields: schemaIndex schema, "fields" dynamicFields: schemaIndex schema, "dynamicFields" + copyFields: schemaIndex schema, "copyFields" this @@ -136,11 +139,13 @@ class Schema key = switch when op is "dynamic-field" then "dynamicFields" when op is "field-type" then "fieldTypes" + when op is "copy-field" then "copyFields" else "fields" - fieldExists = @indexed[key][params.name]? + fieldName = params.name ? params.source + fieldExists = @indexed[key][fieldName]? - targetOpType = switch opType + if op is not "copy-field" then targetOpType = switch opType when "add" if fieldExists then "replace" else "add" when "replace" @@ -148,6 +153,12 @@ class Schema when "delete" if not fieldExists then null else "delete" else opType + else targetOpType = switch opType + when "add" + if fieldExists then null else "add" + when "delete" + if not fieldExists then null else "delete" + else opType "#{targetOpType}-#{op}" if targetOpType? diff --git a/package-lock.json b/package-lock.json index e00daa4..884f76f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -346,9 +346,9 @@ } }, "node_modules/minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" }, "node_modules/ms": { "version": "2.1.2", @@ -712,9 +712,9 @@ } }, "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" }, "ms": { "version": "2.1.2",