summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2019-01-08 10:26:06 +0100
committerJon Bratseth <bratseth@oath.com>2019-01-08 10:26:06 +0100
commit89a35afd50c74a738ed160eae03d8f6384af6834 (patch)
treecbd983878eac733fbfa623f17c5dc7076b1c4269
parent8191ade44977f2874d60fc6811bbb9427a60510d (diff)
Include queryProfile as a regular parameter
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDirectory.java2
-rw-r--r--container-search/src/main/java/com/yahoo/search/Query.java28
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/SubstituteString.java40
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileIntegrationTestCase.java2
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileSubstitutionTestCase.java40
-rw-r--r--container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java43
6 files changed, 83 insertions, 72 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDirectory.java b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDirectory.java
index 2a8abacd24e..d8d510ac469 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDirectory.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDirectory.java
@@ -23,6 +23,7 @@ import java.nio.file.attribute.BasicFileAttributes;
import java.util.logging.Logger;
public class FileDirectory {
+
private static final Logger log = Logger.getLogger(FileDirectory.class.getName());
private final File root;
@@ -77,6 +78,7 @@ public class FileDirectory {
}
private Long computeHash(File file) throws IOException {
+ if (1==1) return 1L;
XXHash64 hasher = XXHashFactory.fastestInstance().hash64();
if (file.isDirectory()) {
return Files.walk(file.toPath(), 100).map(path -> {
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 8e5e14a3aac..3159bfc4658 100644
--- a/container-search/src/main/java/com/yahoo/search/Query.java
+++ b/container-search/src/main/java/com/yahoo/search/Query.java
@@ -187,6 +187,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
public static final CompoundName OFFSET = new CompoundName("offset");
public static final CompoundName HITS = new CompoundName("hits");
+ public static final CompoundName QUERY_PROFILE = new CompoundName("queryProfile");
public static final CompoundName SEARCH_CHAIN = new CompoundName("searchChain");
public static final CompoundName TRACE_LEVEL = new CompoundName("traceLevel");
public static final CompoundName NO_CACHE = new CompoundName("noCache");
@@ -202,6 +203,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
argumentType.addField(new FieldDescription(OFFSET.toString(), "integer", "offset start"));
argumentType.addField(new FieldDescription(HITS.toString(), "integer", "hits count"));
// TODO: Should this be added to com.yahoo.search.query.properties.QueryProperties? If not, why not?
+ argumentType.addField(new FieldDescription(QUERY_PROFILE.toString(), "string"));
argumentType.addField(new FieldDescription(SEARCH_CHAIN.toString(), "string"));
argumentType.addField(new FieldDescription(TRACE_LEVEL.toString(), "integer", "tracelevel"));
argumentType.addField(new FieldDescription(NO_CACHE.toString(), "boolean", "nocache"));
@@ -411,10 +413,10 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
}
}
} else {
- Object value=originalProperties.get(fullName,context);
- if (value!=null) {
+ Object value = originalProperties.get(fullName,context);
+ if (value != null) {
try {
- properties().set(fullName,value,context);
+ properties().set(fullName, value, context);
} catch (IllegalArgumentException e) {
throw new QueryException("Invalid request parameter", e);
}
@@ -427,7 +429,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
private void setPropertiesFromRequestMap(Map<String, String> requestMap, Properties properties) {
for (Map.Entry<String, String> entry : requestMap.entrySet()) {
try {
- if (entry.getKey().equals("queryProfile")) continue;
+ //if (entry.getKey().equals("queryProfile")) continue;
properties.set(entry.getKey(), entry.getValue(), requestMap);
}
catch (IllegalArgumentException e) {
@@ -446,12 +448,12 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
*/
private void traceProperties() {
if (traceLevel == 0) return;
- CompiledQueryProfile profile=null;
- QueryProfileProperties profileProperties=properties().getInstance(QueryProfileProperties.class);
- if (profileProperties!=null)
- profile=profileProperties.getQueryProfile();
+ CompiledQueryProfile profile = null;
+ QueryProfileProperties profileProperties = properties().getInstance(QueryProfileProperties.class);
+ if (profileProperties != null)
+ profile = profileProperties.getQueryProfile();
- if (profile==null)
+ if (profile == null)
trace("No query profile is used", false, 1);
else
trace("Using " + profile.toString(), false, 1);
@@ -466,7 +468,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
b.append(requestProperty.getKey());
b.append("=");
- b.append(String.valueOf(resolvedValue)); // (may be null)
+ b.append(resolvedValue); // (may be null)
b.append(" (");
if (profile != null && ! profile.isOverridable(new CompoundName(requestProperty.getKey()), requestProperties()))
@@ -476,8 +478,8 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
b.append(")\n");
mentioned.add(requestProperty.getKey());
}
- if (profile!=null) {
- appendQueryProfileProperties(profile,mentioned,b);
+ if (profile != null) {
+ appendQueryProfileProperties(profile, mentioned, b);
}
trace(b.toString(),false,4);
}
@@ -487,7 +489,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
}
private void appendQueryProfileProperties(CompiledQueryProfile profile,Set<String> mentioned,StringBuilder b) {
- for (Map.Entry<String,Object> property : profile.listValues("",requestProperties()).entrySet()) {
+ for (Map.Entry<String,Object> property : profile.listValues("", requestProperties()).entrySet()) {
if ( ! mentioned.contains(property.getKey()))
b.append(property.getKey() + "=" + property.getValue() + " (value from query profile)<br/>\n");
}
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/SubstituteString.java b/container-search/src/main/java/com/yahoo/search/query/profile/SubstituteString.java
index 36b38ad8d03..3252f0f4662 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/SubstituteString.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/SubstituteString.java
@@ -27,23 +27,23 @@ public class SubstituteString {
* Returns a new SubstituteString if the given string contains substitutions, null otherwise.
*/
public static SubstituteString create(String value) {
- int lastEnd=0;
- int start=value.indexOf("%{");
- if (start<0) return null; // Shortcut
- List<Component> components=new ArrayList<>();
- while (start>=0) {
- int end=value.indexOf("}",start+2);
- if (end<0)
+ int lastEnd = 0;
+ int start = value.indexOf("%{");
+ if (start < 0) return null; // Shortcut
+ List<Component> components = new ArrayList<>();
+ while (start >= 0) {
+ int end = value.indexOf("}", start + 2);
+ if (end < 0)
throw new IllegalArgumentException("Unterminated value substitution '" + value.substring(start) + "'");
- String propertyName=value.substring(start+2,end);
- if (propertyName.indexOf("%{")>=0)
+ String propertyName = value.substring(start+2,end);
+ if (propertyName.indexOf("%{") >= 0)
throw new IllegalArgumentException("Unterminated value substitution '" + value.substring(start) + "'");
- components.add(new StringComponent(value.substring(lastEnd,start)));
+ components.add(new StringComponent(value.substring(lastEnd, start)));
components.add(new PropertyComponent(propertyName));
- lastEnd=end+1;
- start=value.indexOf("%{",lastEnd);
+ lastEnd = end+1;
+ start = value.indexOf("%{", lastEnd);
}
- components.add(new StringComponent(value.substring(lastEnd,value.length())));
+ components.add(new StringComponent(value.substring(lastEnd)));
return new SubstituteString(components, value);
}
@@ -83,7 +83,7 @@ public class SubstituteString {
private abstract static class Component {
- protected abstract String getValue(Map<String,String> context,Properties substitution);
+ protected abstract String getValue(Map<String, String> context, Properties substitution);
}
@@ -92,11 +92,11 @@ public class SubstituteString {
private final String value;
public StringComponent(String value) {
- this.value=value;
+ this.value = value;
}
@Override
- public String getValue(Map<String,String> context,Properties substitution) {
+ public String getValue(Map<String, String> context, Properties substitution) {
return value;
}
@@ -112,13 +112,13 @@ public class SubstituteString {
private final String propertyName;
public PropertyComponent(String propertyName) {
- this.propertyName=propertyName;
+ this.propertyName = propertyName;
}
@Override
- public String getValue(Map<String,String> context,Properties substitution) {
- Object value=substitution.get(propertyName,context,substitution);
- if (value==null) return "";
+ public String getValue(Map<String,String> context, Properties substitution) {
+ Object value = substitution.get(propertyName, context, substitution);
+ if (value == null) return "";
return String.valueOf(value);
}
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileIntegrationTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileIntegrationTestCase.java
index 67fb5da10a0..67d22fba4a3 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileIntegrationTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileIntegrationTestCase.java
@@ -80,7 +80,7 @@ public class QueryProfileIntegrationTestCase {
System.setProperty("config.id", configId);
Container container = new Container();
HandlersConfigurerTestWrapper configurer = new HandlersConfigurerTestWrapper(container, configId);
- SearchHandler searchHandler = (SearchHandler) configurer.getRequestHandlerRegistry().getComponent(SearchHandler.class.getName());
+ SearchHandler searchHandler = (SearchHandler)configurer.getRequestHandlerRegistry().getComponent(SearchHandler.class.getName());
// Should get "default" query profile containing the "test" search chain containing the "test" searcher
HttpRequest request = HttpRequest.createTestRequest("search", Method.GET);
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileSubstitutionTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileSubstitutionTestCase.java
index 7ff120ddc70..9a0063e7f07 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileSubstitutionTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileSubstitutionTestCase.java
@@ -19,7 +19,7 @@ public class QueryProfileSubstitutionTestCase {
@Test
public void testSingleSubstitution() {
- QueryProfile p=new QueryProfile("test");
+ QueryProfile p = new QueryProfile("test");
p.set("message","Hello %{world}!", null);
p.set("world", "world", null);
assertEquals("Hello world!",p.compile(null).get("message"));
@@ -27,7 +27,7 @@ public class QueryProfileSubstitutionTestCase {
QueryProfile p2=new QueryProfile("test2");
p2.addInherited(p);
p2.set("world", "universe", null);
- assertEquals("Hello universe!",p2.compile(null).get("message"));
+ assertEquals("Hello universe!", p2.compile(null).get("message"));
}
@Test
@@ -39,16 +39,16 @@ public class QueryProfileSubstitutionTestCase {
p.set("exclamation","?", null);
assertEquals("Hola local group?",p.compile(null).get("message"));
- QueryProfile p2=new QueryProfile("test2");
+ QueryProfile p2 = new QueryProfile("test2");
p2.addInherited(p);
p2.set("entity","milky way", null);
- assertEquals("Hola milky way?",p2.compile(null).get("message"));
+ assertEquals("Hola milky way?", p2.compile(null).get("message"));
}
@Test
public void testUnclosedSubstitution1() {
try {
- QueryProfile p=new QueryProfile("test");
+ QueryProfile p = new QueryProfile("test");
p.set("message1","%{greeting} %{entity}%{exclamation", null);
fail("Should have produced an exception");
}
@@ -61,7 +61,7 @@ public class QueryProfileSubstitutionTestCase {
@Test
public void testUnclosedSubstitution2() {
try {
- QueryProfile p=new QueryProfile("test");
+ QueryProfile p = new QueryProfile("test");
p.set("message1","%{greeting} %{entity%{exclamation}", null);
fail("Should have produced an exception");
}
@@ -73,26 +73,26 @@ public class QueryProfileSubstitutionTestCase {
@Test
public void testNullSubstitution() {
- QueryProfile p=new QueryProfile("test");
+ QueryProfile p = new QueryProfile("test");
p.set("message","%{greeting} %{entity}%{exclamation}", null);
p.set("greeting","Hola", null);
assertEquals("Hola ", p.compile(null).get("message"));
- QueryProfile p2=new QueryProfile("test2");
+ QueryProfile p2 = new QueryProfile("test2");
p2.addInherited(p);
p2.set("greeting","Hola", null);
p2.set("exclamation", "?", null);
- assertEquals("Hola ?",p2.compile(null).get("message"));
+ assertEquals("Hola ?", p2.compile(null).get("message"));
}
@Test
public void testNoOverridingOfPropertiesSetAtRuntime() {
- QueryProfile p=new QueryProfile("test");
+ QueryProfile p = new QueryProfile("test");
p.set("message","Hello %{world}!", null);
p.set("world","world", null);
p.freeze();
- Properties runtime=new QueryProfileProperties(p.compile(null));
+ Properties runtime = new QueryProfileProperties(p.compile(null));
runtime.set("runtimeMessage","Hello %{world}!");
assertEquals("Hello world!", runtime.get("message"));
assertEquals("Hello %{world}!",runtime.get("runtimeMessage"));
@@ -100,18 +100,18 @@ public class QueryProfileSubstitutionTestCase {
@Test
public void testButPropertiesSetAtRuntimeAreUsedInSubstitutions() {
- QueryProfile p=new QueryProfile("test");
- p.set("message","Hello %{world}!", null);
- p.set("world","world", null);
+ QueryProfile p = new QueryProfile("test");
+ p.set("message", "Hello %{world}!", null);
+ p.set("world", "world", null);
- Properties runtime=new QueryProfileProperties(p.compile(null));
- runtime.set("world","Earth");
- assertEquals("Hello Earth!",runtime.get("message"));
+ Properties runtime = new QueryProfileProperties(p.compile(null));
+ runtime.set("world", "Earth");
+ assertEquals("Hello Earth!", runtime.get("message"));
}
@Test
public void testInspection() {
- QueryProfile p=new QueryProfile("test");
+ QueryProfile p = new QueryProfile("test");
p.set("message", "%{greeting} %{entity}%{exclamation}", null);
assertEquals("message","%{greeting} %{entity}%{exclamation}",
p.declaredContent().entrySet().iterator().next().getValue().toString());
@@ -119,7 +119,7 @@ public class QueryProfileSubstitutionTestCase {
@Test
public void testVariants() {
- QueryProfile p=new QueryProfile("test");
+ QueryProfile p = new QueryProfile("test");
p.set("message","Hello %{world}!", null);
p.set("world","world", null);
p.setDimensions(new String[] {"x"});
@@ -134,7 +134,7 @@ public class QueryProfileSubstitutionTestCase {
@Test
public void testRecursion() {
- QueryProfile p=new QueryProfile("test");
+ QueryProfile p = new QueryProfile("test");
p.set("message","Hello %{world}!", null);
p.set("world","sol planet number %{number}", null);
p.set("number",3, null);
diff --git a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java
index e60d84db3d0..ce48d000ce8 100644
--- a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java
@@ -301,10 +301,10 @@ public class QueryTestCase {
@Test
public void testTimeoutInRequestOverridesQueryProfile() {
- QueryProfile profile = new QueryProfile("test");
- profile.set("timeout", 318, (QueryProfileRegistry)null);
- Query q = new Query(QueryTestCase.httpEncode("/search?timeout=500"), profile.compile(null));
- assertEquals(500000L, q.getTimeout());
+ QueryProfile profile = new QueryProfile("myProfile");
+ profile.set("myField", "Profile: %{queryProfile}", null);
+ Query q = new Query(QueryTestCase.httpEncode("/search?queryProfile=myProfile"), profile.compile(null));
+ assertEquals("Profile: myProfile", q.properties().get("myField"));
}
@Test
@@ -332,6 +332,20 @@ public class QueryTestCase {
}
@Test
+ public void testQueryProfileInSubstitution() {
+ QueryProfile testProfile = new QueryProfile("test");
+ testProfile.setOverridable("u", false, null);
+ testProfile.set("d","e", null);
+ testProfile.set("u","11", null);
+ testProfile.set("foo.bar", "wiz", null);
+ Query q = new Query(QueryTestCase.httpEncode("?query=a:>5&a=b&traceLevel=5&sources=a,b&u=12&foo.bar2=wiz2&c.d=foo&queryProfile=test"),testProfile.compile(null));
+ String trace = q.getContext(false).getTrace().toString();
+ String[] traceLines = trace.split("\n");
+ for (String line : traceLines)
+ System.out.println(line);
+ }
+
+ @Test
public void testDefaultIndex() {
Query q = new Query("?query=hi%20hello%20keyword:kanoo%20" +
"default:munkz%20%22phrases+too%22&default-index=def");
@@ -385,18 +399,15 @@ public class QueryTestCase {
}
public class TestClass {
+
private int testInt = 0;
- public int getTestInt() {
- return testInt;
- }
- public void setTestInt(int testInt) {
- this.testInt = testInt;
- }
+ public int getTestInt() { return testInt; }
+
+ public void setTestInt(int testInt) { this.testInt = testInt; }
+
+ public void setTestInt(String testInt) { this.testInt = Integer.parseInt(testInt); }
- public void setTestInt(String testInt) {
- this.testInt = Integer.parseInt(testInt);
- }
}
@Test
@@ -431,7 +442,6 @@ public class QueryTestCase {
Set<String> traces = new HashSet<>();
for (String trace : q.getContext(true).getTrace().traceNode().descendants(String.class))
traces.add(trace);
- // for (String s : traces) System.out.println(s);
assertTrue(traces.contains("trace1: [select * from sources * where default contains \"foo\";]"));
assertTrue(traces.contains("trace2"));
assertTrue(traces.contains("trace3-1, trace3-2: [select * from sources * where default contains \"foo\";]"));
@@ -444,9 +454,8 @@ public class QueryTestCase {
assertEquals(2, q.getTraceLevel());
q.trace(false,2, "trace2 ", null);
Set<String> traces = new HashSet<>();
- for (String trace : q.getContext(true).getTrace().traceNode().descendants(String.class)) {
+ for (String trace : q.getContext(true).getTrace().traceNode().descendants(String.class))
traces.add(trace);
- }
assertTrue(traces.contains("trace2 null"));
}
@@ -460,8 +469,6 @@ public class QueryTestCase {
Query q = new Query(QueryTestCase.httpEncode("?query=a:>5&a=b&traceLevel=5&sources=a,b&u=12&foo.bar2=wiz2&c.d=foo&queryProfile=test"),testProfile.compile(null));
String trace = q.getContext(false).getTrace().toString();
String[] traceLines = trace.split("\n");
- for (String line : traceLines)
- System.out.println(line);
assertTrue(contains("query=a:>5 (value from request)", traceLines));
assertTrue(contains("traceLevel=5 (value from request)", traceLines));
assertTrue(contains("a=b (value from request)", traceLines));