Skip to content

Commit

Permalink
Adjusted schema management for copy-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
sermo-de-arboribus committed Apr 26, 2022
1 parent 809dc92 commit 24c6315
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
17 changes: 14 additions & 3 deletions lib/solr.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -123,6 +125,7 @@ class Schema
fieldTypes: schemaIndex schema, "fieldTypes"
fields: schemaIndex schema, "fields"
dynamicFields: schemaIndex schema, "dynamicFields"
copyFields: schemaIndex schema, "copyFields"

this

Expand All @@ -136,18 +139,26 @@ 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"
if not fieldExists then "add" else "replace"
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?

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 24c6315

Please sign in to comment.