diff options
Diffstat (limited to 'container-search/src/test/java/com/yahoo')
3 files changed, 69 insertions, 57 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/yql/MinimalQueryInserterTestCase.java b/container-search/src/test/java/com/yahoo/search/yql/MinimalQueryInserterTestCase.java index b23e25e173e..e89c8aeb409 100644 --- a/container-search/src/test/java/com/yahoo/search/yql/MinimalQueryInserterTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/yql/MinimalQueryInserterTestCase.java @@ -318,12 +318,12 @@ public class MinimalQueryInserterTestCase { } @Test - public void testStringReprBasicSanity() { + public void testStringRepresentation() { String yql = "select%20ignoredfield%20from%20ignoredsource%20where%20title%20contains%20%22madonna%22%20order%20by%20something%2C%20shoesize%20desc%20limit%20300%20timeout%203%3B"; Query query = new Query("search/?yql=" + yql); execution.search(query); - assertEquals("select ignoredfield from ignoredsource where [{\"segmenter\": {\"version\": \"1.9\", \"backend\": \"YqlUnitTest\"}}](title contains \"madonna\") order by something, shoesize desc limit 300 timeout 3;", - query.yqlRepresentation(new Tuple2<>("YqlUnitTest", new Version(1, 9)), true)); + assertEquals("select ignoredfield from ignoredsource where title contains \"madonna\" order by something, shoesize desc limit 300 timeout 3;", + query.yqlRepresentation()); } diff --git a/container-search/src/test/java/com/yahoo/search/yql/VespaSerializerTestCase.java b/container-search/src/test/java/com/yahoo/search/yql/VespaSerializerTestCase.java index 6984a8537ef..faf254577ce 100644 --- a/container-search/src/test/java/com/yahoo/search/yql/VespaSerializerTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/yql/VespaSerializerTestCase.java @@ -94,7 +94,7 @@ public class VespaSerializerTestCase { } @Test - public final void testAnd() { + public void testAnd() { parseAndConfirm("(description contains \"a\" AND title contains \"that\")"); } @@ -103,39 +103,42 @@ public class VespaSerializerTestCase { } private void parseAndConfirm(String expected, String toParse) { - QueryTree item = parser - .parse(new Parsable() - .setQuery(SELECT + toParse + ";")); - // System.out.println(item.toString()); + QueryTree item = parser.parse(new Parsable().setQuery(SELECT + toParse + ";")); String q = VespaSerializer.serialize(item.getRoot()); assertEquals(expected, q); } @Test - public final void testAndNot() { + public void testAndNot() { parseAndConfirm("(description contains \"a\") AND !(title contains \"that\")"); } @Test - public final void testEquiv() { + public void testEquiv() { parseAndConfirm("title contains equiv(\"a\", \"b\")"); } @Test - public final void testNear() { + public void testNear() { parseAndConfirm("title contains near(\"a\", \"b\")"); parseAndConfirm("title contains ([{\"distance\": 50}]near(\"a\", \"b\"))"); } @Test - public final void testNumbers() { + public void testNumbers() { parseAndConfirm("title = 500"); parseAndConfirm("title > 500"); parseAndConfirm("title < 500"); } @Test - public final void testAnnotatedNumbers() { + public void testBoolean() { + parseAndConfirm("flag = true"); + parseAndConfirm("flag = false"); + } + + @Test + public void testAnnotatedNumbers() { parseAndConfirm("title = ([{\"filter\": true}]500)"); parseAndConfirm("title > ([{\"filter\": true}]500)"); parseAndConfirm("title < ([{\"filter\": true}](-500))"); @@ -144,32 +147,32 @@ public class VespaSerializerTestCase { } @Test - public final void testRange() { + public void testRange() { parseAndConfirm("range(title, 1, 500)"); } @Test - public final void testAnnotatedRange() { + public void testAnnotatedRange() { parseAndConfirm("[{\"filter\": true}]range(title, 1, 500)"); } @Test - public final void testOrderedNear() { + public void testOrderedNear() { parseAndConfirm("title contains onear(\"a\", \"b\")"); } @Test - public final void testOr() { + public void testOr() { parseAndConfirm("(description contains \"a\" OR title contains \"that\")"); } @Test - public final void testDotProduct() { + public void testDotProduct() { parseAndConfirm("dotProduct(description, {\"a\": 1, \"b\": 2})"); } @Test - public final void testPredicate() { + public void testPredicate() { parseAndConfirm("predicate(boolean,{\"gender\":\"male\"},{\"age\":25L})"); parseAndConfirm("predicate(boolean,{\"gender\":\"male\",\"hobby\":\"music\",\"hobby\":\"hiking\"}," + "{\"age\":25L})", @@ -182,32 +185,32 @@ public class VespaSerializerTestCase { } @Test - public final void testPhrase() { + public void testPhrase() { parseAndConfirm("description contains phrase(\"a\", \"b\")"); } @Test - public final void testAnnotatedPhrase() { + public void testAnnotatedPhrase() { parseAndConfirm("description contains ([{\"id\": 1}]phrase(\"a\", \"b\"))"); } @Test - public final void testAnnotatedNear() { + public void testAnnotatedNear() { parseAndConfirm("description contains ([{\"distance\": 37}]near(\"a\", \"b\"))"); } @Test - public final void testAnnotatedOnear() { + public void testAnnotatedOnear() { parseAndConfirm("description contains ([{\"distance\": 37}]onear(\"a\", \"b\"))"); } @Test - public final void testAnnotatedEquiv() { + public void testAnnotatedEquiv() { parseAndConfirm("description contains ([{\"id\": 1}]equiv(\"a\", \"b\"))"); } @Test - public final void testAnnotatedPhraseSegment() { + public void testAnnotatedPhraseSegment() { PhraseSegmentItem phraseSegment = new PhraseSegmentItem("abc", true, false); phraseSegment.addItem(new WordItem("a", "indexNamePlaceholder")); phraseSegment.addItem(new WordItem("b", "indexNamePlaceholder")); @@ -219,7 +222,7 @@ public class VespaSerializerTestCase { } @Test - public final void testSameElement() { + public void testSameElement() { SameElementItem sameElement = new SameElementItem("ss"); sameElement.addItem(new WordItem("a", "f1")); sameElement.addItem(new WordItem("b", "f2")); @@ -228,7 +231,7 @@ public class VespaSerializerTestCase { } @Test - public final void testAnnotatedAndSegment() { + public void testAnnotatedAndSegment() { AndSegmentItem andSegment = new AndSegmentItem("abc", true, false); andSegment.addItem(new WordItem("a", "indexNamePlaceholder")); andSegment.addItem(new WordItem("b", "indexNamePlaceholder")); @@ -239,32 +242,32 @@ public class VespaSerializerTestCase { } @Test - public final void testPhraseWithAnnotations() { + public void testPhraseWithAnnotations() { parseAndConfirm("description contains phrase(([{\"id\": 15}]\"a\"), \"b\")"); } @Test - public final void testPhraseSegmentInPhrase() { + public void testPhraseSegmentInPhrase() { parseAndConfirm("description contains phrase(\"a\", \"b\", ([{\"origin\": {\"original\": \"c d\", \"offset\": 0, \"length\": 3}}]phrase(\"c\", \"d\")))"); } @Test - public final void testRank() { + public void testRank() { parseAndConfirm("rank(a contains \"A\", b contains \"B\")"); } @Test - public final void testWand() { + public void testWand() { parseAndConfirm("wand(description, {\"a\": 1, \"b\": 2})"); } @Test - public final void testWeakAnd() { + public void testWeakAnd() { parseAndConfirm("weakAnd(a contains \"A\", b contains \"B\")"); } @Test - public final void testAnnotatedWeakAnd() { + public void testAnnotatedWeakAnd() { parseAndConfirm("([{\"" + YqlParser.TARGET_NUM_HITS + "\": 10}]weakAnd(a contains \"A\", b contains \"B\"))"); parseAndConfirm("([{\"" + YqlParser.SCORE_THRESHOLD + "\": 10}]weakAnd(a contains \"A\", b contains \"B\"))"); parseAndConfirm("([{\"" + YqlParser.TARGET_NUM_HITS + "\": 10, \"" + YqlParser.SCORE_THRESHOLD @@ -272,12 +275,12 @@ public class VespaSerializerTestCase { } @Test - public final void testWeightedSet() { + public void testWeightedSet() { parseAndConfirm("weightedSet(description, {\"a\": 1, \"b\": 2})"); } @Test - public final void testAnnotatedWord() { + public void testAnnotatedWord() { parseAndConfirm("description contains ([{\"andSegmenting\": true}]\"a\")"); parseAndConfirm("description contains ([{\"weight\": 37}]\"a\")"); parseAndConfirm("description contains ([{\"id\": 37}]\"a\")"); @@ -289,29 +292,29 @@ public class VespaSerializerTestCase { } @Test - public final void testPrefix() { + public void testPrefix() { parseAndConfirm("description contains ([{\"prefix\": true}]\"a\")"); } @Test - public final void testSuffix() { + public void testSuffix() { parseAndConfirm("description contains ([{\"suffix\": true}]\"a\")"); } @Test - public final void testSubstring() { + public void testSubstring() { parseAndConfirm("description contains ([{\"substring\": true}]\"a\")"); } @Test - public final void testExoticItemTypes() { + public void testExoticItemTypes() { Item item = MarkerWordItem.createEndOfHost(); String q = VespaSerializer.serialize(item); assertEquals("default contains ([{\"implicitTransforms\": false}]\"$\")", q); } @Test - public final void testEmptyIndex() { + public void testEmptyIndex() { Item item = new WordItem("nalle", true); String q = VespaSerializer.serialize(item); assertEquals("default contains \"nalle\"", q); @@ -319,7 +322,7 @@ public class VespaSerializerTestCase { @Test - public final void testLongAndNot() { + public void testLongAndNot() { NotItem item = new NotItem(); item.addItem(new WordItem("a")); item.addItem(new WordItem("b")); @@ -330,7 +333,7 @@ public class VespaSerializerTestCase { } @Test - public final void testPhraseAsOperatorArgument() { + public void testPhraseAsOperatorArgument() { // flattening phrases is a feature, not a bug parseAndConfirm("description contains phrase(\"a\", \"b\", \"c\")", "description contains phrase(\"a\", phrase(\"b\", \"c\"))"); @@ -344,7 +347,7 @@ public class VespaSerializerTestCase { } @Test - public final void testNumberTypeInt() { + public void testNumberTypeInt() { parseAndConfirm("title = 500"); parseAndConfirm("title > 500"); parseAndConfirm("title < (-500)"); @@ -354,7 +357,7 @@ public class VespaSerializerTestCase { } @Test - public final void testNumberTypeLong() { + public void testNumberTypeLong() { parseAndConfirm("title = 549755813888L"); parseAndConfirm("title > 549755813888L"); parseAndConfirm("title < (-549755813888L)"); @@ -364,7 +367,7 @@ public class VespaSerializerTestCase { } @Test - public final void testNumberTypeFloat() { + public void testNumberTypeFloat() { parseAndConfirm("title = 500.0"); // silly parseAndConfirm("title > 500.0"); parseAndConfirm("title < (-500.0)"); @@ -374,19 +377,19 @@ public class VespaSerializerTestCase { } @Test - public final void testAnnotatedLong() { + public void testAnnotatedLong() { parseAndConfirm("title >= ([{\"id\": 2014}](-549755813888L))"); } @Test - public final void testHitLimit() { + public void testHitLimit() { parseAndConfirm("title <= ([{\"hitLimit\": 89}](-500))"); parseAndConfirm("title <= ([{\"hitLimit\": 89}](-500))"); parseAndConfirm("[{\"hitLimit\": 89}]range(title, 1, 500)"); } @Test - public final void testOpenIntervals() { + public void testOpenIntervals() { parseAndConfirm("range(title, 0.0, 500.0)"); parseAndConfirm("[{\"bounds\": \"open\"}]range(title, 0.0, 500.0)"); parseAndConfirm("[{\"bounds\": \"leftOpen\"}]range(title, 0.0, 500.0)"); @@ -395,18 +398,18 @@ public class VespaSerializerTestCase { } @Test - public final void testRegExp() { + public void testRegExp() { parseAndConfirm("foo matches \"a b\""); } @Test - public final void testWordAlternatives() { + public void testWordAlternatives() { parseAndConfirm("foo contains" + " ([{\"origin\": {\"original\": \" trees \", \"offset\": 1, \"length\": 5}}]" + "alternatives({\"trees\": 1.0, \"tree\": 0.7}))"); } @Test - public final void testWordAlternativesInPhrase() { + public void testWordAlternativesInPhrase() { parseAndConfirm("foo contains phrase(\"forest\"," + " ([{\"origin\": {\"original\": \" trees \", \"offset\": 1, \"length\": 5}}]" + "alternatives({\"trees\": 1.0, \"tree\": 0.7}))" diff --git a/container-search/src/test/java/com/yahoo/search/yql/YqlParserTestCase.java b/container-search/src/test/java/com/yahoo/search/yql/YqlParserTestCase.java index 31a057c158f..531167bb342 100644 --- a/container-search/src/test/java/com/yahoo/search/yql/YqlParserTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/yql/YqlParserTestCase.java @@ -7,6 +7,7 @@ import com.yahoo.language.Language; import com.yahoo.prelude.IndexFacts; import com.yahoo.prelude.IndexModel; import com.yahoo.prelude.query.AndItem; +import com.yahoo.prelude.query.BoolItem; import com.yahoo.prelude.query.IndexedItem; import com.yahoo.prelude.query.ExactStringItem; import com.yahoo.prelude.query.Item; @@ -249,7 +250,11 @@ public class YqlParserTestCase { @Test public void testBoolean() { assertParse("select foo from bar where flag = true;", "flag:true"); - assertParse("select foo from bar where flag = false;", "flag:false"); + QueryTree query = assertParse("select foo from bar where flag = false;", "flag:false"); + assertEquals(BoolItem.class, query.getRoot().getClass()); + BoolItem item = (BoolItem)query.getRoot(); + assertEquals("flag", item.getIndexName()); + assertEquals(false, item.value()); } @Test @@ -922,8 +927,10 @@ public class YqlParserTestCase { } } - private void assertParse(String yqlQuery, String expectedQueryTree) { - assertEquals(expectedQueryTree, parse(yqlQuery).toString()); + private QueryTree assertParse(String yqlQuery, String expectedQueryTree) { + QueryTree query = parse(yqlQuery); + assertEquals(expectedQueryTree, query.toString()); + return query; } private void assertCanonicalParse(String yqlQuery, String expectedQueryTree) { @@ -935,15 +942,17 @@ public class YqlParserTestCase { assertEquals(q.getModel().getQueryTree().toString(), expectedQueryTree); } - private void assertParseFail(String yqlQuery, Throwable expectedException) { + private QueryTree assertParseFail(String yqlQuery, Throwable expectedException) { + QueryTree query = null; try { - parse(yqlQuery); + query = parse(yqlQuery); } catch (Throwable t) { assertEquals(expectedException.getClass(), t.getClass()); assertEquals(expectedException.getMessage(), t.getMessage()); - return; + return query; } fail("Parse succeeded: " + yqlQuery); + return query; } private void assertSources(String yqlQuery, Collection<String> expectedSources) { |