summaryrefslogtreecommitdiffstats
path: root/container-search/src
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2020-05-19 21:02:34 +0200
committergjoranv <gv@verizonmedia.com>2020-05-22 14:33:39 +0200
commitbdfc429cda06bb6f285e94f9ac5752bc86b7df57 (patch)
tree3afb0c8bb7333227c13a3162614e5e9f93fc6102 /container-search/src
parent53d49accd023d09e22ebda430791c2d4ed3c3cd1 (diff)
Allow creating a CompiledQueryProfileRegistry from config.
Diffstat (limited to 'container-search/src')
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfileRegistry.java18
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfileRegistryTest.java28
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileConfigurationTestCase.java14
3 files changed, 50 insertions, 10 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfileRegistry.java b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfileRegistry.java
index 7ab05d0cd1e..744c6eb6933 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfileRegistry.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfileRegistry.java
@@ -1,9 +1,14 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query.profile.compiled;
+import com.google.inject.Inject;
import com.yahoo.component.ComponentSpecification;
import com.yahoo.component.provider.ComponentRegistry;
-import com.yahoo.search.query.profile.types.QueryProfileType;
+import com.yahoo.search.query.profile.QueryProfile;
+import com.yahoo.search.query.profile.QueryProfileCompiler;
+import com.yahoo.search.query.profile.QueryProfileRegistry;
+import com.yahoo.search.query.profile.config.QueryProfileConfigurer;
+import com.yahoo.search.query.profile.config.QueryProfilesConfig;
import com.yahoo.search.query.profile.types.QueryProfileTypeRegistry;
/**
@@ -18,6 +23,15 @@ public class CompiledQueryProfileRegistry extends ComponentRegistry<CompiledQuer
private final QueryProfileTypeRegistry typeRegistry;
+ @Inject
+ public CompiledQueryProfileRegistry(QueryProfilesConfig config) {
+ QueryProfileRegistry registry = QueryProfileConfigurer.createFromConfig(config);
+ typeRegistry = registry.getTypeRegistry();
+ for (QueryProfile inputProfile : registry.allComponents()) {
+ register(QueryProfileCompiler.compile(inputProfile, this));
+ }
+ }
+
/** Creates a compiled query profile registry with no types */
public CompiledQueryProfileRegistry() {
this(QueryProfileTypeRegistry.emptyFrozen());
@@ -28,7 +42,7 @@ public class CompiledQueryProfileRegistry extends ComponentRegistry<CompiledQuer
}
/** Registers a type by its id */
- public void register(CompiledQueryProfile profile) {
+ public final void register(CompiledQueryProfile profile) {
super.register(profile.getId(), profile);
}
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfileRegistryTest.java b/container-search/src/test/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfileRegistryTest.java
new file mode 100644
index 00000000000..39d4fec2716
--- /dev/null
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfileRegistryTest.java
@@ -0,0 +1,28 @@
+package com.yahoo.search.query.profile.compiled;
+
+import com.yahoo.search.query.profile.config.QueryProfilesConfig;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author gjoranv
+ */
+public class CompiledQueryProfileRegistryTest {
+
+ @Test
+ public void registry_can_be_created_from_config() {
+ var config = new QueryProfilesConfig.Builder()
+ .queryprofile(new QueryProfilesConfig.Queryprofile.Builder()
+ .id("profile1")
+ .property(new QueryProfilesConfig.Queryprofile.Property.Builder()
+ .name("hits")
+ .value("5")))
+ .build();
+
+ var registry = new CompiledQueryProfileRegistry(config);
+ var profile1 = registry.findQueryProfile("profile1");
+ assertEquals("5", profile1.get("hits"));
+ }
+
+}
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileConfigurationTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileConfigurationTestCase.java
index 819cd3cdfd4..a1fba8e07f1 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileConfigurationTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileConfigurationTestCase.java
@@ -1,27 +1,25 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query.profile.config.test;
-import com.yahoo.config.subscription.ConfigInstanceUtil;
-import com.yahoo.io.IOUtils;
import com.yahoo.search.Query;
import com.yahoo.search.query.profile.QueryProfile;
-import com.yahoo.search.query.profile.compiled.CompiledQueryProfile;
import com.yahoo.search.query.profile.QueryProfileProperties;
+import com.yahoo.search.query.profile.compiled.CompiledQueryProfile;
import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry;
import com.yahoo.search.query.profile.config.QueryProfileConfigurer;
import com.yahoo.search.query.profile.config.QueryProfilesConfig;
+import com.yahoo.search.query.profile.config.QueryProfilesConfig.Queryprofile;
import com.yahoo.search.test.QueryTestCase;
-import com.yahoo.vespa.config.ConfigPayload;
-import org.junit.Ignore;
import org.junit.Test;
-import static org.junit.Assert.*;
-import java.io.File;
-import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+
/**
* @author bratseth
*/