summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@verizonmedia.com>2019-09-30 12:58:59 +0200
committerJon Bratseth <bratseth@verizonmedia.com>2019-09-30 12:58:59 +0200
commit44f2ecfdaacd12062087fd91161a25cc302e6c6f (patch)
tree71bbe41d5cb5035ed2cd950b4886b1c90ee60c69
parentaa7061626f330bfb573f4afdbab8bc9ddd5ec927 (diff)
Substitute properties in trace output
-rw-r--r--container-search/src/main/java/com/yahoo/search/Query.java8
-rw-r--r--container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java4
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java8
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java25
-rw-r--r--vespajlib/src/main/java/com/yahoo/text/Text.java5
5 files changed, 36 insertions, 14 deletions
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 66a75b7092c..ca52c517bbf 100644
--- a/container-search/src/main/java/com/yahoo/search/Query.java
+++ b/container-search/src/main/java/com/yahoo/search/Query.java
@@ -464,8 +464,8 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
trace("No query profile is used", false, 1);
else
trace("Using " + profile.toString(), false, 1);
- if (traceLevel < 4) return;
+ if (traceLevel < 4) return;
StringBuilder b = new StringBuilder("Resolved properties:\n");
Set<String> mentioned = new HashSet<>();
for (Map.Entry<String,String> requestProperty : requestProperties().entrySet() ) {
@@ -495,10 +495,10 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
return httpRequest.propertyMap();
}
- private void appendQueryProfileProperties(CompiledQueryProfile profile,Set<String> mentioned,StringBuilder b) {
- for (Map.Entry<String,Object> property : profile.listValues("", requestProperties()).entrySet()) {
+ private void appendQueryProfileProperties(CompiledQueryProfile profile, Set<String> mentioned, StringBuilder b) {
+ for (Map.Entry<String,Object> property : profile.listValues(CompoundName.empty, requestProperties(), properties()).entrySet()) {
if ( ! mentioned.contains(property.getKey()))
- b.append(property.getKey()).append("=").append(property.getValue()).append(" (value from query profile)<br/>\n");
+ b.append(property.getKey()).append("=").append(property.getValue()).append(" (value from query profile)\n");
}
}
diff --git a/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java b/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java
index 1c58081e4f1..0981c6e8dad 100644
--- a/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java
+++ b/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java
@@ -353,9 +353,7 @@ public class SearchHandler extends LoggingRequestHandler {
}
}
- /**
- * For internal use only
- */
+ /** For internal use only */
public Renderer<Result> getRendererCopy(ComponentSpecification spec) {
Renderer<Result> renderer = executionFactory.rendererRegistry().getRenderer(spec);
return perRenderingCopy(renderer);
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java
index 7ac73947905..e6fedada35d 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java
@@ -102,15 +102,15 @@ public class CompiledQueryProfile extends AbstractComponent implements Cloneable
* For example, if {a.d =&gt; "a.d-value" ,a.e =&gt; "a.e-value", b.d =&gt; "b.d-value", then calling listValues("a")
* will return {"d" =&gt; "a.d-value","e" =&gt; "a.e-value"}
*/
- public final Map<String, Object> listValues(final CompoundName prefix) { return listValues(prefix, Collections.<String,String>emptyMap()); }
- public final Map<String, Object> listValues(final String prefix) { return listValues(new CompoundName(prefix)); }
+ public final Map<String, Object> listValues(CompoundName prefix) { return listValues(prefix, Collections.<String,String>emptyMap()); }
+ public final Map<String, Object> listValues(String prefix) { return listValues(new CompoundName(prefix)); }
/**
* Return all objects that start with the given prefix path. Use "" to list all.
* <p>
* For example, if {a.d =&gt; "a.d-value" ,a.e =&gt; "a.e-value", b.d =&gt; "b.d-value", then calling listValues("a")
* will return {"d" =&gt; "a.d-value","e" =&gt; "a.e-value"}
*/
- public final Map<String, Object> listValues(final String prefix,Map<String, String> context) {
+ public final Map<String, Object> listValues(String prefix, Map<String, String> context) {
return listValues(new CompoundName(prefix), context);
}
/**
@@ -119,7 +119,7 @@ public class CompiledQueryProfile extends AbstractComponent implements Cloneable
* For example, if {a.d =&gt; "a.d-value" ,a.e =&gt; "a.e-value", b.d =&gt; "b.d-value", then calling listValues("a")
* will return {"d" =&gt; "a.d-value","e" =&gt; "a.e-value"}
*/
- public final Map<String, Object> listValues(final CompoundName prefix,Map<String, String> context) {
+ public final Map<String, Object> listValues(CompoundName prefix, Map<String, String> context) {
return listValues(prefix, context, null);
}
/**
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java
index 46dbac859a2..18329a817a5 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java
@@ -9,6 +9,7 @@ import com.yahoo.search.query.profile.BackedOverridableQueryProfile;
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.yolean.trace.TraceNode;
import org.junit.Test;
import java.util.Arrays;
@@ -18,6 +19,7 @@ import java.util.Map;
import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
* @author bratseth
@@ -68,6 +70,21 @@ public class QueryProfileVariantsTestCase {
}
@Test
+ public void testVariantSubstitution() {
+ QueryProfile profile = new QueryProfile("test");
+ profile.setDimensions(new String[] { "langReg", "region", "site" });
+ profile.set("property", "%{site}", null);
+ profile.set("property", "fp", new String[] { null, null, "frontpage"}, null);
+ profile.set("streams", "ntk_stream_fresh", new String[] { "en-GB", "GB" }, null);
+ CompiledQueryProfile cProfile = profile.compile(null);
+
+ Query query = new Query("?langReg=en-GB&region=GB&site=frontpage&tracelevel=4", cProfile);
+ assertEquals("frontpage", query.properties().get("property"));
+ assertEquals("ntk_stream_fresh", query.properties().get("streams"));
+ assertTrue(traceContains("property=frontpage", query));
+ }
+
+ @Test
public void testInheritedVariants() {
QueryProfile parent = new QueryProfile("parent");
parent.setDimensions(new String[] { "parentDim" });
@@ -1147,4 +1164,12 @@ public class QueryProfileVariantsTestCase {
return context;
}
+ // NB: NOT RECURSIVE
+ private boolean traceContains(String string, Query query) {
+ for (TraceNode node : query.getContext(true).getTrace().traceNode().children())
+ if (node.payload().toString().contains(string))
+ return true;
+ return false;
+ }
+
}
diff --git a/vespajlib/src/main/java/com/yahoo/text/Text.java b/vespajlib/src/main/java/com/yahoo/text/Text.java
index 0acb2407e68..706fd1583a3 100644
--- a/vespajlib/src/main/java/com/yahoo/text/Text.java
+++ b/vespajlib/src/main/java/com/yahoo/text/Text.java
@@ -143,9 +143,8 @@ public final class Text {
sb.append(' ');
return sb;
}
- /**
- * Returns a string where any invalid characters in the input string is replaced by spaces
- */
+
+ /** Returns a string where any invalid characters in the input string is replaced by spaces */
public static String stripInvalidCharacters(String string) {
StringBuilder stripped = null; // lazy, as most string will not need stripping
for (int i = 0; i < string.length();) {