diff options
author | Jon Bratseth <bratseth@vespa.ai> | 2023-06-07 14:42:16 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@vespa.ai> | 2023-06-07 14:42:16 +0200 |
commit | 537d80f3aad6351322ded0f3e300722cbcdba5d7 (patch) | |
tree | a791da0b25eb250e4455e2c6f511b20978e8a134 /container-search/src/test/java/com/yahoo/search/searchers | |
parent | 5347cb3fe63c1e3c40eb8d5dab7bcf1b11a79124 (diff) |
Revert "Revert "Validate prefix matching""
This reverts commit 875018f7acb1bbd9f186b97d177be296ff157ba7.
Diffstat (limited to 'container-search/src/test/java/com/yahoo/search/searchers')
-rw-r--r-- | container-search/src/test/java/com/yahoo/search/searchers/test/QueryValidatorTestCase.java | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/searchers/test/QueryValidatorTestCase.java b/container-search/src/test/java/com/yahoo/search/searchers/test/QueryValidatorTestCase.java index 64fb4354003..8c525b2975a 100644 --- a/container-search/src/test/java/com/yahoo/search/searchers/test/QueryValidatorTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/searchers/test/QueryValidatorTestCase.java @@ -18,7 +18,7 @@ import static org.junit.jupiter.api.Assertions.fail; public class QueryValidatorTestCase { @Test - void testValidation() { + void testTensorsCannotBeSearchedForTerms() { SearchDefinition sd = new SearchDefinition("test"); sd.addCommand("mytensor1", "type tensor(x[100]"); sd.addCommand("mytensor2", "type tensor<float>(x[100]"); @@ -27,24 +27,47 @@ public class QueryValidatorTestCase { IndexFacts indexFacts = new IndexFacts(model); Execution execution = new Execution(Execution.Context.createContextStub(indexFacts)); - new QueryValidator().search(new Query("?query=mystring:foo"), execution); + assertSucceeds("?query=mystring:foo", execution); + assertFails("Cannot search for terms in 'mytensor1': It is a tensor field", + "?query=mytensor1:foo", execution); + assertFails("Cannot search for terms in 'mytensor2': It is a tensor field", + "?query=mytensor2:foo", execution); + } - try { - new QueryValidator().search(new Query("?query=mytensor1:foo"), execution); - fail("Expected validation error"); - } - catch (IllegalArgumentException e) { - // success - assertEquals("Cannot search 'mytensor1': It is a tensor field", e.getMessage()); - } + @Test + void testPrefixRequiresAttribute() { + SearchDefinition sd = new SearchDefinition("test"); + sd.addCommand("attributeOnly", "type string") + .addCommand("attribute"); + sd.addCommand("indexOnly", "type string") + .addCommand("index"); + sd.addCommand("attributeAndIndex", "type string") + .addCommand("attribute") + .addCommand("index"); + IndexModel model = new IndexModel(sd); + + IndexFacts indexFacts = new IndexFacts(model); + Execution execution = new Execution(Execution.Context.createContextStub(indexFacts)); + + assertSucceeds("?query=attributeOnly:foo*", execution); + assertFails("'indexOnly' is not an attribute field: Prefix matching is not supported", + "?query=indexOnly:foo*", execution); + assertFails("'attributeAndIndex' is an index field: Prefix matching is not supported even when it is also an attribute", + "?query=attributeAndIndex:foo*", execution); + } + + private void assertSucceeds(String query, Execution execution) { + new QueryValidator().search(new Query(query), execution); + } + private void assertFails(String expectedError, String query, Execution execution) { try { - new QueryValidator().search(new Query("?query=mytensor2:foo"), execution); - fail("Expected validation error"); + new QueryValidator().search(new Query(query), execution); + fail("Expected validation error from " + query); } catch (IllegalArgumentException e) { // success - assertEquals("Cannot search 'mytensor2': It is a tensor field", e.getMessage()); + assertEquals(expectedError, e.getMessage()); } } |