summaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2019-01-25 16:08:02 +0100
committerGitHub <noreply@github.com>2019-01-25 16:08:02 +0100
commit63bf575a90afb7f9888aeca260704989da47e726 (patch)
tree965efaf626317ec8479fd111bd21746f947c63d1 /container-search
parent512d60bd0d34e52dace3776902b4da5cb1e06561 (diff)
parent9b74bd11fa8afff6523c5946ac62c84f09a59b85 (diff)
Merge pull request #8226 from vespa-engine/bratseth/map-query-model-locale-to-query-property
Map locale to a query property
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/Model.java4
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java3
-rw-r--r--container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java25
4 files changed, 27 insertions, 6 deletions
diff --git a/container-search/abi-spec.json b/container-search/abi-spec.json
index e37836a5f06..e402adbaeb9 100644
--- a/container-search/abi-spec.json
+++ b/container-search/abi-spec.json
@@ -4934,6 +4934,7 @@
"public static final java.lang.String FILTER",
"public static final java.lang.String DEFAULT_INDEX",
"public static final java.lang.String LANGUAGE",
+ "public static final java.lang.String LOCALE",
"public static final java.lang.String ENCODING",
"public static final java.lang.String SOURCES",
"public static final java.lang.String SEARCH_PATH",
diff --git a/container-search/src/main/java/com/yahoo/search/query/Model.java b/container-search/src/main/java/com/yahoo/search/query/Model.java
index 28b605fa095..f01951047d0 100644
--- a/container-search/src/main/java/com/yahoo/search/query/Model.java
+++ b/container-search/src/main/java/com/yahoo/search/query/Model.java
@@ -46,6 +46,7 @@ public class Model implements Cloneable {
public static final String FILTER = "filter";
public static final String DEFAULT_INDEX = "defaultIndex";
public static final String LANGUAGE = "language";
+ public static final String LOCALE = "locale";
public static final String ENCODING = "encoding";
public static final String SOURCES = "sources";
public static final String SEARCH_PATH = "searchPath";
@@ -61,6 +62,7 @@ public class Model implements Cloneable {
argumentType.addField(new FieldDescription(FILTER, "string","filter"));
argumentType.addField(new FieldDescription(DEFAULT_INDEX, "string", "default-index"));
argumentType.addField(new FieldDescription(LANGUAGE, "string", "language lang"));
+ argumentType.addField(new FieldDescription(LOCALE, "string", "locale"));
argumentType.addField(new FieldDescription(ENCODING, "string", "encoding"));
argumentType.addField(new FieldDescription(SOURCES, "string", "sources search"));
argumentType.addField(new FieldDescription(SEARCH_PATH, "string", "searchpath"));
@@ -72,7 +74,7 @@ public class Model implements Cloneable {
public static QueryProfileType getArgumentType() { return argumentType; }
/** The name of the query property used for generating hit count estimate queries. */
- public static final CompoundName ESTIMATE = new CompoundName("hitcountestimate"); // TODO:Cleanup
+ public static final CompoundName ESTIMATE = new CompoundName("hitcountestimate"); // TODO: Cleanup
private String encoding = null;
private String queryString = "";
diff --git a/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java b/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java
index 9e043bc3dc9..ac0e715abd2 100644
--- a/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java
+++ b/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java
@@ -53,6 +53,7 @@ public class QueryProperties extends Properties {
if (key.last().equals(Model.FILTER)) return model.getFilter();
if (key.last().equals(Model.DEFAULT_INDEX)) return model.getDefaultIndex();
if (key.last().equals(Model.LANGUAGE)) return model.getLanguage();
+ if (key.last().equals(Model.LOCALE)) return model.getLocale();
if (key.last().equals(Model.ENCODING)) return model.getEncoding();
if (key.last().equals(Model.SOURCES)) return model.getSources();
if (key.last().equals(Model.SEARCH_PATH)) return model.getSearchPath();
@@ -154,6 +155,8 @@ public class QueryProperties extends Properties {
model.setDefaultIndex(asString(value, ""));
else if (key.last().equals(Model.LANGUAGE))
model.setLanguage(asString(value, ""));
+ else if (key.last().equals(Model.LOCALE))
+ model.setLocale(asString(value, ""));
else if (key.last().equals(Model.ENCODING))
model.setEncoding(asString(value,""));
else if (key.last().equals(Model.SEARCH_PATH))
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 a5c46fc7887..93299a5f589 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
@@ -21,10 +21,8 @@ import com.yahoo.prelude.query.Highlight;
import com.yahoo.prelude.query.IndexedItem;
import com.yahoo.prelude.query.IntItem;
import com.yahoo.prelude.query.Item;
-import com.yahoo.prelude.query.Limit;
import com.yahoo.prelude.query.OrItem;
import com.yahoo.prelude.query.QueryException;
-import com.yahoo.prelude.query.RangeItem;
import com.yahoo.prelude.query.RankItem;
import com.yahoo.prelude.query.WordItem;
import com.yahoo.processing.request.CompoundName;
@@ -41,7 +39,6 @@ import com.yahoo.yolean.Exceptions;
import org.junit.Ignore;
import org.junit.Test;
-import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
@@ -102,7 +99,7 @@ public class QueryTestCase {
// TODO: YQL work in progress (jon)
@Ignore
@Test
- public void testSimpleProgramParameterAlias() throws UnsupportedEncodingException {
+ public void testSimpleProgramParameterAlias() {
Query q = new Query(httpEncode("/sdfsd.html?yql=select * from source where myfield contains(word);"));
assertEquals("", q.getModel().getQueryTree().toString());
}
@@ -300,7 +297,7 @@ public class QueryTestCase {
}
@Test
- public void testQueryProfileSubstitution() {
+ public void testQueryProfileSubstitution1() {
QueryProfile profile = new QueryProfile("myProfile");
profile.set("myField", "Profile: %{queryProfile}", null);
Query q = new Query(QueryTestCase.httpEncode("/search?queryProfile=myProfile"), profile.compile(null));
@@ -308,6 +305,24 @@ public class QueryTestCase {
}
@Test
+ public void testQueryProfileSubstitution2() {
+ QueryProfile profile = new QueryProfile("myProfile");
+ profile.set("model.language", "en-US", null);
+ profile.set("myField", "Language: %{lang}", null);
+ Query q = new Query(QueryTestCase.httpEncode("/search?queryProfile=myProfile"), profile.compile(null));
+ assertEquals("Language: ENGLISH", q.properties().get("myField"));
+ }
+
+ @Test
+ public void testQueryProfileSubstitution3() {
+ QueryProfile profile = new QueryProfile("myProfile");
+ profile.set("model.locale", "en-US", null);
+ profile.set("myField", "Language: %{lang}, locale: %{locale}", null);
+ Query q = new Query(QueryTestCase.httpEncode("/search?queryProfile=myProfile"), profile.compile(null));
+ assertEquals("Language: ENGLISH, locale: en_US", q.properties().get("myField"));
+ }
+
+ @Test
public void testTimeoutInRequestOverridesQueryProfile() {
QueryProfile profile = new QueryProfile("test");
profile.set("timeout", 318, (QueryProfileRegistry)null);