diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-08-16 14:58:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-16 14:58:14 +0200 |
commit | c32eb05eb420abe1964bbdd60d03f72ed6546e6c (patch) | |
tree | 7813a7ec729cc021c88cd8e100fe4fa2ad6a5824 /container-search/src/test/java/com/yahoo/search/yql/UserInputTestCase.java | |
parent | 120dcac54aa5fd19f02a6cd48b4b02327362ed60 (diff) | |
parent | 5d7a6831032badd54854e9ac261bc370e8e740e7 (diff) |
Merge pull request #23678 from vespa-engine/bratseth/default-index
Bratseth/default index
Diffstat (limited to 'container-search/src/test/java/com/yahoo/search/yql/UserInputTestCase.java')
-rw-r--r-- | container-search/src/test/java/com/yahoo/search/yql/UserInputTestCase.java | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/yql/UserInputTestCase.java b/container-search/src/test/java/com/yahoo/search/yql/UserInputTestCase.java index 8fe451dd095..1e3b52c23af 100644 --- a/container-search/src/test/java/com/yahoo/search/yql/UserInputTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/yql/UserInputTestCase.java @@ -3,7 +3,10 @@ package com.yahoo.search.yql; import static org.junit.jupiter.api.Assertions.*; -import com.yahoo.search.query.QueryTree; +import com.yahoo.prelude.Index; +import com.yahoo.prelude.IndexFacts; +import com.yahoo.prelude.IndexModel; +import com.yahoo.prelude.SearchDefinition; import org.apache.http.client.utils.URIBuilder; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -367,4 +370,32 @@ public class UserInputTestCase { assertEquals("select * from sources * where text_field contains \"boom\"", query.yqlRepresentation()); } + @Test + void testUserInputWithPhraseSegmentingIndex() { + execution = new Execution(searchChain, Execution.Context.createContextStub(createIndexFacts(true))); + URIBuilder builder = searchUri(); + builder.setParameter("wql", "foo&bar"); + builder.setParameter("yql", "select * from sources * where ([{\"defaultIndex\": \"text_field\",\"grammar\": \"any\"}]userInput(@wql))"); + Query query = searchAndAssertNoErrors(builder); + assertEquals("select * from sources * where text_field contains phrase(\"foo\", \"bar\")", query.yqlRepresentation()); + } + + @Test + void testUserInputWithNonPhraseSegmentingIndex() { + execution = new Execution(searchChain, Execution.Context.createContextStub(createIndexFacts(false))); + URIBuilder builder = searchUri(); + builder.setParameter("wql", "foo&bar"); + builder.setParameter("yql", "select * from sources * where ([{\"defaultIndex\": \"text_field\",\"grammar\": \"any\"}]userInput(@wql))"); + Query query = searchAndAssertNoErrors(builder); + assertEquals("select * from sources * where (text_field contains \"foo\" AND text_field contains \"bar\")", query.yqlRepresentation()); + } + + private IndexFacts createIndexFacts(boolean phraseSegmenting) { + SearchDefinition sd = new SearchDefinition("sources"); + Index test = new Index("text_field"); + test.setPhraseSegmenting(phraseSegmenting); + sd.addIndex(test); + return new IndexFacts(new IndexModel(sd)); + } + } |