diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-10-15 20:06:06 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-10-15 20:06:06 +0200 |
commit | b28a953489d50d4366ebd01922ea1d1febdfe86c (patch) | |
tree | c2b441912e76d0cb08d9cfed6307c97d72ac51fe /container-search | |
parent | dbefc9f0fa3b338232fc504f547a0f71c5f56d71 (diff) |
Avoid deprecated method
Diffstat (limited to 'container-search')
10 files changed, 292 insertions, 240 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 ae8aad3956e..109ecfd29f8 100644 --- a/container-search/src/main/java/com/yahoo/prelude/Index.java +++ b/container-search/src/main/java/com/yahoo/prelude/Index.java @@ -253,8 +253,8 @@ public class Index { public int getGramSize() { return gramSize; } public void setNGram(boolean nGram,int gramSize) { - this.isNGram=nGram; - this.gramSize=gramSize; + this.isNGram = nGram; + this.gramSize = gramSize; } public void setDynamicSummary(boolean dynamicSummary) { this.dynamicSummary=dynamicSummary; } diff --git a/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java b/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java index 8343040be79..640282439d5 100644 --- a/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java +++ b/container-search/src/main/java/com/yahoo/prelude/IndexFacts.java @@ -183,6 +183,7 @@ public class IndexFacts { } DocumentTypeListOffset sd = chooseSearchDefinition(documentTypes, 0); + while (sd != null) { Index index = sd.searchDefinition.getIndex(canonicName); diff --git a/container-search/src/main/java/com/yahoo/prelude/IndexModel.java b/container-search/src/main/java/com/yahoo/prelude/IndexModel.java index 0a413c1611c..45214d4d3df 100644 --- a/container-search/src/main/java/com/yahoo/prelude/IndexModel.java +++ b/container-search/src/main/java/com/yahoo/prelude/IndexModel.java @@ -7,7 +7,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.logging.Logger; import java.util.stream.Collectors; import com.yahoo.search.config.IndexInfoConfig; @@ -21,15 +20,13 @@ import com.yahoo.container.QrSearchersConfig; */ public final class IndexModel { - private static final Logger log = Logger.getLogger(IndexModel.class.getName()); - - // Copied from MasterClustersInfoUpdater. It's a temporary workaround for IndexFacts. + // Copied from MasterClustersInfoUpdater. It's a temporary workaround for IndexFacts private Map<String, List<String>> masterClusters; private Map<String, SearchDefinition> searchDefinitions; private SearchDefinition unionSearchDefinition; /** - * Use IndexModel as a pure wrapper for the parameters given. + * Create an index model. */ public IndexModel(Map<String, List<String>> masterClusters, Collection<SearchDefinition> searchDefinitions) { this.masterClusters = masterClusters; @@ -112,6 +109,7 @@ public final class IndexModel { for (SearchDefinition sd : searchDefinitions) { for (Index index : sd.indices().values()) { + union.getOrCreateIndex(index.getName()); for (String command : index.allCommands()) union.addCommand(index.getName(), command); for (String alias : index.aliases()) diff --git a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ExactMatchAndDefaultIndexTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ExactMatchAndDefaultIndexTestCase.java index a8eeaeda2a0..fb43fa0421f 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ExactMatchAndDefaultIndexTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ExactMatchAndDefaultIndexTestCase.java @@ -3,12 +3,15 @@ package com.yahoo.prelude.query.parser.test; import com.yahoo.prelude.Index; import com.yahoo.prelude.IndexFacts; +import com.yahoo.prelude.IndexModel; +import com.yahoo.prelude.SearchDefinition; import com.yahoo.search.Query; import com.yahoo.search.searchchain.Execution; import org.junit.Test; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.util.Collections; import static org.junit.Assert.assertEquals; @@ -21,10 +24,12 @@ public class ExactMatchAndDefaultIndexTestCase { @Test public void testExactMatchTokenization() { + SearchDefinition sd = new SearchDefinition("testsd"); Index index = new Index("testexact"); index.setExact(true, null); - IndexFacts facts = new IndexFacts(); - facts.addIndex("testsd", index); + sd.addIndex(index); + IndexFacts facts = new IndexFacts(new IndexModel(Collections.emptyMap(), Collections.singleton(sd))); + Query q = new Query("?query=" + enc("a/b foo.com") + "&default-index=testexact"); q.getModel().setExecution(new Execution(new Execution.Context(null, facts, null, null, null))); assertEquals("AND testexact:a/b testexact:foo.com", q.getModel().getQueryTree().getRoot().toString()); diff --git a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParseTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParseTestCase.java index 9181ea4e268..12f9ef2b18f 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParseTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParseTestCase.java @@ -4,6 +4,8 @@ package com.yahoo.prelude.query.parser.test; import com.yahoo.language.Language; import com.yahoo.prelude.Index; import com.yahoo.prelude.IndexFacts; +import com.yahoo.prelude.IndexModel; +import com.yahoo.prelude.SearchDefinition; import com.yahoo.prelude.query.AndItem; import com.yahoo.prelude.query.CompositeItem; import com.yahoo.prelude.query.IntItem; @@ -22,6 +24,7 @@ import com.yahoo.prelude.query.parser.TestLinguistics; import com.yahoo.search.Query; import org.junit.Test; +import java.util.Collections; import java.util.Iterator; import static org.junit.Assert.assertEquals; @@ -2058,13 +2061,17 @@ public class ParseTestCase { @Test public void testExactMatchParsing1() { - IndexFacts indexFacts = ParsingTester.createIndexFacts(); - Index index1=new Index("testexact1"); - index1.setExact(true,null); - Index index2=new Index("testexact2"); - index2.setExact(true,"()/aa*::*&"); - indexFacts.addIndex("testsd",index1); - indexFacts.addIndex("testsd",index2); + SearchDefinition sd = new SearchDefinition("testsd"); + + Index index1 = new Index("testexact1"); + index1.setExact(true, null); + sd.addIndex(index1); + + Index index2 = new Index("testexact2"); + index2.setExact(true, "()/aa*::*&"); + sd.addIndex(index2); + + IndexFacts indexFacts = new IndexFacts(new IndexModel(Collections.emptyMap(), Collections.singleton(sd))); ParsingTester customTester = new ParsingTester(indexFacts); customTester.assertParsed("testexact1:/,%&#", "testexact1:/,%&#", Query.Type.ALL); @@ -2076,10 +2083,13 @@ public class ParseTestCase { /** Testing terminators containing control characters in conjunction with those control characters */ @Test public void testExactMatchParsing2() { - IndexFacts indexFacts = ParsingTester.createIndexFacts(); - Index index1=new Index("testexact1"); - index1.setExact(true,"*!*"); - indexFacts.addIndex("testsd",index1); + SearchDefinition sd = new SearchDefinition("testsd"); + + Index index1 = new Index("testexact1"); + index1.setExact(true, "*!*"); + sd.addIndex(index1); + + IndexFacts indexFacts = new IndexFacts(new IndexModel(Collections.emptyMap(), Collections.singleton(sd))); ParsingTester customTester = new ParsingTester(indexFacts); customTester.assertParsed("testexact1:_-_*!200","testexact1:_-_*!**!!",Query.Type.ALL); @@ -2088,10 +2098,13 @@ public class ParseTestCase { /** Testing terminators containing control characters in conjunction with those control characters */ @Test public void testExactMatchParsing3() { - IndexFacts indexFacts = ParsingTester.createIndexFacts(); - Index index1=new Index("testexact1"); - index1.setExact(true,"*"); - indexFacts.addIndex("testsd",index1); + SearchDefinition sd = new SearchDefinition("testsd"); + + Index index1 = new Index("testexact1"); + index1.setExact(true, "*"); + sd.addIndex(index1); + + IndexFacts indexFacts = new IndexFacts(new IndexModel(Collections.emptyMap(), Collections.singleton(sd))); ParsingTester customTester = new ParsingTester(indexFacts); customTester.assertParsed("testexact1:_-_*!200","testexact1:_-_**!!",Query.Type.ALL); diff --git a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/TokenizerTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/TokenizerTestCase.java index 778802e065c..70fc5d56ab9 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/TokenizerTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/TokenizerTestCase.java @@ -4,6 +4,8 @@ package com.yahoo.prelude.query.parser.test; import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.prelude.Index; import com.yahoo.prelude.IndexFacts; +import com.yahoo.prelude.IndexModel; +import com.yahoo.prelude.SearchDefinition; import com.yahoo.prelude.query.parser.SpecialTokenRegistry; import com.yahoo.prelude.query.parser.SpecialTokens; import com.yahoo.prelude.query.parser.Token; @@ -304,13 +306,17 @@ public class TokenizerTestCase { @Test public void testExactMatchTokenization() { - Index index1=new Index("testexact1"); - index1.setExact(true,null); - Index index2=new Index("testexact2"); - index2.setExact(true,"()/aa*::*&"); - IndexFacts facts = new IndexFacts(); - facts.addIndex("testsd",index1); - facts.addIndex("testsd",index2); + SearchDefinition sd = new SearchDefinition("testsd"); + + Index index1 = new Index("testexact1"); + index1.setExact(true, null); + sd.addIndex(index1); + + Index index2 = new Index("testexact2"); + index2.setExact(true, "()/aa*::*&"); + sd.addIndex(index2); + + IndexFacts facts = new IndexFacts(new IndexModel(Collections.emptyMap(), Collections.singleton(sd))); IndexFacts.Session session = facts.newSession(Collections.emptySet(), Collections.emptySet()); Tokenizer tokenizer=new Tokenizer(new SimpleLinguistics()); List<?> tokens=tokenizer.tokenize("normal a:b (normal testexact1:/,%#%&+-+ ) testexact2:ho_/&%&/()/aa*::*& b:c", "default", session); @@ -344,16 +350,20 @@ public class TokenizerTestCase { @Test public void testExactMatchTokenizationTerminatorTerminatesQuery() { - Index index1=new Index("testexact1"); - index1.setExact(true,null); - Index index2=new Index("testexact2"); - index2.setExact(true,"()/aa*::*&"); - IndexFacts facts = new IndexFacts(); - facts.addIndex("testsd",index1); - facts.addIndex("testsd",index2); - Tokenizer tokenizer=new Tokenizer(new SimpleLinguistics()); + SearchDefinition sd = new SearchDefinition("testsd"); + + Index index1 = new Index("testexact1"); + index1.setExact(true, null); + sd.addIndex(index1); + + Index index2 = new Index("testexact2"); + index2.setExact(true, "()/aa*::*&"); + sd.addIndex(index2); + + IndexFacts facts = new IndexFacts(new IndexModel(Collections.emptyMap(), Collections.singleton(sd))); + Tokenizer tokenizer = new Tokenizer(new SimpleLinguistics()); IndexFacts.Session session = facts.newSession(Collections.emptySet(), Collections.emptySet()); - List<?> tokens=tokenizer.tokenize("normal a:b (normal testexact1:/,%#%&+-+ ) testexact2:ho_/&%&/()/aa*::*&", session); + List<?> tokens = tokenizer.tokenize("normal a:b (normal testexact1:/,%#%&+-+ ) testexact2:ho_/&%&/()/aa*::*&", session); assertEquals(new Token(WORD, "normal"), tokens.get(0)); assertEquals(new Token(SPACE, " "), tokens.get(1)); assertEquals(new Token(WORD, "a"), tokens.get(2)); @@ -377,16 +387,20 @@ public class TokenizerTestCase { @Test public void testExactMatchTokenizationWithTerminatorTerminatedByEndOfString() { - Index index1=new Index("testexact1"); - index1.setExact(true,null); - Index index2=new Index("testexact2"); - index2.setExact(true,"()/aa*::*&"); - IndexFacts facts = new IndexFacts(); - facts.addIndex("testsd",index1); - facts.addIndex("testsd",index2); - Tokenizer tokenizer=new Tokenizer(new SimpleLinguistics()); + SearchDefinition sd = new SearchDefinition("testsd"); + + Index index1 = new Index("testexact1"); + index1.setExact(true, null); + sd.addIndex(index1); + + Index index2 = new Index("testexact2"); + index2.setExact(true, "()/aa*::*&"); + sd.addIndex(index2); + + IndexFacts facts = new IndexFacts(new IndexModel(Collections.emptyMap(), Collections.singleton(sd))); + Tokenizer tokenizer = new Tokenizer(new SimpleLinguistics()); IndexFacts.Session session = facts.newSession(Collections.emptySet(), Collections.emptySet()); - List<?> tokens=tokenizer.tokenize("normal a:b (normal testexact1:/,%#%&+-+ ) testexact2:ho_/&%&/()/aa*::*", session); + List<?> tokens = tokenizer.tokenize("normal a:b (normal testexact1:/,%#%&+-+ ) testexact2:ho_/&%&/()/aa*::*", session); assertEquals(new Token(WORD, "normal"), tokens.get(0)); assertEquals(new Token(SPACE, " "), tokens.get(1)); assertEquals(new Token(WORD, "a"), tokens.get(2)); @@ -410,16 +424,20 @@ public class TokenizerTestCase { @Test public void testExactMatchTokenizationEndsByColon() { - Index index1=new Index("testexact1"); - index1.setExact(true,null); - Index index2=new Index("testexact2"); - index2.setExact(true,"()/aa*::*&"); - IndexFacts facts = new IndexFacts(); - facts.addIndex("testsd",index1); - facts.addIndex("testsd",index2); - Tokenizer tokenizer=new Tokenizer(new SimpleLinguistics()); + SearchDefinition sd = new SearchDefinition("testsd"); + + Index index1 = new Index("testexact1"); + index1.setExact(true, null); + sd.addIndex(index1); + + Index index2 = new Index("testexact2"); + index2.setExact(true, "()/aa*::*&"); + sd.addIndex(index2); + + IndexFacts facts = new IndexFacts(new IndexModel(Collections.emptyMap(), Collections.singleton(sd))); + Tokenizer tokenizer = new Tokenizer(new SimpleLinguistics()); IndexFacts.Session session = facts.newSession(Collections.emptySet(), Collections.emptySet()); - List<?> tokens=tokenizer.tokenize("normal a:b (normal testexact1:!/%#%&+-+ ) testexact2:ho_/&%&/()/aa*::*&b:", session); + List<?> tokens = tokenizer.tokenize("normal a:b (normal testexact1:!/%#%&+-+ ) testexact2:ho_/&%&/()/aa*::*&b:", session); assertEquals(new Token(WORD, "normal"), tokens.get(0)); assertEquals(new Token(SPACE, " "), tokens.get(1)); assertEquals(new Token(WORD, "a"), tokens.get(2)); @@ -444,13 +462,17 @@ public class TokenizerTestCase { @Test public void testExactMatchHeuristics() { - Index index1=new Index("testexact1"); + SearchDefinition sd = new SearchDefinition("testsd"); + + Index index1 = new Index("testexact1"); index1.setExact(true, null); - Index index2=new Index("testexact2"); + sd.addIndex(index1); + + Index index2 = new Index("testexact2"); index2.setExact(true, "()/aa*::*&"); - IndexFacts indexFacts = new IndexFacts(); - indexFacts.addIndex("testsd", index1); - indexFacts.addIndex("testsd", index2); + sd.addIndex(index2); + + IndexFacts indexFacts = new IndexFacts(new IndexModel(Collections.emptyMap(), Collections.singleton(sd))); IndexFacts.Session facts = indexFacts.newSession(Collections.emptySet(), Collections.emptySet()); Tokenizer tokenizer = new Tokenizer(new SimpleLinguistics()); diff --git a/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java index 8c59b20a5dd..88c06635520 100644 --- a/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java @@ -134,10 +134,13 @@ public class IndexFactsTestCase { } private void assertExactIsWorking(String indexName) { - Index index=new Index(indexName); + SearchDefinition sd = new SearchDefinition("artist"); + + Index index = new Index(indexName); index.setExact(true,"^^^"); - IndexFacts indexFacts = createIndexFacts(); - indexFacts.addIndex("artist",index); + sd.addIndex(index); + + IndexFacts indexFacts = new IndexFacts(new IndexModel(Collections.emptyMap(), Collections.singleton(sd))); Query query = new Query(); query.getModel().getSources().add("artist"); assertTrue(indexFacts.newSession(query).getIndex(indexName).isExact()); @@ -150,7 +153,7 @@ public class IndexFactsTestCase { assertExactIsWorking("test"); assertExactIsWorking("artist_name_ft_norm1"); - List search=new ArrayList(); + List search = new ArrayList(); search.add("three"); Query query = new Query(); query.getModel().getSources().add("three"); @@ -176,13 +179,15 @@ public class IndexFactsTestCase { @Test public void testComplexExactMatching() { - IndexFacts indexFacts = createIndexFacts(); + SearchDefinition sd = new SearchDefinition("foobar"); String u_name = "foo_bar"; Index u_index = new Index(u_name); u_index.setExact(true, "^^^"); Index b_index = new Index("bar"); - indexFacts.addIndex("foobar", u_index); - indexFacts.addIndex("foobar", b_index); + sd.addIndex(u_index); + sd.addIndex(b_index); + + IndexFacts indexFacts = new IndexFacts(new IndexModel(Collections.emptyMap(), Collections.singleton(sd))); Query query = new Query(); query.getModel().getSources().add("foobar"); IndexFacts.Session session = indexFacts.newSession(query); diff --git a/container-search/src/test/java/com/yahoo/search/querytransform/LowercasingTestCase.java b/container-search/src/test/java/com/yahoo/search/querytransform/LowercasingTestCase.java index 4b2da823271..663fe004b43 100644 --- a/container-search/src/test/java/com/yahoo/search/querytransform/LowercasingTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/querytransform/LowercasingTestCase.java @@ -5,8 +5,11 @@ package com.yahoo.search.querytransform; import static org.junit.Assert.assertEquals; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import com.yahoo.prelude.IndexModel; +import com.yahoo.prelude.SearchDefinition; import com.yahoo.prelude.query.SameElementItem; import org.junit.After; import org.junit.Before; @@ -31,19 +34,16 @@ import com.yahoo.search.searchchain.Execution; /** * Tests term lowercasing in the search chain. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class LowercasingTestCase { private static final String TEDDY = "teddy"; private static final String BAMSE = "bamse"; private static final String SARR = "sarr"; - IndexFacts settings; - Execution execution; - @Before - public void setUp() throws Exception { - IndexFacts f = new IndexFacts(); + private IndexFacts createIndexFacts() { + SearchDefinition sd = new SearchDefinition("nalle"); Index bamse = new Index(BAMSE); Index teddy = new Index(TEDDY); Index sarrBamse = new Index(SARR + "." + BAMSE); @@ -54,25 +54,22 @@ public class LowercasingTestCase { sarrBamse.setLowercase(true); sarrTeddy.setLowercase(true); defaultIndex.setLowercase(true); - f.addIndex("nalle", bamse); - f.addIndex("nalle", teddy); - f.addIndex("nalle", defaultIndex); - f.addIndex("nalle", sarrBamse); - f.addIndex("nalle", sarrTeddy); - f.freeze(); - settings = f; - execution = new Execution(new Chain<Searcher>( - new VespaLowercasingSearcher(new LowercasingConfig(new LowercasingConfig.Builder()))), - Execution.Context.createContextStub(settings)); + sd.addIndex(bamse); + sd.addIndex(teddy); + sd.addIndex(defaultIndex); + sd.addIndex(sarrBamse); + sd.addIndex(sarrTeddy); + return new IndexFacts(new IndexModel(Collections.emptyMap(), Collections.singleton(sd))); } - @After - public void tearDown() throws Exception { - execution = null; + private Execution createExecution() { + return new Execution(new Chain<Searcher>( + new VespaLowercasingSearcher(new LowercasingConfig(new LowercasingConfig.Builder()))), + Execution.Context.createContextStub(createIndexFacts())); } @Test - public void smoke() { + public void simple() { Query q = new Query(); AndItem root = new AndItem(); WordItem tmp; @@ -84,7 +81,7 @@ public class LowercasingTestCase { root.addItem(tmp); q.getModel().getQueryTree().setRoot(root); - Result r = execution.search(q); + Result r = createExecution().search(q); root = (AndItem) r.getQuery().getModel().getQueryTree().getRoot(); WordItem w0 = (WordItem) root.getItem(0); WordItem w1 = (WordItem) root.getItem(1); @@ -129,7 +126,7 @@ public class LowercasingTestCase { q.getModel().getQueryTree().setRoot(a0); - Result r = execution.search(q); + Result r = createExecution().search(q); AndItem root = (AndItem) r.getQuery().getModel().getQueryTree().getRoot(); tmp = (WordItem) root.getItem(0); assertEquals("nalle0", tmp.getWord()); @@ -162,7 +159,7 @@ public class LowercasingTestCase { tmp.addToken("dEf", 5); root.addItem(tmp); q.getModel().getQueryTree().setRoot(root); - Result r = execution.search(q); + Result r = createExecution().search(q); root = (AndItem) r.getQuery().getModel().getQueryTree().getRoot(); WeightedSetItem w0 = (WeightedSetItem) root.getItem(0); WeightedSetItem w1 = (WeightedSetItem) root.getItem(1); @@ -174,11 +171,11 @@ public class LowercasingTestCase { @Test public void testDisableLowercasingWeightedSet() { - execution = new Execution(new Chain<Searcher>( + Execution execution = new Execution(new Chain<Searcher>( new VespaLowercasingSearcher(new LowercasingConfig( new LowercasingConfig.Builder() .transform_weighted_sets(false)))), - Execution.Context.createContextStub(settings)); + Execution.Context.createContextStub(createIndexFacts())); Query q = new Query(); AndItem root = new AndItem(); @@ -202,8 +199,8 @@ public class LowercasingTestCase { @Test public void testLowercasingWordAlternatives() { - execution = new Execution(new Chain<Searcher>(new VespaLowercasingSearcher(new LowercasingConfig( - new LowercasingConfig.Builder().transform_weighted_sets(false)))), Execution.Context.createContextStub(settings)); + Execution execution = new Execution(new Chain<Searcher>(new VespaLowercasingSearcher(new LowercasingConfig( + new LowercasingConfig.Builder().transform_weighted_sets(false)))), Execution.Context.createContextStub(createIndexFacts())); Query q = new Query(); WordAlternativesItem root; @@ -224,17 +221,18 @@ public class LowercasingTestCase { } @Test - public void testLowercaseingSameElement() { + public void testLowercasingSameElement() { Query q = new Query(); SameElementItem root = new SameElementItem(SARR); root.addItem(new WordItem("ABC", BAMSE, true)); root.addItem(new WordItem("DEF", TEDDY, true)); q.getModel().getQueryTree().setRoot(root); - Result r = execution.search(q); + Result r = createExecution().search(q); root = (SameElementItem) r.getQuery().getModel().getQueryTree().getRoot(); WordItem w0 = (WordItem) root.getItem(0); WordItem w1 = (WordItem) root.getItem(1); assertEquals("abc", w0.getWord()); assertEquals("def", w1.getWord()); } + } diff --git a/container-search/src/test/java/com/yahoo/search/querytransform/WandSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/querytransform/WandSearcherTestCase.java index 93955da383e..c52cedaaf0e 100644 --- a/container-search/src/test/java/com/yahoo/search/querytransform/WandSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/querytransform/WandSearcherTestCase.java @@ -4,6 +4,8 @@ package com.yahoo.search.querytransform; import com.yahoo.component.chain.Chain; import com.yahoo.prelude.Index; import com.yahoo.prelude.IndexFacts; +import com.yahoo.prelude.IndexModel; +import com.yahoo.prelude.SearchDefinition; import com.yahoo.prelude.query.AndItem; import com.yahoo.prelude.query.DotProductItem; import com.yahoo.prelude.query.Item; @@ -20,6 +22,7 @@ import com.yahoo.search.searchchain.Execution; import org.junit.Before; import org.junit.Test; +import java.util.Collections; import java.util.ListIterator; import static com.yahoo.container.protect.Error.INVALID_QUERY_PARAMETER; @@ -40,10 +43,9 @@ public class WandSearcherTestCase { @SuppressWarnings("deprecation") private IndexFacts buildIndexFacts() { - IndexFacts retval = new IndexFacts(); - retval.addIndex("test", new Index(VESPA_FIELD)); - retval.freeze(); - return retval; + SearchDefinition sd = new SearchDefinition("test"); + sd.addIndex(new Index(VESPA_FIELD)); + return new IndexFacts(new IndexModel(Collections.emptyMap(), Collections.singleton(sd))); } private Execution buildExec() { diff --git a/container-search/src/test/java/com/yahoo/search/querytransform/test/NGramSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/querytransform/test/NGramSearcherTestCase.java index a3f7ff12319..60abac599c4 100644 --- a/container-search/src/test/java/com/yahoo/search/querytransform/test/NGramSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/querytransform/test/NGramSearcherTestCase.java @@ -2,15 +2,19 @@ package com.yahoo.search.querytransform.test; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import com.google.common.collect.ImmutableList; import com.yahoo.component.chain.Chain; import com.yahoo.language.Language; import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.prelude.Index; import com.yahoo.prelude.IndexFacts; +import com.yahoo.prelude.IndexModel; +import com.yahoo.prelude.SearchDefinition; import com.yahoo.prelude.hitfield.JSONString; import com.yahoo.prelude.hitfield.XMLString; import com.yahoo.prelude.query.AndItem; @@ -28,7 +32,6 @@ import com.yahoo.search.querytransform.NGramSearcher; import com.yahoo.search.result.Hit; import com.yahoo.search.result.HitGroup; import com.yahoo.search.searchchain.Execution; -import org.junit.Before; import org.junit.Test; import static com.yahoo.search.searchchain.Execution.Context.createContextStub; @@ -41,157 +44,151 @@ import static org.junit.Assert.assertTrue; */ public class NGramSearcherTestCase { - private Searcher searcher; - private IndexFacts indexFacts; - - @Before - public void setUp() { - searcher = new NGramSearcher(new SimpleLinguistics()); - indexFacts = new IndexFacts(); + public IndexFacts createIndexFacts() { + SearchDefinition sd = new SearchDefinition("default"); Index defaultIndex = new Index("default"); defaultIndex.setNGram(true, 3); defaultIndex.setDynamicSummary(true); - indexFacts.addIndex("default", defaultIndex); + sd.addIndex(defaultIndex); Index test = new Index("test"); test.setHighlightSummary(true); - indexFacts.addIndex("default", test); + sd.addIndex(test); Index gram2 = new Index("gram2"); gram2.setNGram(true, 2); gram2.setDynamicSummary(true); - indexFacts.addIndex("default", gram2); + sd.addIndex(gram2); Index gram3 = new Index("gram3"); gram3.setNGram(true, 3); gram3.setHighlightSummary(true); - indexFacts.addIndex("default", gram3); + sd.addIndex(gram3); Index gram14 = new Index("gram14"); gram14.setNGram(true, 14); gram14.setDynamicSummary(true); - indexFacts.addIndex("default", gram14); + sd.addIndex(gram14); + + return new IndexFacts(new IndexModel(Collections.emptyMap(), Collections.singleton(sd))); + } + + private Searcher createSearcher() { + return new NGramSearcher(new SimpleLinguistics()); } - private IndexFacts getMixedSetup() { - IndexFacts indexFacts = new IndexFacts(); - String musicDoctype = "music"; - String songDoctype = "song"; + public Execution createExecution() { + return new Execution(createSearcher(), Execution.Context.createContextStub(createIndexFacts())); + } + + private Execution createMixedSetupExecution() { + SearchDefinition music = new SearchDefinition("music"); Index musicDefault = new Index("default"); - musicDefault.setNGram(true, 1); - indexFacts.addIndex(musicDoctype, musicDefault); + musicDefault.addCommand("ngram 1"); + music.addIndex(musicDefault); + + SearchDefinition song = new SearchDefinition("song"); Index songDefault = new Index("default"); - indexFacts.addIndex(songDoctype, songDefault); + song.addIndex(songDefault); + Map<String, List<String>> clusters = new HashMap<>(); - clusters.put("musicOnly", Arrays.asList(new String[] { musicDoctype })); - clusters.put("songOnly", Arrays.asList(new String[] { songDoctype })); - clusters.put("musicAndSong", Arrays.asList(new String[] { musicDoctype, songDoctype })); - indexFacts.setClusters(clusters); - return indexFacts; + clusters.put("musicOnly", Collections.singletonList(music.getName())); + clusters.put("songOnly", Collections.singletonList(song.getName())); + clusters.put("musicAndSong", Arrays.asList(music.getName(), song.getName())); + + IndexFacts indexFacts = new IndexFacts(new IndexModel(clusters, ImmutableList.of(music, song))); + return new Execution(createSearcher(), Execution.Context.createContextStub(indexFacts)); } @Test public void testMixedDocTypes() { - final IndexFacts mixedSetup = getMixedSetup(); { Query q = new Query("?query=abc&restrict=song"); - new Execution(searcher, Execution.Context.createContextStub(mixedSetup)).search(q); + createMixedSetupExecution().search(q); assertEquals("abc", q.getModel().getQueryTree().toString()); } { Query q = new Query("?query=abc&restrict=music"); - new Execution(searcher, Execution.Context.createContextStub(mixedSetup)).search(q); - assertEquals("AND a b c", q.getModel().getQueryTree().toString()); - } - { - Query q = new Query("?query=abc"); - new Execution(searcher, Execution.Context.createContextStub(mixedSetup)).search(q); + createMixedSetupExecution().search(q); assertEquals("AND a b c", q.getModel().getQueryTree().toString()); } { Query q = new Query("?query=abc&search=song"); - new Execution(searcher, Execution.Context.createContextStub(mixedSetup)).search(q); + createMixedSetupExecution().search(q); assertEquals("abc", q.getModel().getQueryTree().toString()); } { Query q = new Query("?query=abc&search=music"); - new Execution(searcher, Execution.Context.createContextStub(mixedSetup)).search(q); + createMixedSetupExecution().search(q); assertEquals("AND a b c", q.getModel().getQueryTree().toString()); } } @Test public void testMixedClusters() { - final IndexFacts mixedSetup = getMixedSetup(); { Query q = new Query("?query=abc&search=songOnly"); - new Execution(searcher, Execution.Context.createContextStub(mixedSetup)).search(q); + createMixedSetupExecution().search(q); assertEquals("abc", q.getModel().getQueryTree().toString()); } { Query q = new Query("?query=abc&search=musicOnly"); - new Execution(searcher, Execution.Context.createContextStub(mixedSetup)).search(q); + createMixedSetupExecution().search(q); assertEquals("AND a b c", q.getModel().getQueryTree().toString()); } { Query q = new Query("?query=abc&search=musicAndSong&restrict=music"); - new Execution(searcher, Execution.Context.createContextStub(mixedSetup)).search(q); + createMixedSetupExecution().search(q); assertEquals("AND a b c", q.getModel().getQueryTree().toString()); } { Query q = new Query("?query=abc&search=musicAndSong&restrict=song"); - new Execution(searcher, Execution.Context.createContextStub(mixedSetup)).search(q); + createMixedSetupExecution().search(q); assertEquals("abc", q.getModel().getQueryTree().toString()); } } @Test - public void testClusterMappingWithMixedDoctypes() { - final IndexFacts mixedSetup = getMixedSetup(); - - } - - @Test public void testNGramRewritingMixedQuery() { - Query q=new Query("?query=foo+gram3:engul+test:bar"); - new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); - assertEquals("AND foo (AND gram3:eng gram3:ngu gram3:gul) test:bar",q.getModel().getQueryTree().toString()); + Query q = new Query("?query=foo+gram3:engul+test:bar"); + createExecution().search(q); + assertEquals("AND foo (AND gram3:eng gram3:ngu gram3:gul) test:bar", q.getModel().getQueryTree().toString()); } @Test public void testNGramRewritingNGramOnly() { - Query q=new Query("?query=gram3:engul"); - new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); - assertEquals("AND gram3:eng gram3:ngu gram3:gul",q.getModel().getQueryTree().toString()); + Query q = new Query("?query=gram3:engul"); + createExecution().search(q); + assertEquals("AND gram3:eng gram3:ngu gram3:gul", q.getModel().getQueryTree().toString()); } @Test public void testNGramRewriting2NGramsOnly() { - Query q=new Query("?query=gram3:engul+gram2:123"); - new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); - assertEquals("AND (AND gram3:eng gram3:ngu gram3:gul) (AND gram2:12 gram2:23)",q.getModel().getQueryTree().toString()); + Query q = new Query("?query=gram3:engul+gram2:123"); + createExecution().search(q); + assertEquals("AND (AND gram3:eng gram3:ngu gram3:gul) (AND gram2:12 gram2:23)", q.getModel().getQueryTree().toString()); } @Test public void testNGramRewritingShortOnly() { - Query q=new Query("?query=gram3:en"); - new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); - assertEquals("gram3:en",q.getModel().getQueryTree().toString()); + Query q = new Query("?query=gram3:en"); + createExecution().search(q); + assertEquals("gram3:en", q.getModel().getQueryTree().toString()); } @Test public void testNGramRewritingShortInMixes() { - Query q=new Query("?query=test:a+gram3:en"); - new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); - assertEquals("AND test:a gram3:en",q.getModel().getQueryTree().toString()); + Query q = new Query("?query=test:a+gram3:en"); + createExecution().search(q); + assertEquals("AND test:a gram3:en", q.getModel().getQueryTree().toString()); } @Test public void testNGramRewritingPhrase() { - Query q=new Query("?query=gram3:%22engul+a+holi%22"); - new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); - assertEquals("gram3:\"eng ngu gul a hol oli\"",q.getModel().getQueryTree().toString()); + Query q = new Query("?query=gram3:%22engul+a+holi%22"); + createExecution().search(q); + assertEquals("gram3:\"eng ngu gul a hol oli\"", q.getModel().getQueryTree().toString()); } /** @@ -200,159 +197,169 @@ public class NGramSearcherTestCase { */ @Test public void testNGramRewritingPhraseSingleTerm() { - Query q=new Query("?query=gram3:%22engul%22"); - new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); - assertEquals("AND gram3:eng gram3:ngu gram3:gul",q.getModel().getQueryTree().toString()); + Query q = new Query("?query=gram3:%22engul%22"); + createExecution().search(q); + assertEquals("AND gram3:eng gram3:ngu gram3:gul", q.getModel().getQueryTree().toString()); } @Test public void testNGramRewritingAdditionalTermInfo() { - Query q=new Query("?query=gram3:engul!50+foo+gram2:123!150"); - new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); - AndItem root=(AndItem)q.getModel().getQueryTree().getRoot(); - AndItem gram3And=(AndItem)root.getItem(0); - AndItem gram2And=(AndItem)root.getItem(2); - - assertExtraTermInfo(50,"engul",gram3And.getItem(0)); - assertExtraTermInfo(50,"engul",gram3And.getItem(1)); - assertExtraTermInfo(50,"engul",gram3And.getItem(2)); - assertExtraTermInfo(150,"123",gram2And.getItem(0)); - assertExtraTermInfo(150,"123",gram2And.getItem(1)); + Query q = new Query("?query=gram3:engul!50+foo+gram2:123!150"); + createExecution().search(q); + AndItem root = (AndItem)q.getModel().getQueryTree().getRoot(); + AndItem gram3And = (AndItem)root.getItem(0); + AndItem gram2And = (AndItem)root.getItem(2); + + assertExtraTermInfo(50, "engul", gram3And.getItem(0)); + assertExtraTermInfo(50, "engul", gram3And.getItem(1)); + assertExtraTermInfo(50, "engul", gram3And.getItem(2)); + assertExtraTermInfo(150, "123", gram2And.getItem(0)); + assertExtraTermInfo(150, "123", gram2And.getItem(1)); } - private void assertExtraTermInfo(int weight,String origin, Item g) { - WordItem gram=(WordItem)g; - assertEquals(weight,gram.getWeight()); - assertEquals(origin,gram.getOrigin().getValue()); + private void assertExtraTermInfo(int weight, String origin, Item g) { + WordItem gram = (WordItem)g; + assertEquals(weight, gram.getWeight()); + assertEquals(origin, gram.getOrigin().getValue()); assertTrue(gram.isProtected()); assertFalse(gram.isFromQuery()); } @Test public void testNGramRewritingExplicitDefault() { - Query q=new Query("?query=default:engul"); - new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); - assertEquals("AND default:eng default:ngu default:gul",q.getModel().getQueryTree().toString()); + Query q = new Query("?query=default:engul"); + createExecution().search(q); + assertEquals("AND default:eng default:ngu default:gul" ,q.getModel().getQueryTree().toString()); } @Test public void testNGramRewritingImplicitDefault() { - Query q=new Query("?query=engul"); - new Execution(searcher,Execution.Context.createContextStub(indexFacts)).search(q); - assertEquals("AND eng ngu gul",q.getModel().getQueryTree().toString()); + Query q = new Query("?query=engul"); + createExecution().search(q); + assertEquals("AND eng ngu gul", q.getModel().getQueryTree().toString()); } @Test public void testGramsWithSegmentation() { + Searcher searcher = createSearcher(); assertGramsWithSegmentation(new Chain<>(searcher)); - assertGramsWithSegmentation(new Chain<>(new CJKSearcher(),searcher)); - assertGramsWithSegmentation(new Chain<>(searcher,new CJKSearcher())); + assertGramsWithSegmentation(new Chain<>(new CJKSearcher(), searcher)); + assertGramsWithSegmentation(new Chain<>(searcher, new CJKSearcher())); } public void assertGramsWithSegmentation(Chain<Searcher> chain) { // "first" "second" and "third" are segments in the "test" language Item item = parseQuery("gram14:firstsecondthird", Query.Type.ANY); - Query q=new Query("?query=ignored"); + Query q = new Query("?query=ignored"); q.getModel().setLanguage(Language.UNKNOWN); q.getModel().getQueryTree().setRoot(item); - new Execution(chain,createContextStub(indexFacts)).search(q); - assertEquals("AND gram14:firstsecondthi gram14:irstsecondthir gram14:rstsecondthird",q.getModel().getQueryTree().toString()); + new Execution(chain, createContextStub(createIndexFacts())).search(q); + assertEquals("AND gram14:firstsecondthi gram14:irstsecondthir gram14:rstsecondthird", q.getModel().getQueryTree().toString()); } @Test public void testGramsWithSegmentationSingleSegment() { + Searcher searcher = createSearcher(); assertGramsWithSegmentationSingleSegment(new Chain<>(searcher)); - assertGramsWithSegmentationSingleSegment(new Chain<>(new CJKSearcher(),searcher)); - assertGramsWithSegmentationSingleSegment(new Chain<>(searcher,new CJKSearcher())); + assertGramsWithSegmentationSingleSegment(new Chain<>(new CJKSearcher(), searcher)); + assertGramsWithSegmentationSingleSegment(new Chain<>(searcher, new CJKSearcher())); } public void assertGramsWithSegmentationSingleSegment(Chain<Searcher> chain) { // "first" "second" and "third" are segments in the "test" language Item item = parseQuery("gram14:first", Query.Type.ANY); - Query q=new Query("?query=ignored"); + Query q = new Query("?query=ignored"); q.getModel().setLanguage(Language.UNKNOWN); q.getModel().getQueryTree().setRoot(item); - new Execution(chain,createContextStub(indexFacts)).search(q); - assertEquals("gram14:first",q.getModel().getQueryTree().toString()); + new Execution(chain, createContextStub(createIndexFacts())).search(q); + assertEquals("gram14:first", q.getModel().getQueryTree().toString()); } @Test public void testGramsWithSegmentationSubstringSegmented() { + Searcher searcher = createSearcher(); assertGramsWithSegmentationSubstringSegmented(new Chain<>(searcher)); - assertGramsWithSegmentationSubstringSegmented(new Chain<>(new CJKSearcher(),searcher)); - assertGramsWithSegmentationSubstringSegmented(new Chain<>(searcher,new CJKSearcher())); + assertGramsWithSegmentationSubstringSegmented(new Chain<>(new CJKSearcher(), searcher)); + assertGramsWithSegmentationSubstringSegmented(new Chain<>(searcher, new CJKSearcher())); } public void assertGramsWithSegmentationSubstringSegmented(Chain<Searcher> chain) { // "first" "second" and "third" are segments in the "test" language Item item = parseQuery("gram14:afirstsecondthirdo", Query.Type.ANY); - Query q=new Query("?query=ignored"); + Query q = new Query("?query=ignored"); q.getModel().setLanguage(Language.UNKNOWN); q.getModel().getQueryTree().setRoot(item); - new Execution(chain,createContextStub(indexFacts)).search(q); - assertEquals("AND gram14:afirstsecondth gram14:firstsecondthi gram14:irstsecondthir gram14:rstsecondthird gram14:stsecondthirdo",q.getModel().getQueryTree().toString()); + new Execution(chain, createContextStub(createIndexFacts())).search(q); + assertEquals("AND gram14:afirstsecondth gram14:firstsecondthi gram14:irstsecondthir gram14:rstsecondthird gram14:stsecondthirdo", + q.getModel().getQueryTree().toString()); } @Test public void testGramsWithSegmentationMixed() { + Searcher searcher = createSearcher(); assertGramsWithSegmentationMixed(new Chain<>(searcher)); - assertGramsWithSegmentationMixed(new Chain<>(new CJKSearcher(),searcher)); - assertGramsWithSegmentationMixed(new Chain<>(searcher,new CJKSearcher())); + assertGramsWithSegmentationMixed(new Chain<>(new CJKSearcher(), searcher)); + assertGramsWithSegmentationMixed(new Chain<>(searcher, new CJKSearcher())); } public void assertGramsWithSegmentationMixed(Chain<Searcher> chain) { // "first" "second" and "third" are segments in the "test" language Item item = parseQuery("a gram14:afirstsecondthird b gram14:hi", Query.Type.ALL); - Query q=new Query("?query=ignored"); + Query q = new Query("?query=ignored"); q.getModel().setLanguage(Language.UNKNOWN); q.getModel().getQueryTree().setRoot(item); - new Execution(chain,createContextStub(indexFacts)).search(q); - assertEquals("AND a (AND gram14:afirstsecondth gram14:firstsecondthi gram14:irstsecondthir gram14:rstsecondthird) b gram14:hi",q.getModel().getQueryTree().toString()); + new Execution(chain, createContextStub(createIndexFacts())).search(q); + assertEquals("AND a (AND gram14:afirstsecondth gram14:firstsecondthi gram14:irstsecondthir gram14:rstsecondthird) b gram14:hi", + q.getModel().getQueryTree().toString()); } @Test public void testGramsWithSegmentationMixedAndPhrases() { + Searcher searcher = createSearcher(); assertGramsWithSegmentationMixedAndPhrases(new Chain<>(searcher)); - assertGramsWithSegmentationMixedAndPhrases(new Chain<>(new CJKSearcher(),searcher)); - assertGramsWithSegmentationMixedAndPhrases(new Chain<>(searcher,new CJKSearcher())); + assertGramsWithSegmentationMixedAndPhrases(new Chain<>(new CJKSearcher(), searcher)); + assertGramsWithSegmentationMixedAndPhrases(new Chain<>(searcher, new CJKSearcher())); } public void assertGramsWithSegmentationMixedAndPhrases(Chain<Searcher> chain) { // "first" "second" and "third" are segments in the "test" language Item item = parseQuery("a gram14:\"afirstsecondthird b hi\"", Query.Type.ALL); - Query q=new Query("?query=ignored"); + Query q = new Query("?query=ignored"); q.getModel().setLanguage(Language.UNKNOWN); q.getModel().getQueryTree().setRoot(item); - new Execution(chain,createContextStub(indexFacts)).search(q); - assertEquals("AND a gram14:\"afirstsecondth firstsecondthi irstsecondthir rstsecondthird b hi\"",q.getModel().getQueryTree().toString()); + new Execution(chain, createContextStub(createIndexFacts())).search(q); + assertEquals("AND a gram14:\"afirstsecondth firstsecondthi irstsecondthir rstsecondthird b hi\"", + q.getModel().getQueryTree().toString()); } @Test public void testNGramRecombining() { - Query q=new Query("?query=ignored"); - Result r=new Execution(new Chain<>(searcher,new MockBackend1()),createContextStub(indexFacts)).search(q); - Hit h1=r.hits().get("hit1"); - assertEquals("Should be untouched,\u001feven if containing \u001f",h1.getField("test").toString()); + Query q = new Query("?query=ignored"); + Result r = new Execution(new Chain<>(createSearcher(), new MockBackend1()), createContextStub(createIndexFacts())).search(q); + Hit h1 = r.hits().get("hit1"); + assertEquals("Should be untouched,\u001feven if containing \u001f", + h1.getField("test").toString()); assertTrue(h1.getField("test") instanceof String); assertEquals("Blue red Ed A",h1.getField("gram2").toString()); assertTrue(h1.getField("gram2") instanceof XMLString); - assertEquals("Separators on borders work","Blue red ed a\u001f",h1.getField("gram3").toString()); + assertEquals("Separators on borders work","Blue red ed a\u001f", + h1.getField("gram3").toString()); assertTrue(h1.getField("gram3") instanceof String); - Hit h2=r.hits().get("hit2"); - assertEquals("katt i...morgen",h2.getField("gram3").toString()); + Hit h2 = r.hits().get("hit2"); + assertEquals("katt i...morgen", h2.getField("gram3").toString()); assertTrue(h2.getField("gram3") instanceof JSONString); - Hit h3=r.hits().get("hit3"); - assertEquals("\u001ffin\u001f \u001fen\u001f \u001fa\u001f",h3.getField("gram2").toString()); + Hit h3 = r.hits().get("hit3"); + assertEquals("\u001ffin\u001f \u001fen\u001f \u001fa\u001f", h3.getField("gram2").toString()); assertEquals("#Logging in #Java is like that \"Judean P\u001fopul\u001far Front\" scene from \"Life of Brian\".", h3.getField("gram3").toString()); } private Item parseQuery(String query, Query.Type type) { - Parser parser = ParserFactory.newInstance(type, new ParserEnvironment().setIndexFacts(indexFacts)); + Parser parser = ParserFactory.newInstance(type, new ParserEnvironment().setIndexFacts(createIndexFacts())); return parser.parse(new Parsable().setQuery(query).setLanguage(Language.UNKNOWN)).getRoot(); } @@ -360,31 +367,32 @@ public class NGramSearcherTestCase { @Override public Result search(Query query, Execution execution) { - Result r=new Result(query); - HitGroup g=new HitGroup(); + Result r = new Result(query); + HitGroup g = new HitGroup(); r.hits().add(g); - Hit h1=new Hit("hit1"); - h1.setField(Hit.SDDOCNAME_FIELD,"default"); - h1.setField("test","Should be untouched,\u001feven if containing \u001f"); - h1.setField("gram2",new XMLString("\uFFF9Bl\uFFFAbl\uFFFBluue reed \uFFF9Ed\uFFFAed\uFFFB \uFFF9A\uFFFAa\uFFFB")); - h1.setField("gram3","\uFFF9Blu\uFFFAblu\uFFFBlue red ed a\u001f"); // separator on borders should not trip anything + Hit h1 = new Hit("hit1"); + h1.setField(Hit.SDDOCNAME_FIELD, "default"); + h1.setField("test", "Should be untouched,\u001feven if containing \u001f"); + h1.setField("gram2", new XMLString("\uFFF9Bl\uFFFAbl\uFFFBluue reed \uFFF9Ed\uFFFAed\uFFFB \uFFF9A\uFFFAa\uFFFB")); + h1.setField("gram3", "\uFFF9Blu\uFFFAblu\uFFFBlue red ed a\u001f"); // separator on borders should not trip anything g.add(h1); - Hit h2=new Hit("hit2"); - h2.setField(Hit.SDDOCNAME_FIELD,"default"); - h2.setField("gram3",new JSONString("katatt i...mororgrgegen")); + Hit h2 = new Hit("hit2"); + h2.setField(Hit.SDDOCNAME_FIELD, "default"); + h2.setField("gram3", new JSONString("katatt i...mororgrgegen")); r.hits().add(h2); // Test bolding - Hit h3=new Hit("hit3"); - h3.setField(Hit.SDDOCNAME_FIELD,"default"); + Hit h3 = new Hit("hit3"); + h3.setField(Hit.SDDOCNAME_FIELD, "default"); // the result of searching for "fin en a" - h3.setField("gram2","\u001ffi\u001f\u001fin\u001f \u001fen\u001f \u001fa\u001f"); + h3.setField("gram2", "\u001ffi\u001f\u001fin\u001f \u001fen\u001f \u001fa\u001f"); // the result from Juniper from of bolding the substring "opul": - h3.setField("gram3","#Logoggggigining in #Javava is likike thahat \"Jududedeaean Pop\u001fopu\u001f\u001fpul\u001fulalar Froronont\" scecenene frorom \"Lifife of Bririaian\"."); + h3.setField("gram3", + "#Logoggggigining in #Javava is likike thahat \"Jududedeaean Pop\u001fopu\u001f\u001fpul\u001fulalar Froronont\" scecenene frorom \"Lifife of Bririaian\"."); r.hits().add(h3); return r; } |