From fa241579cb3423b1d8d702ffdc77a92f3b116ec8 Mon Sep 17 00:00:00 2001 From: Ralph Gasser Date: Thu, 8 Aug 2024 15:44:29 +0200 Subject: [PATCH] Adds a generic merge method that allows the merger for parameter maps, with the parameters defined in an IndexConfig or QueryConfig taking precedence. Signed-off-by: Ralph Gasser --- .../engine/core/model/metamodel/Analyser.kt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/metamodel/Analyser.kt b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/metamodel/Analyser.kt index cbe2e050..14139bf4 100644 --- a/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/metamodel/Analyser.kt +++ b/vitrivr-engine-core/src/main/kotlin/org/vitrivr/engine/core/model/metamodel/Analyser.kt @@ -1,5 +1,6 @@ package org.vitrivr.engine.core.model.metamodel +import org.vitrivr.engine.core.context.IndexContext import org.vitrivr.engine.core.context.QueryContext import org.vitrivr.engine.core.model.content.Content import org.vitrivr.engine.core.model.content.element.ContentElement @@ -20,6 +21,40 @@ import kotlin.reflect.KClass * @version 1.4.0 */ interface Analyser, D : Descriptor> : ExtractorFactory { + + + companion object { + /** + * Merges the parameters of a [Schema.Field] with the parameters of the [IndexContext]. + * + * @param field The [Schema.Field] to merge parameters for. + * @param context The [IndexContext] to merge parameters with. + * @return Merged parameter map. + */ + fun merge(field: Schema.Field<*, *>, context: IndexContext): Map { + val fieldParameters = field.parameters + val contextParameters = context.local[field.fieldName] ?: emptyMap() + val merged = HashMap(contextParameters) + merged.putAll(fieldParameters) + return merged + } + + /** + * Merges the parameters of a [Schema.Field] with the parameters of the [IndexContext]. + * + * @param field The [Schema.Field] to merge parameters for. + * @param context The [QueryContext] to merge parameters with. + * @return Merged parameter map. + */ + fun merge(field: Schema.Field<*, *>, context: QueryContext): Map { + val fieldParameters = field.parameters + val contextParameters = context.local[field.fieldName] ?: emptyMap() + val merged = HashMap(contextParameters) + merged.putAll(fieldParameters) + return merged + } + } + /** The [KClass]es of the [ContentElement] accepted by this [Analyser]. */ val contentClasses: Set>>