summaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-05-31 23:32:02 +0200
committergjoranv <gv@verizonmedia.com>2022-06-08 11:45:23 +0200
commit1463c41b72fb46fa3bd57be965b0d0681749944d (patch)
tree9f98272202c5405476e548e88805224c804dd668 /container-search
parentd8c94dd62a910e8f66bbe341fa96eef6bb3f1121 (diff)
Remove on Vespa 8
Diffstat (limited to 'container-search')
-rw-r--r--container-search/abi-spec.json3
-rw-r--r--container-search/src/main/java/com/yahoo/search/federation/CommonFields.java25
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfileRegistry.java4
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/config/QueryProfileConfigurer.java30
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileConfigurationTestCase.java99
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/config/test/TypedProfilesConfigurationTestCase.java28
6 files changed, 69 insertions, 120 deletions
diff --git a/container-search/abi-spec.json b/container-search/abi-spec.json
index 78ebd80e1db..0c6437fd754 100644
--- a/container-search/abi-spec.json
+++ b/container-search/abi-spec.json
@@ -6285,7 +6285,8 @@
"public void <init>(com.yahoo.search.query.profile.types.QueryProfileTypeRegistry)",
"public final void register(com.yahoo.search.query.profile.compiled.CompiledQueryProfile)",
"public com.yahoo.search.query.profile.types.QueryProfileTypeRegistry getTypeRegistry()",
- "public com.yahoo.search.query.profile.compiled.CompiledQueryProfile findQueryProfile(java.lang.String)"
+ "public com.yahoo.search.query.profile.compiled.CompiledQueryProfile findQueryProfile(java.lang.String)",
+ "public static com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry fromConfig(com.yahoo.search.query.profile.config.QueryProfilesConfig)"
],
"fields": [
"public static final com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry empty"
diff --git a/container-search/src/main/java/com/yahoo/search/federation/CommonFields.java b/container-search/src/main/java/com/yahoo/search/federation/CommonFields.java
deleted file mode 100644
index 5c9b1da8c3d..00000000000
--- a/container-search/src/main/java/com/yahoo/search/federation/CommonFields.java
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.search.federation;
-/**
- * A set of string constants for common hit field names.
- *
- * @author laboisse
- * @deprecated do not use
- */
-@Deprecated // TODO: Remove on Vespa 8
-public class CommonFields {
-
- public static final String TITLE = "title";
- public static final String URL = "url";
- public static final String DESCRIPTION = "description";
- public static final String DATE = "date";
- public static final String SIZE = "size";
- public static final String DISP_URL = "dispurl";
- public static final String BASE_URL = "baseurl";
- public static final String MIME_TYPE = "mimetype";
- public static final String RELEVANCY = "relevancy";
- public static final String THUMBNAIL_URL = "thumbnailUrl";
- public static final String THUMBNAIL_WIDTH = "thumbnailWidth";
- public static final String THUMBNAIL_HEIGHT = "thumbnailHeight";
-
-}
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 84246b1eb25..b870b32da77 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
@@ -135,4 +135,8 @@ public class CompiledQueryProfileRegistry extends ComponentRegistry<CompiledQuer
return registry;
}
+ public static CompiledQueryProfileRegistry fromConfig(QueryProfilesConfig config) {
+ return QueryProfileConfigurer.createFromConfig(config).compile();
+ }
+
}
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/config/QueryProfileConfigurer.java b/container-search/src/main/java/com/yahoo/search/query/profile/config/QueryProfileConfigurer.java
index c3bd4f7b962..31278af9579 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/config/QueryProfileConfigurer.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/config/QueryProfileConfigurer.java
@@ -3,7 +3,7 @@ package com.yahoo.search.query.profile.config;
import com.yahoo.component.ComponentId;
import com.yahoo.component.ComponentSpecification;
-import com.yahoo.config.subscription.ConfigSubscriber;
+import com.yahoo.config.subscription.ConfigGetter;
import com.yahoo.search.query.profile.DimensionValues;
import com.yahoo.search.query.profile.QueryProfile;
import com.yahoo.search.query.profile.QueryProfileRegistry;
@@ -19,27 +19,10 @@ import java.util.Set;
/**
* @author bratseth
*/
-@SuppressWarnings("removal") // TODO Vespa 8: remove
-public class QueryProfileConfigurer implements ConfigSubscriber.SingleSubscriber<QueryProfilesConfig> {
+public class QueryProfileConfigurer {
- private final ConfigSubscriber subscriber = new ConfigSubscriber();
-
- private volatile QueryProfileRegistry currentRegistry;
-
- public QueryProfileConfigurer(String configId) {
- subscriber.subscribe(this, QueryProfilesConfig.class, configId);
- }
-
- /** Returns the registry created by the last occurring call to configure */
- public QueryProfileRegistry getCurrentRegistry() { return currentRegistry; }
-
- private void setCurrentRegistry(QueryProfileRegistry registry) {
- this.currentRegistry=registry;
- }
-
- public void configure(QueryProfilesConfig config) {
- QueryProfileRegistry registry = createFromConfig(config);
- setCurrentRegistry(registry);
+ public static QueryProfileRegistry createFromConfigId(String configId) {
+ return createFromConfig(ConfigGetter.getConfig(QueryProfilesConfig.class, configId));
}
public static QueryProfileRegistry createFromConfig(QueryProfilesConfig config) {
@@ -69,11 +52,6 @@ public class QueryProfileConfigurer implements ConfigSubscriber.SingleSubscriber
return registry;
}
- /** Stop subscribing from this configurer */
- public void shutdown() {
- subscriber.close();
- }
-
private static void createProfile(QueryProfilesConfig.Queryprofile config, QueryProfileRegistry registry) {
QueryProfile profile = new QueryProfile(new ComponentId(config.id()), config.id(), registry);
try {
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 84bb82f3851..29a8969233b 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
@@ -5,10 +5,7 @@ import com.yahoo.search.Query;
import com.yahoo.search.query.profile.QueryProfile;
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 org.junit.Test;
@@ -29,27 +26,27 @@ public class QueryProfileConfigurationTestCase {
@Test
public void testConfiguration() {
- QueryProfileConfigurer configurer=
- new QueryProfileConfigurer("file:" + CONFIG_DIR + "query-profiles-configuration.cfg");
- QueryProfile profile=configurer.getCurrentRegistry().getComponent("default");
+ var profile = QueryProfileConfigurer.createFromConfigId("file:" + CONFIG_DIR + "query-profiles-configuration.cfg")
+ .getComponent("default");
- assertEquals("a-value",profile.get("a"));
- assertEquals("b-value",profile.get("b"));
- assertEquals("c.d-value",profile.get("c.d"));
+ assertEquals("a-value", profile.get("a"));
+ assertEquals("b-value", profile.get("b"));
+ assertEquals("c.d-value", profile.get("c.d"));
assertFalse(profile.isDeclaredOverridable("c.d", null));
- assertEquals("e-value-inherited1",profile.get("e"));
- assertEquals("g.d2-value-inherited1",profile.get("g.d2")); // Even though we make an explicit reference to one not having this value, we still inherit it
- assertEquals("a-value-subprofile1",profile.get("sub1.a"));
- assertEquals("c.d-value-subprofile1",profile.get("sub1.c.d"));
- assertEquals("a-value-subprofile2",profile.get("sub2.a"));
- assertEquals("c.d-value-subprofile2",profile.get("sub2.c.d"));
- assertEquals("e-value-subprofile3",profile.get("g.e"));
+ assertEquals("e-value-inherited1", profile.get("e"));
+ assertEquals("g.d2-value-inherited1", profile.get("g.d2")); // Even though we make an explicit reference to one not having this value, we still inherit it
+ assertEquals("a-value-subprofile1", profile.get("sub1.a"));
+ assertEquals("c.d-value-subprofile1", profile.get("sub1.c.d"));
+ assertEquals("a-value-subprofile2", profile.get("sub2.a"));
+ assertEquals("c.d-value-subprofile2", profile.get("sub2.c.d"));
+ assertEquals("e-value-subprofile3", profile.get("g.e"));
}
@Test
public void testBug3197426() {
- QueryProfileConfigurer configurer = new QueryProfileConfigurer("file:" + CONFIG_DIR + "bug3197426.cfg");
- CompiledQueryProfile profile = configurer.getCurrentRegistry().getComponent("default").compile(null);
+ var profile = QueryProfileConfigurer.createFromConfigId("file:" + CONFIG_DIR + "bug3197426.cfg")
+ .getComponent("default").compile(null);
+
Map<String, Object> properties = new QueryProfileProperties(profile).listProperties("source.image");
assertEquals("yes", properties.get("mlr"));
assertEquals("zh-Hant", properties.get("language"));
@@ -67,44 +64,42 @@ public class QueryProfileConfigurationTestCase {
@Test
public void testVariantConfiguration() {
- QueryProfileConfigurer configurer=
- new QueryProfileConfigurer("file:" + CONFIG_DIR + "query-profile-variants-configuration.cfg");
+ var registry = QueryProfileConfigurer.createFromConfigId("file:" + CONFIG_DIR + "query-profile-variants-configuration.cfg");
// Variant 1
- QueryProfile variants1 =configurer.getCurrentRegistry().getComponent("variants1");
- assertGet("x1.y1.a","a",new String[] { "x1","y1" }, variants1);
- assertGet("x1.y1.b","b",new String[] { "x1","y1" }, variants1);
- assertGet("x1.y?.a","a",new String[] { "x1","zz" }, variants1);
- assertGet("x?.y1.a","a",new String[] { "zz","y1" }, variants1);
- assertGet("a-deflt","a",new String[] { "z1","z2" }, variants1);
+ QueryProfile variants1 = registry.getComponent("variants1");
+ assertGet("x1.y1.a", "a", new String[] { "x1","y1" }, variants1);
+ assertGet("x1.y1.b", "b", new String[] { "x1","y1" }, variants1);
+ assertGet("x1.y?.a", "a", new String[] { "x1","zz" }, variants1);
+ assertGet("x?.y1.a", "a", new String[] { "zz","y1" }, variants1);
+ assertGet("a-deflt", "a", new String[] { "z1","z2" }, variants1);
// ...inherited
- assertGet("parent1-value","parent1",new String[] { "x1","y1" }, variants1);
- assertGet("parent2-value","parent2",new String[] { "x1","y1" }, variants1);
- assertGet(null,"parent1",new String[] { "x1","y2" }, variants1);
- assertGet(null,"parent2",new String[] { "x1","y2" }, variants1);
+ assertGet("parent1-value", "parent1", new String[] { "x1","y1" }, variants1);
+ assertGet("parent2-value", "parent2", new String[] { "x1","y1" }, variants1);
+ assertGet(null, "parent1", new String[] { "x1","y2" }, variants1);
+ assertGet(null, "parent2", new String[] { "x1","y2" }, variants1);
// Variant 2
- QueryProfile variants2 =configurer.getCurrentRegistry().getComponent("variants2");
- assertGet("variant2:y1.c","c",new String[] { "*","y1" }, variants2);
- assertGet("variant2:y2.c","c",new String[] { "*","y2" }, variants2);
- assertGet("variant2:c-df","c",new String[] { "*","z1" }, variants2);
- assertGet("variant2:c-df","c",new String[] { }, variants2);
- assertGet("variant2:c-df","c",new String[] { "*" }, variants2);
- assertGet(null, "d",new String[] { "*","y1" }, variants2);
+ QueryProfile variants2 = registry.getComponent("variants2");
+ assertGet("variant2:y1.c", "c", new String[] { "*","y1" }, variants2);
+ assertGet("variant2:y2.c", "c", new String[] { "*","y2" }, variants2);
+ assertGet("variant2:c-df", "c", new String[] { "*","z1" }, variants2);
+ assertGet("variant2:c-df", "c", new String[] { }, variants2);
+ assertGet("variant2:c-df", "c", new String[] { "*" }, variants2);
+ assertGet(null, "d", new String[] { "*","y1" }, variants2);
// Reference following from variant 1
- assertGet("variant2:y1.c","toVariants.c",new String[] { "**", "y1" } , variants1);
- assertGet("variant3:c-df","toVariants.c",new String[] { "x1", "**" } , variants1);
- assertGet("variant3:y1.c","toVariants.c",new String[] { "x1", "y1" } , variants1); // variant3 by order priority
- assertGet("variant3:y2.c","toVariants.c",new String[] { "x1", "y2" } , variants1);
+ assertGet("variant2:y1.c", "toVariants.c", new String[] { "**", "y1" } , variants1);
+ assertGet("variant3:c-df", "toVariants.c", new String[] { "x1", "**" } , variants1);
+ assertGet("variant3:y1.c", "toVariants.c", new String[] { "x1", "y1" } , variants1); // variant3 by order priority
+ assertGet("variant3:y2.c", "toVariants.c", new String[] { "x1", "y2" } , variants1);
}
@Test
public void testVariantConfigurationThroughQueryLookup() {
- QueryProfileConfigurer configurer=
- new QueryProfileConfigurer("file:" + CONFIG_DIR + "query-profile-variants-configuration.cfg");
+ var registry = QueryProfileConfigurer.createFromConfigId("file:" + CONFIG_DIR + "query-profile-variants-configuration.cfg")
+ .compile();
- CompiledQueryProfileRegistry registry = configurer.getCurrentRegistry().compile();
CompiledQueryProfile variants1 = registry.getComponent("variants1");
// Variant 1
@@ -138,10 +133,9 @@ public class QueryProfileConfigurationTestCase {
public void testVariant2ConfigurationThroughQueryLookup() {
final double delta = 0.0000001;
- QueryProfileConfigurer configurer=
- new QueryProfileConfigurer("file:" + CONFIG_DIR + "query-profile-variants2.cfg");
+ var registry = QueryProfileConfigurer.createFromConfigId("file:" + CONFIG_DIR + "query-profile-variants2.cfg")
+ .compile();
- CompiledQueryProfileRegistry registry = configurer.getCurrentRegistry().compile();
Query query = new Query(QueryTestCase.httpEncode("?query=heh&queryProfile=multi&myindex=default&myquery=lo ve&tracelevel=5"),
registry.findQueryProfile("multi"));
assertEquals("love", query.properties().get("model.queryString"));
@@ -154,11 +148,12 @@ public class QueryProfileConfigurationTestCase {
assertEquals(-30, query.getRanking().getFeatures().getDouble("query(scorelimit)").getAsDouble(), delta);
}
- private void assertGet(String expectedValue,String parameter,String[] dimensionValues,QueryProfile profile) {
- Map<String,String> context=new HashMap<>();
- for (int i=0; i<dimensionValues.length; i++)
- context.put(profile.getVariants().getDimensions().get(i),dimensionValues[i]); // Lookup dim. names to ease test...
- assertEquals("Looking up '" + parameter + "' for '" + Arrays.toString(dimensionValues) + "'",expectedValue,profile.get(parameter, context, null));
+ private void assertGet(String expectedValue, String parameter, String[] dimensionValues, QueryProfile profile) {
+ Map<String, String> context = new HashMap<>();
+ for (int i = 0; i<dimensionValues.length; i++)
+ context.put(profile.getVariants().getDimensions().get(i), dimensionValues[i]); // Lookup dim. names to ease test...
+ assertEquals("Looking up '" + parameter + "' for '" + Arrays.toString(dimensionValues) + "'",
+ expectedValue, profile.get(parameter, context, null));
}
}
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/TypedProfilesConfigurationTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/TypedProfilesConfigurationTestCase.java
index 0531d847c9e..944ee6d79ef 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/TypedProfilesConfigurationTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/TypedProfilesConfigurationTestCase.java
@@ -1,11 +1,9 @@
// Copyright Yahoo. 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.search.query.profile.QueryProfileRegistry;
import com.yahoo.search.query.profile.config.QueryProfileConfigurer;
import com.yahoo.search.query.profile.types.FieldDescription;
import com.yahoo.search.query.profile.types.QueryProfileType;
-import com.yahoo.search.query.profile.types.QueryProfileTypeRegistry;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -20,45 +18,43 @@ public class TypedProfilesConfigurationTestCase {
/** Asserts that everything is read correctly from this configuration */
@Test
public void testIt() {
- QueryProfileConfigurer configurer=
- new QueryProfileConfigurer("file:src/test/java/com/yahoo/search/query/profile/config/test/typed-profiles.cfg");
- QueryProfileRegistry registry=configurer.getCurrentRegistry();
- QueryProfileTypeRegistry types=registry.getTypeRegistry();
+ var registry = QueryProfileConfigurer.createFromConfigId("file:src/test/java/com/yahoo/search/query/profile/config/test/typed-profiles.cfg");
+ var types = registry.getTypeRegistry();
// Assert that each type was read correctly
- QueryProfileType testType=types.getComponent("testtype");
- assertEquals("testtype",testType.getId().getName());
+ QueryProfileType testType = types.getComponent("testtype");
+ assertEquals("testtype", testType.getId().getName());
assertFalse(testType.isStrict());
assertFalse(testType.getMatchAsPath());
- assertEquals(7,testType.fields().size());
- assertEquals("myString",testType.getField("myString").getName());
+ assertEquals(7, testType.fields().size());
+ assertEquals("myString", testType.getField("myString").getName());
assertTrue(testType.getField("myString").isMandatory());
assertTrue(testType.getField("myString").isOverridable());
assertFalse(testType.getField("myInteger").isMandatory());
assertFalse(testType.getField("myInteger").isOverridable());
FieldDescription field= testType.getField("myUserQueryProfile");
- assertEquals("reference to a query profile of type 'user'",field.getType().toInstanceDescription());
+ assertEquals("reference to a query profile of type 'user'", field.getType().toInstanceDescription());
assertTrue(field.getAliases().contains("myqp"));
assertTrue(field.getAliases().contains("user-profile"));
QueryProfileType testTypeStrict=types.getComponent("testtypestrict");
assertTrue(testTypeStrict.isStrict());
assertTrue(testTypeStrict.getMatchAsPath());
- assertEquals(7,testTypeStrict.fields().size());
+ assertEquals(7, testTypeStrict.fields().size());
assertEquals("reference to a query profile of type 'userstrict'",
testTypeStrict.getField("myUserQueryProfile").getType().toInstanceDescription());
QueryProfileType user=types.getComponent("user");
assertFalse(user.isStrict());
assertFalse(user.getMatchAsPath());
- assertEquals(2,user.fields().size());
- assertEquals(String.class,user.getField("myUserString").getType().getValueClass());
+ assertEquals(2, user.fields().size());
+ assertEquals(String.class, user.getField("myUserString").getType().getValueClass());
- QueryProfileType userStrict=types.getComponent("userstrict");
+ QueryProfileType userStrict = types.getComponent("userstrict");
assertTrue(userStrict.isStrict());
assertFalse(userStrict.getMatchAsPath());
- assertEquals(2,userStrict.fields().size());
+ assertEquals(2, userStrict.fields().size());
}
}