aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2020-07-03 13:43:27 +0200
committerJon Bratseth <bratseth@gmail.com>2020-07-03 13:43:27 +0200
commit25367bc45e5accc2d93ad9559e740ca317c0cf4a (patch)
tree821335b66c4dfb34d9f43d6fd53ad85fe2465c72
parent566d9a7d5cf2df8e3a0746522c5f0936977a3b8f (diff)
Value nodes have priority over non-value nodes
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/AllValuesQueryProfileVisitor.java6
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java12
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/config/test/inheritance/child.xml6
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/config/test/inheritance/parent.xml7
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/types/test/MandatoryTestCase.java2
5 files changed, 30 insertions, 3 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/AllValuesQueryProfileVisitor.java b/container-search/src/main/java/com/yahoo/search/query/profile/AllValuesQueryProfileVisitor.java
index 2b61dc4c0a6..3c336c80d37 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/AllValuesQueryProfileVisitor.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/AllValuesQueryProfileVisitor.java
@@ -47,7 +47,11 @@ final class AllValuesQueryProfileVisitor extends PrefixQueryProfileVisitor {
DimensionValues variant,
DimensionBinding binding) {
CompoundName fullName = currentPrefix.append(key);
- if (values.containsKey(fullName.toString())) return; // The first value encountered has priority
+
+ ValueWithSource existing = values.get(fullName.toString());
+
+ // The first value encountered has priority and values have priority over profiles
+ if (existing != null && (existing.value() != null || value == null)) return;
Boolean isOverridable = owner != null ? owner.isLocalOverridable(key, binding) : null;
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java
index 06434da2478..e85940278e3 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java
@@ -14,6 +14,7 @@ import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry;
import com.yahoo.search.query.profile.config.QueryProfileXMLReader;
import com.yahoo.search.query.profile.types.FieldDescription;
import com.yahoo.search.query.profile.types.QueryProfileType;
+import org.junit.Ignore;
import org.junit.Test;
import java.util.HashMap;
@@ -31,6 +32,17 @@ import static org.junit.Assert.fail;
public class XmlReadingTestCase {
@Test
+ public void testInheritance() {
+ QueryProfileRegistry registry =
+ new QueryProfileXMLReader().read("src/test/java/com/yahoo/search/query/profile/config/test/inheritance");
+
+ CompiledQueryProfile cProfile = registry.getComponent("child").compile(null);
+ Query q = new Query("?query=foo", cProfile);
+ assertEquals("a.b-parent", q.properties().getString("a.b"));
+ assertEquals("d-parent", q.properties().getString("d"));
+ }
+
+ @Test
public void testValid() {
QueryProfileRegistry registry=
new QueryProfileXMLReader().read("src/test/java/com/yahoo/search/query/profile/config/test/validxml");
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/inheritance/child.xml b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/inheritance/child.xml
new file mode 100644
index 00000000000..64dd3b787ac
--- /dev/null
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/inheritance/child.xml
@@ -0,0 +1,6 @@
+<!-- Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
+<query-profile id="child" inherits="parent">
+ <field name="a.b.c">a.b.c-child</field>
+ <field name="d.e.f">d.e.f-child</field>
+</query-profile>
+
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/inheritance/parent.xml b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/inheritance/parent.xml
new file mode 100644
index 00000000000..b3443fab646
--- /dev/null
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/inheritance/parent.xml
@@ -0,0 +1,7 @@
+<!-- Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
+<query-profile id="parent">
+ <field name="a.b">a.b-parent</field>
+ <field name="a.b.c">a.b.c-parent</field>
+ <field name="d">d-parent</field>
+ <field name="d.e.f">d.e.f-parent</field>
+</query-profile>
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/MandatoryTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/MandatoryTestCase.java
index 7dc6eb3d8aa..b875c66735b 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/MandatoryTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/MandatoryTestCase.java
@@ -230,7 +230,6 @@ public class MandatoryTestCase {
defaultProfile.setType(fixture.rootType);
QueryProfile mandatoryProfile = new QueryProfile("mandatory");
- mandatoryProfile.setType(fixture.rootType);
mandatoryProfile.setType(fixture.mandatoryType);
fixture.registry.register(defaultProfile);
@@ -249,7 +248,6 @@ public class MandatoryTestCase {
defaultProfile.setType(fixture.rootType);
QueryProfile mandatoryProfile = new QueryProfile("mandatory");
- mandatoryProfile.setType(fixture.rootType);
mandatoryProfile.addInherited(defaultProfile); // The single difference from the test above
mandatoryProfile.setType(fixture.mandatoryType);