diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-11-30 14:47:38 -0800 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-11-30 14:47:38 -0800 |
commit | cf6da96964eb010e79117a680199916d946dfc22 (patch) | |
tree | 665fb956723c3abd141d7d1b519a92fced83bf3d /container-search/src | |
parent | c0513ac34d2c438e9f97e699659855029e1f06e8 (diff) |
Add build() method to config builders
Diffstat (limited to 'container-search/src')
3 files changed, 63 insertions, 4 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/yql/MinimalQueryInserter.java b/container-search/src/main/java/com/yahoo/search/yql/MinimalQueryInserter.java index a20949e3dfd..91992c3e29e 100644 --- a/container-search/src/main/java/com/yahoo/search/yql/MinimalQueryInserter.java +++ b/container-search/src/main/java/com/yahoo/search/yql/MinimalQueryInserter.java @@ -36,9 +36,6 @@ public class MinimalQueryInserter extends Searcher { private static final CompoundName MAX_HITS = new CompoundName("maxHits"); private static final CompoundName MAX_OFFSET = new CompoundName("maxOffset"); - public MinimalQueryInserter() { - } - @Override public Result search(Query query, Execution execution) { if (query.properties().get(YQL) == null) { diff --git a/container-search/src/test/java/com/yahoo/search/handler/test/JSONSearchHandlerTestCase.java b/container-search/src/test/java/com/yahoo/search/handler/test/JSONSearchHandlerTestCase.java index 5c2a749f858..e07fbd46845 100644 --- a/container-search/src/test/java/com/yahoo/search/handler/test/JSONSearchHandlerTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/handler/test/JSONSearchHandlerTestCase.java @@ -82,7 +82,7 @@ public class JSONSearchHandlerTestCase { } @Test - public void testBadJSON() throws Exception{ + public void testBadJSON() { String json = "Not a valid JSON-string"; RequestHandlerTestDriver.MockResponseHandler responseHandler = driver.sendRequest(uri, com.yahoo.jdisc.http.HttpRequest.Method.POST, json, JSON_CONTENT_TYPE); String response = responseHandler.readAll(); 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 2b0398a8e45..e60d84db3d0 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 @@ -19,9 +19,12 @@ import com.yahoo.prelude.query.AndItem; import com.yahoo.prelude.query.CompositeItem; 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; @@ -770,6 +773,65 @@ public class QueryTestCase { } } + @Test + public void queryLanguageAlternatives() { + // Given: + // Person = { + // Name: 'Joe', + // Hobbies: ['sports','books','bonzais'], + // Phones: [{Number: '12-3456-7890', areaCode: 'NY'},{Number: '22-3456-7890', areaCode: 'CA'}], + // Mother: { + // Name: 'Mom', + // Birthyear: '1961' + // } + //} + + { // Select all Persons whose hobbies contains 'sport' + // YQL + Query yqlQuery = new Query(httpEncode("?query=select * from Persons where hobbies contains 'sports';&type=yql")); + assertEquals("hobbies:sports", yqlQuery.getModel().getQueryTree().toString()); + + // JSON + Query jsonQuery = new Query(httpEncode("?select.where={\"contains\" : [ \"hobbies\", \"sports\" ]}&type=select")); + assertEquals("hobbies:sports", jsonQuery.getModel().getQueryTree().toString()); + + // Programmatically + Query query = new Query(); + query.getModel().getQueryTree().setRoot(new WordItem("sports", "hobbies")); + assertEquals("hobbies:sports", query.getModel().getQueryTree().toString()); + } + + { // Select all Persons whose Phones areaCode equals 'NY' + // YQL + Query yqlQuery = new Query(httpEncode("?query=select * from Persons where phones.areaCode contains 'NY';&type=yql")); + assertEquals("phones.areaCode:NY", yqlQuery.getModel().getQueryTree().toString()); + + // JSON + Query jsonQuery = new Query(httpEncode("?select.where={\"contains\" : [ \"phones.areaCode\", \"NY\" ]}&type=select")); + assertEquals("phones.areaCode:NY", jsonQuery.getModel().getQueryTree().toString()); + + // Programmatically + Query query = new Query(); + query.getModel().getQueryTree().setRoot(new WordItem("NY", "phones.areaCode")); + assertEquals("phones.areaCode:NY", query.getModel().getQueryTree().toString()); + } + + { // Select all Persons whose Mother's Birthyear is greater than 1960 + // YQL + Query yqlQuery = new Query(httpEncode("?query=select * from Persons where mother.Birthyear > 1960;&type=yql")); + assertEquals("mother.Birthyear:>1960", yqlQuery.getModel().getQueryTree().toString()); + + // JSON + Query jsonQuery = new Query(httpEncode("?select.where={\"range\" : [ \"mother.Birthyear\", { \">\": 1960}]}&type=select")); + assertEquals("mother.Birthyear:>1960", jsonQuery.getModel().getQueryTree().toString()); + + // Programmatically + Query query = new Query(); + query.getModel().getQueryTree().setRoot(new IntItem(">1960", "mother.Birthyear")); + assertEquals("mother.Birthyear:>1960", query.getModel().getQueryTree().toString()); + } + } + private void assertDetectionText(String expectedDetectionText, String queryString, String ... indexSpecs) { Query q = new Query(httpEncode("/?query=" + queryString)); SearchDefinition sd = new SearchDefinition("testSearchDefinition"); |