From 4232154ed3bd86861dee67ae6f1fcd3116729864 Mon Sep 17 00:00:00 2001 From: Kathleen DeRusso Date: Tue, 3 Dec 2024 16:01:26 -0500 Subject: [PATCH] Cleanup --- .../query/InferenceQueryBuilderService.java | 32 +++++++++++ .../InferenceQueryBuilderServiceBuilder.java | 53 ------------------- .../elasticsearch/indices/IndicesService.java | 3 +- 3 files changed, 33 insertions(+), 55 deletions(-) delete mode 100644 server/src/main/java/org/elasticsearch/index/query/InferenceQueryBuilderServiceBuilder.java diff --git a/server/src/main/java/org/elasticsearch/index/query/InferenceQueryBuilderService.java b/server/src/main/java/org/elasticsearch/index/query/InferenceQueryBuilderService.java index 8a20712b87630..eaa44b2ec57bb 100644 --- a/server/src/main/java/org/elasticsearch/index/query/InferenceQueryBuilderService.java +++ b/server/src/main/java/org/elasticsearch/index/query/InferenceQueryBuilderService.java @@ -9,6 +9,12 @@ package org.elasticsearch.index.query; import org.elasticsearch.common.TriFunction; +import org.elasticsearch.plugins.PluginsService; +import org.elasticsearch.plugins.SearchPlugin; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; public class InferenceQueryBuilderService { private final TriFunction> defaultInferenceQueryBuilder; @@ -22,4 +28,30 @@ public AbstractQueryBuilder getDefaultInferenceQueryBuilder(String fieldName, ? defaultInferenceQueryBuilder.apply(fieldName, query, throwOnUnsupportedQueries) : null; } + + public static InferenceQueryBuilderService build(PluginsService pluginsService) { + Objects.requireNonNull(pluginsService); + + List>> definedInferenceQueryBuilders = new ArrayList<>(); + + List searchPlugins = pluginsService.filterPlugins(SearchPlugin.class).toList(); + for (SearchPlugin searchPlugin : searchPlugins) { + if (searchPlugin.getDefaultInferenceQueryBuilder() != null) { + definedInferenceQueryBuilders.add(searchPlugin.getDefaultInferenceQueryBuilder()); + } + } + + if (definedInferenceQueryBuilders.isEmpty()) { + // Backwards compatibility + return new InferenceQueryBuilderService(null); + } + + if (definedInferenceQueryBuilders.size() != 1) { + throw new IllegalStateException( + "Expected a single default inference query builder, but found " + definedInferenceQueryBuilders.size() + ); + } + + return new InferenceQueryBuilderService(definedInferenceQueryBuilders.getFirst()); + } } diff --git a/server/src/main/java/org/elasticsearch/index/query/InferenceQueryBuilderServiceBuilder.java b/server/src/main/java/org/elasticsearch/index/query/InferenceQueryBuilderServiceBuilder.java deleted file mode 100644 index 06f5e05015e2e..0000000000000 --- a/server/src/main/java/org/elasticsearch/index/query/InferenceQueryBuilderServiceBuilder.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.index.query; - -import org.elasticsearch.common.TriFunction; -import org.elasticsearch.plugins.PluginsService; -import org.elasticsearch.plugins.SearchPlugin; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -public class InferenceQueryBuilderServiceBuilder { - private PluginsService pluginsService; - - public InferenceQueryBuilderServiceBuilder pluginsService(PluginsService pluginsService) { - this.pluginsService = pluginsService; - return this; - } - - public InferenceQueryBuilderService build() { - Objects.requireNonNull(pluginsService); - - List>> definedInferenceQueryBuilders = new ArrayList<>(); - - List searchPlugins = pluginsService.filterPlugins(SearchPlugin.class).toList(); - for (SearchPlugin searchPlugin : searchPlugins) { - if (searchPlugin.getDefaultInferenceQueryBuilder() != null) { - definedInferenceQueryBuilders.add(searchPlugin.getDefaultInferenceQueryBuilder()); - } - } - - if (definedInferenceQueryBuilders.isEmpty()) { - // Backwards compatibility - return new InferenceQueryBuilderService(null); - } - - if (definedInferenceQueryBuilders.size() != 1) { - throw new IllegalStateException( - "Expected a single default inference query builder, but found " + definedInferenceQueryBuilders.size() - ); - } - - return new InferenceQueryBuilderService(definedInferenceQueryBuilders.getFirst()); - } -} diff --git a/server/src/main/java/org/elasticsearch/indices/IndicesService.java b/server/src/main/java/org/elasticsearch/indices/IndicesService.java index f386b9a3723e6..8aecac103faf1 100644 --- a/server/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/server/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -108,7 +108,6 @@ import org.elasticsearch.index.query.CoordinatorRewriteContextProvider; import org.elasticsearch.index.query.DataRewriteContext; import org.elasticsearch.index.query.InferenceQueryBuilderService; -import org.elasticsearch.index.query.InferenceQueryBuilderServiceBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryRewriteContext; import org.elasticsearch.index.recovery.RecoveryStats; @@ -382,7 +381,7 @@ public void onRemoval(ShardId shardId, String fieldName, boolean wasEvicted, lon this.timestampFieldMapperService = new TimestampFieldMapperService(settings, threadPool, this); this.postRecoveryMerger = new PostRecoveryMerger(settings, threadPool.executor(ThreadPool.Names.FORCE_MERGE), this::getShardOrNull); this.searchOperationListeners = builder.searchOperationListener; - this.inferenceQueryBuilderService = new InferenceQueryBuilderServiceBuilder().pluginsService(pluginsService).build(); + this.inferenceQueryBuilderService = InferenceQueryBuilderService.build(pluginsService); } private static final String DANGLING_INDICES_UPDATE_THREAD_NAME = "DanglingIndices#updateTask";