diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2019-08-26 13:50:33 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2019-08-26 13:50:33 +0200 |
commit | 195734c17c9aec03549c50ae07418cef540ca506 (patch) | |
tree | 9f4f2575f8cff39a5dad9036a854adc7d7e07454 | |
parent | 072a47d3e0c9352add3e5a3cf9d6d7bd22ec04ff (diff) |
Test implicit and option
3 files changed, 39 insertions, 3 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/Index.java b/container-search/src/main/java/com/yahoo/prelude/Index.java index 245612d24bd..65d5879b004 100644 --- a/container-search/src/main/java/com/yahoo/prelude/Index.java +++ b/container-search/src/main/java/com/yahoo/prelude/Index.java @@ -184,7 +184,7 @@ public class Index { setNumerical(true); } else if (commandString.startsWith("predicate-bounds ")) { setPredicateBounds(commandString.substring(17)); - } else if (commandString.startsWith("phrase-segmenting ")) { + } else if (commandString.equals("phrase-segmenting")) { setPhraseSegmenting(true); } else if (commandString.startsWith("phrase-segmenting ")) { setPhraseSegmenting(Boolean.parseBoolean(commandString.substring("phrase-segmenting ".length()))); diff --git a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/parseindexinfo.cfg b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/parseindexinfo.cfg index 0d264e04799..4a4a5c3a04d 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/parseindexinfo.cfg +++ b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/parseindexinfo.cfg @@ -1,6 +1,6 @@ indexinfo[3] indexinfo[0].name one -indexinfo[0].command[44] +indexinfo[0].command[45] indexinfo[0].command[0].indexname url.all indexinfo[0].command[0].command fullurl indexinfo[0].command[1].indexname host.all @@ -89,6 +89,8 @@ indexinfo[0].command[42].indexname exactindex indexinfo[0].command[42].command index indexinfo[0].command[43].indexname exactindex indexinfo[0].command[43].command exact +indexinfo[0].command[44].indexname phraseSegment +indexinfo[0].command[44].command "phrase-segmenting false" indexinfo[1].name twoRanges indexinfo[1].command[2] @@ -109,3 +111,4 @@ indexinfo[2].command[3].indexname link indexinfo[2].command[3].command index indexinfo[2].command[4].indexname url indexinfo[2].command[4].command index + 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 32d31a6dbd9..10d2dd9efc7 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 @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.test; +import com.google.common.collect.ImmutableList; import com.yahoo.component.chain.Chain; import com.yahoo.language.Language; import com.yahoo.language.Linguistics; @@ -42,7 +43,9 @@ import org.junit.Test; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -878,11 +881,41 @@ public class QueryTestCase { } @Test - public void testImplicitPhrase() { + public void testImplicitPhraseIsDefault() { Query query = new Query(httpEncode("?query=it's fine")); assertEquals("AND 'it s' fine", query.getModel().getQueryTree().toString()); } + @Test + public void testImplicitAnd() { + Query query = new Query(httpEncode("?query=myfield:it's myfield:fine")); + + SearchDefinition test = new SearchDefinition("test"); + Index myField = new Index("myfield"); + myField.addCommand("phrase-segmenting false"); + assertFalse(myField.getPhraseSegmenting()); + test.addIndex(myField); + IndexModel indexModel = new IndexModel(test); + query.getModel().setExecution(new Execution(Execution.Context.createContextStub(new IndexFacts(indexModel)))); + + assertEquals("AND (SAND myfield:it myfield:s) myfield:fine", query.getModel().getQueryTree().toString()); + } + + @Test + public void testImplicitPhrase() { + Query query = new Query(httpEncode("?query=myfield:it's myfield:fine")); + + SearchDefinition test = new SearchDefinition("test"); + Index myField = new Index("myfield"); + myField.addCommand("phrase-segmenting true"); + assertTrue(myField.getPhraseSegmenting()); + test.addIndex(myField); + IndexModel indexModel = new IndexModel(test); + query.getModel().setExecution(new Execution(Execution.Context.createContextStub(new IndexFacts(indexModel)))); + + assertEquals("AND myfield:'it s' myfield:fine", 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"); |