summaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
Diffstat (limited to 'container-search')
-rw-r--r--container-search/abi-spec.json1
-rw-r--r--container-search/src/main/java/com/yahoo/search/Query.java23
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java24
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java7
4 files changed, 38 insertions, 17 deletions
diff --git a/container-search/abi-spec.json b/container-search/abi-spec.json
index 61338ed3b3a..06713d14d88 100644
--- a/container-search/abi-spec.json
+++ b/container-search/abi-spec.json
@@ -6141,6 +6141,7 @@
"public void <init>(java.lang.String)",
"public void <init>(com.yahoo.component.ComponentId)",
"public com.yahoo.search.query.profile.types.QueryProfileType unfrozen()",
+ "public com.yahoo.processing.request.CompoundName getComponentIdAsCompoundName()",
"public void setBuiltin(boolean)",
"public boolean isBuiltin()",
"public java.util.List inherited()",
diff --git a/container-search/src/main/java/com/yahoo/search/Query.java b/container-search/src/main/java/com/yahoo/search/Query.java
index 766af8f05fd..7105ba8c7ad 100644
--- a/container-search/src/main/java/com/yahoo/search/Query.java
+++ b/container-search/src/main/java/com/yahoo/search/Query.java
@@ -236,15 +236,16 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
propertyAliases = ImmutableMap.copyOf(propertyAliasesBuilder);
}
private static void addAliases(QueryProfileType arguments, Map<String, CompoundName> aliases) {
- String prefix = getPrefix(arguments);
+ CompoundName prefix = getPrefix(arguments);
for (FieldDescription field : arguments.fields().values()) {
for (String alias : field.getAliases())
- aliases.put(alias, new CompoundName(prefix+field.getName()));
+ aliases.put(alias, prefix.append(field.getName()));
}
}
- private static String getPrefix(QueryProfileType type) {
- if (type.getId().getName().equals("native")) return ""; // The arguments of this directly
- return type.getId().getName() + ".";
+
+ private static CompoundName getPrefix(QueryProfileType type) {
+ if (type.getId().getName().equals("native")) return CompoundName.empty; // The arguments of this directly
+ return type.getComponentIdAsCompoundName();
}
public static void addNativeQueryProfileTypesTo(QueryProfileTypeRegistry registry) {
@@ -391,22 +392,22 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
* dependent objects for the appropriate subset of the given property values
*/
private void setFieldsFrom(Properties properties, Map<String, String> context) {
- setFrom("", properties, Query.getArgumentType(), context);
+ setFrom(CompoundName.empty, properties, Query.getArgumentType(), context);
}
/**
* For each field in the given query profile type, take the corresponding value from originalProperties
* (if any) set it to properties(), recursively.
*/
- private void setFrom(String prefix, Properties originalProperties, QueryProfileType arguments, Map<String, String> context) {
- prefix = prefix + getPrefix(arguments);
+ private void setFrom(CompoundName prefix, Properties originalProperties, QueryProfileType arguments, Map<String, String> context) {
+ prefix = prefix.append(getPrefix(arguments));
for (FieldDescription field : arguments.fields().values()) {
if (field.getType() == FieldType.genericQueryProfileType) { // Generic map
- CompoundName fullName = new CompoundName(prefix + field.getName());
+ CompoundName fullName = prefix.append(field.getName());
for (Map.Entry<String, Object> entry : originalProperties.listProperties(fullName, context).entrySet()) {
try {
- properties().set(fullName + "." + entry.getKey(), entry.getValue(), context);
+ properties().set(fullName.append(entry.getKey()), entry.getValue(), context);
} catch (IllegalArgumentException e) {
throw new QueryException("Invalid request parameter", e);
}
@@ -416,7 +417,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
setFrom(prefix, originalProperties, ((QueryProfileFieldType)field.getType()).getQueryProfileType(), context);
}
else {
- CompoundName fullName = new CompoundName(prefix + field.getName());
+ CompoundName fullName = prefix.append(field.getName());
Object value = originalProperties.get(fullName, context);
if (value != null) {
try {
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java b/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java
index 2ec3df4a976..07c9e4475ec 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java
@@ -8,7 +8,11 @@ import com.yahoo.component.provider.FreezableSimpleComponent;
import com.yahoo.processing.request.CompoundName;
import com.yahoo.search.query.profile.QueryProfile;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import static com.yahoo.text.Lowercase.toLowerCase;
@@ -19,11 +23,12 @@ import static com.yahoo.text.Lowercase.toLowerCase;
*/
public class QueryProfileType extends FreezableSimpleComponent {
+ private final CompoundName componentIdAsCompoundName;
/** The fields of this query profile type */
- private Map<String, FieldDescription> fields = new HashMap<>();
+ private Map<String, FieldDescription> fields;
/** The query profile types this inherits */
- private List<QueryProfileType> inherited = new ArrayList<>();
+ private List<QueryProfileType> inherited;
/** If this is true, keys which are not declared in this type cannot be set in instances */
private boolean strict = false;
@@ -41,15 +46,20 @@ public class QueryProfileType extends FreezableSimpleComponent {
}
public QueryProfileType(ComponentId id) {
+ this(id, new HashMap<>(), new ArrayList<>());
+ }
+
+ private QueryProfileType(ComponentId id, Map<String, FieldDescription> fields, List<QueryProfileType> inherited) {
super(id);
QueryProfile.validateName(id.getName());
+ componentIdAsCompoundName = new CompoundName(getId().getName());
+ this.fields = fields;
+ this.inherited = inherited;
}
private QueryProfileType(ComponentId id, Map<String, FieldDescription> fields, List<QueryProfileType> inherited,
boolean strict, boolean matchAsPath, boolean builtin, Map<String,String> aliases) {
- super(id);
- this.fields = new HashMap<>(fields);
- this.inherited = new ArrayList<>(inherited);
+ this(id, new HashMap<>(fields), new ArrayList<>(inherited));
this.strict = strict;
this.matchAsPath = matchAsPath;
this.builtin = builtin;
@@ -84,6 +94,8 @@ public class QueryProfileType extends FreezableSimpleComponent {
return new QueryProfileType(getId(), unfrozenFields, unfrozenInherited, strict, matchAsPath, builtin, aliases);
}
+ public CompoundName getComponentIdAsCompoundName() { return componentIdAsCompoundName; }
+
/** Mark this type as built into the system. Do not use */
public void setBuiltin(boolean builtin) { this.builtin=builtin; }
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java
index da457dba3b0..2a62cfec507 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java
@@ -1,6 +1,7 @@
// 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.types.test;
+import com.yahoo.processing.request.CompoundName;
import com.yahoo.search.query.profile.QueryProfileRegistry;
import com.yahoo.yolean.Exceptions;
import com.yahoo.search.query.profile.QueryProfile;
@@ -52,6 +53,12 @@ public class NameTestCase {
"Illegal name '-some-other'");
}
+ @Test
+ public void testComponentIdAsCompoundName() {
+ String name = "a/b";
+ assertEquals(new CompoundName(name), new QueryProfileType(name).getComponentIdAsCompoundName());
+ }
+
private void assertLegalName(String name) {
new QueryProfile(name);
new QueryProfileType(name);