diff options
author | Jon Bratseth <bratseth@gmail.com> | 2023-03-30 09:31:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-30 09:31:47 +0200 |
commit | 50e8eb5dcd0e3c40bfb9cd28c8a185e7b57f614c (patch) | |
tree | 66da3e2b98c57980b1d812471970ae5033e139cd | |
parent | 904eac185da61419c9c7e244835c1704c318c134 (diff) | |
parent | 656e755c584897d298fcf95bea5376f1fb1c13f5 (diff) |
Merge pull request #26631 from vespa-engine/balder/use-compoundname-from-in-tests-and-static-usage
Use CompoundName.from in tests and construction of static objects.
51 files changed, 330 insertions, 329 deletions
diff --git a/container-core/src/main/java/com/yahoo/processing/Request.java b/container-core/src/main/java/com/yahoo/processing/Request.java index cff546f1fd4..313df855cd4 100644 --- a/container-core/src/main/java/com/yahoo/processing/Request.java +++ b/container-core/src/main/java/com/yahoo/processing/Request.java @@ -30,13 +30,13 @@ public class Request extends FreezableClass implements Cloneable { * The name of the chain of Processor instances which will be invoked when * executing a request. */ - public static final CompoundName CHAIN = new CompoundName("chain"); + public static final CompoundName CHAIN = CompoundName.from("chain"); /** * The name of the request property used in the processing framework to * store the incoming JDisc request. */ - public static final CompoundName JDISC_REQUEST = new CompoundName("jdisc.request"); + public static final CompoundName JDISC_REQUEST = CompoundName.from("jdisc.request"); /** * Creates a request with no properties diff --git a/container-core/src/main/java/com/yahoo/processing/Response.java b/container-core/src/main/java/com/yahoo/processing/Response.java index 59533900a0c..9f87f42ba65 100644 --- a/container-core/src/main/java/com/yahoo/processing/Response.java +++ b/container-core/src/main/java/com/yahoo/processing/Response.java @@ -35,7 +35,7 @@ import java.util.concurrent.TimeoutException; */ public class Response extends ListenableFreezableClass { - private final static CompoundName freezeListenerKey =new CompoundName("processing.freezeListener"); + private final static CompoundName freezeListenerKey = CompoundName.from("processing.freezeListener"); private final DataList<?> data; diff --git a/container-core/src/main/java/com/yahoo/processing/handler/AbstractProcessingHandler.java b/container-core/src/main/java/com/yahoo/processing/handler/AbstractProcessingHandler.java index f7aea8abbd1..a838af263c1 100644 --- a/container-core/src/main/java/com/yahoo/processing/handler/AbstractProcessingHandler.java +++ b/container-core/src/main/java/com/yahoo/processing/handler/AbstractProcessingHandler.java @@ -46,7 +46,7 @@ import static com.yahoo.component.chain.ChainsConfigurer.prepareChainRegistry; @SuppressWarnings("deprecation") // super class is deprecated public abstract class AbstractProcessingHandler<COMPONENT extends Processor> extends LoggingRequestHandler { - private final static CompoundName freezeListenerKey =new CompoundName("processing.freezeListener"); + private final static CompoundName freezeListenerKey = CompoundName.from("processing.freezeListener"); public final static String DEFAULT_RENDERER_ID = "default"; diff --git a/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java b/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java index ac7b3d24d08..194fcd37bd1 100644 --- a/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java +++ b/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java @@ -21,9 +21,12 @@ import static com.yahoo.text.Lowercase.toLowerCase; */ public final class CompoundName { - /** - * The string name of this compound. - */ + private static final int MAX_CACHE_SIZE = 10_000; + private static final Map<String, CompoundName> cache = new CopyOnWriteHashMap<>(); + /** The empty compound */ + public static final CompoundName empty = CompoundName.from(""); + + /* The string name of this compound. */ private final String name; private final String lowerCasedName; @@ -37,10 +40,6 @@ public final class CompoundName { /** This name with the last component removed */ private final CompoundName first; - /** The empty compound */ - public static final CompoundName empty = new CompoundName(""); - private static final Map<String, CompoundName> cache = new CopyOnWriteHashMap<>(); - private static final int MAX_CACHE_SIZE = 10_000; /** * Constructs this from a string which may contains dot-separated components * diff --git a/container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java b/container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java index 4bbece0af29..eccc4dd8842 100644 --- a/container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java +++ b/container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java @@ -18,59 +18,61 @@ import static org.junit.jupiter.api.Assertions.*; public class CompoundNameTestCase { private static final String NAME = "com.yahoo.processing.request.CompoundNameTestCase"; - private final CompoundName cn = new CompoundName(NAME); + private static final CompoundName C_NAME = CompoundName.from(NAME); + private static final CompoundName C_abcde = CompoundName.from("a.b.c.d.e"); void verifyStrict(CompoundName expected, CompoundName actual) { assertEquals(expected, actual); assertEquals(expected.asList(), actual.asList()); } void verifyStrict(String expected, CompoundName actual) { - verifyStrict(new CompoundName(expected), actual); + verifyStrict(CompoundName.from(expected), actual); } @Test final void testLast() { - assertEquals(NAME.substring(NAME.lastIndexOf('.') + 1), cn.last()); + assertEquals(NAME.substring(NAME.lastIndexOf('.') + 1), C_NAME.last()); } @Test final void testFirst() { - assertEquals(NAME.substring(0, NAME.indexOf('.')), cn.first()); + assertEquals(NAME.substring(0, NAME.indexOf('.')), C_NAME.first()); } @Test final void testRest() { - verifyStrict(NAME.substring(NAME.indexOf('.') + 1), cn.rest()); + verifyStrict(NAME.substring(NAME.indexOf('.') + 1), C_NAME.rest()); } @Test final void testRestN() { - verifyStrict("a.b.c.d.e", new CompoundName("a.b.c.d.e").rest(0)); - verifyStrict("b.c.d.e", new CompoundName("a.b.c.d.e").rest(1)); - verifyStrict("c.d.e", new CompoundName("a.b.c.d.e").rest(2)); - verifyStrict("d.e", new CompoundName("a.b.c.d.e").rest(3)); - verifyStrict("e", new CompoundName("a.b.c.d.e").rest(4)); - verifyStrict(CompoundName.empty, new CompoundName("a.b.c.d.e").rest(5)); + verifyStrict("a.b.c.d.e", C_abcde.rest(0)); + verifyStrict("b.c.d.e", C_abcde.rest(1)); + verifyStrict("c.d.e", C_abcde.rest(2)); + verifyStrict("d.e", C_abcde.rest(3)); + verifyStrict("e", C_abcde.rest(4)); + verifyStrict(CompoundName.empty, C_abcde.rest(5)); } @Test final void testFirstN() { - verifyStrict("a.b.c.d.e", new CompoundName("a.b.c.d.e").first(5)); - verifyStrict("a.b.c.d", new CompoundName("a.b.c.d.e").first(4)); - verifyStrict("a.b.c", new CompoundName("a.b.c.d.e").first(3)); - verifyStrict("a.b", new CompoundName("a.b.c.d.e").first(2)); - verifyStrict("a", new CompoundName("a.b.c.d.e").first(1)); - verifyStrict(CompoundName.empty, new CompoundName("a.b.c.d.e").first(0)); + verifyStrict("a.b.c.d.e", C_abcde.first(5)); + verifyStrict("a.b.c.d", C_abcde.first(4)); + verifyStrict("a.b.c", C_abcde.first(3)); + verifyStrict("a.b", C_abcde.first(2)); + verifyStrict("a", C_abcde.first(1)); + verifyStrict(CompoundName.empty, C_abcde.first(0)); } @Test final void testPrefix() { - assertTrue(new CompoundName("a.b.c").hasPrefix(new CompoundName(""))); - assertTrue(new CompoundName("a.b.c").hasPrefix(new CompoundName("a"))); - assertTrue(new CompoundName("a.b.c").hasPrefix(new CompoundName("a.b"))); - assertTrue(new CompoundName("a.b.c").hasPrefix(new CompoundName("a.b.c"))); + CompoundName abc = CompoundName.from("a.b.c"); + assertTrue(abc.hasPrefix(CompoundName.empty)); + assertTrue(abc.hasPrefix(CompoundName.from("a"))); + assertTrue(abc.hasPrefix(CompoundName.from("a.b"))); + assertTrue(abc.hasPrefix(CompoundName.from("a.b.c"))); - assertFalse(new CompoundName("a.b.c").hasPrefix(new CompoundName("a.b.c.d"))); - assertFalse(new CompoundName("a.b.c").hasPrefix(new CompoundName("a.b.d"))); + assertFalse(abc.hasPrefix(CompoundName.from("a.b.c.d"))); + assertFalse(abc.hasPrefix(CompoundName.from("a.b.d"))); } @Test @@ -87,28 +89,28 @@ public class CompoundNameTestCase { for (@SuppressWarnings("unused") String x : i) { ++n; } - assertEquals(n, cn.size()); + assertEquals(n, C_NAME.size()); } @Test final void testGet() { - String s = cn.get(0); + String s = C_NAME.get(0); assertEquals(NAME.substring(0, NAME.indexOf('.')), s); } @Test final void testIsCompound() { - assertTrue(cn.isCompound()); + assertTrue(C_NAME.isCompound()); } @Test final void testIsEmpty() { - assertFalse(cn.isEmpty()); + assertFalse(C_NAME.isEmpty()); } @Test final void testAsList() { - List<String> l = cn.asList(); + List<String> l = C_NAME.asList(); Splitter peoplesFront = Splitter.on('.'); Iterable<String> answer = peoplesFront.split(NAME); Iterator<String> expected = answer.iterator(); @@ -120,35 +122,35 @@ public class CompoundNameTestCase { @Test final void testEqualsObject() { - assertNotEquals(cn, NAME); - assertNotEquals(cn, null); - verifyStrict(cn, cn); - verifyStrict(cn, new CompoundName(NAME)); + assertNotEquals(C_NAME, NAME); + assertNotEquals(C_NAME, null); + verifyStrict(C_NAME, C_NAME); + verifyStrict(C_NAME, CompoundName.from(NAME)); } @Test final void testEmptyNonEmpty() { - assertTrue(new CompoundName("").isEmpty()); - assertEquals(0, new CompoundName("").size()); - assertFalse(new CompoundName("a").isEmpty()); - assertEquals(1, new CompoundName("a").size()); - CompoundName empty = new CompoundName("a.b.c"); + assertTrue(CompoundName.empty.isEmpty()); + assertEquals(0, CompoundName.empty.size()); + assertFalse(CompoundName.from("a").isEmpty()); + assertEquals(1, CompoundName.from("a").size()); + CompoundName empty = CompoundName.from("a.b.c"); verifyStrict(empty, empty.rest(0)); assertNotEquals(empty, empty.rest(1)); } @Test final void testGetLowerCasedName() { - assertEquals(Lowercase.toLowerCase(NAME), cn.getLowerCasedName()); + assertEquals(Lowercase.toLowerCase(NAME), C_NAME.getLowerCasedName()); } @Test void testAppendCompound() { - verifyStrict("a.b.c.d", new CompoundName("").append(new CompoundName("a.b.c.d"))); - verifyStrict("a.b.c.d", new CompoundName("a").append(new CompoundName("b.c.d"))); - verifyStrict("a.b.c.d", new CompoundName("a.b").append(new CompoundName("c.d"))); - verifyStrict("a.b.c.d", new CompoundName("a.b.c").append(new CompoundName("d"))); - verifyStrict("a.b.c.d", new CompoundName("a.b.c.d").append(new CompoundName(""))); + verifyStrict("a.b.c.d", CompoundName.empty.append(CompoundName.from("a.b.c.d"))); + verifyStrict("a.b.c.d", CompoundName.from("a").append(CompoundName.from("b.c.d"))); + verifyStrict("a.b.c.d", CompoundName.from("a.b").append(CompoundName.from("c.d"))); + verifyStrict("a.b.c.d", CompoundName.from("a.b.c").append(CompoundName.from("d"))); + verifyStrict("a.b.c.d", CompoundName.from("a.b.c.d").append(CompoundName.empty)); } @Test @@ -156,13 +158,13 @@ public class CompoundNameTestCase { CompoundName empty = new CompoundName(""); assertTrue(empty.hasPrefix(empty)); - assertTrue(new CompoundName("a").hasPrefix(empty)); + assertTrue(CompoundName.from("a").hasPrefix(empty)); } @Test void whole_components_must_match_to_be_prefix() { - CompoundName stringPrefix = new CompoundName("a"); - CompoundName name = new CompoundName("aa"); + CompoundName stringPrefix = CompoundName.from("a"); + CompoundName name = CompoundName.from("aa"); assertFalse(name.hasPrefix(stringPrefix)); } @@ -171,7 +173,7 @@ public class CompoundNameTestCase { void testFirstRest() { verifyStrict(CompoundName.empty, CompoundName.empty.rest()); - CompoundName n = new CompoundName("on.two.three"); + CompoundName n = CompoundName.from("on.two.three"); assertEquals("on", n.first()); verifyStrict("two.three", n.rest()); n = n.rest(); @@ -190,7 +192,7 @@ public class CompoundNameTestCase { @Test void testHashCodeAndEquals() { - CompoundName n1 = new CompoundName("venn.d.a"); + CompoundName n1 = CompoundName.from("venn.d.a"); CompoundName n2 = new CompoundName(n1.asList()); assertEquals(n1.hashCode(), n2.hashCode()); verifyStrict(n1, n2); @@ -198,12 +200,12 @@ public class CompoundNameTestCase { @Test void testAppendString() { - verifyStrict("a", new CompoundName("a").append("")); - verifyStrict("a", new CompoundName("").append("a")); - verifyStrict("a.b", new CompoundName("a").append("b")); - verifyStrict("a.b.c.d", new CompoundName("a.b").append("c.d")); + verifyStrict("a", CompoundName.from("a").append("")); + verifyStrict("a", CompoundName.empty.append("a")); + verifyStrict("a.b", CompoundName.from("a").append("b")); + verifyStrict("a.b.c.d", CompoundName.from("a.b").append("c.d")); - CompoundName name = new CompoundName("a.b"); + CompoundName name = CompoundName.from("a.b"); verifyStrict("a.b.c", name.append("c")); verifyStrict("a.b.d", name.append("d")); verifyStrict("a.b.d.e", name.append("d.e")); @@ -218,7 +220,7 @@ public class CompoundNameTestCase { @Test void testAsList2() { - assertEquals("[one]", new CompoundName("one").asList().toString()); - assertEquals("[one, two, three]", new CompoundName("one.two.three").asList().toString()); + assertEquals("[one]", CompoundName.from("one").asList().toString()); + assertEquals("[one, two, three]", CompoundName.from("one.two.three").asList().toString()); } } diff --git a/container-core/src/test/java/com/yahoo/processing/request/test/RequestTestCase.java b/container-core/src/test/java/com/yahoo/processing/request/test/RequestTestCase.java index c82b85d84d9..8e960bd1305 100644 --- a/container-core/src/test/java/com/yahoo/processing/request/test/RequestTestCase.java +++ b/container-core/src/test/java/com/yahoo/processing/request/test/RequestTestCase.java @@ -9,7 +9,9 @@ import com.yahoo.processing.request.properties.PropertyMap; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests using requests @@ -19,9 +21,26 @@ import static org.junit.jupiter.api.Assertions.assertNull; public class RequestTestCase { private static final double delta = 0.0000000001; + private static final CompoundName C_a = CompoundName.from("a"); + + private static final CompoundName C_B = CompoundName.from("b"); + private static final CompoundName C_C = CompoundName.from("c"); + private static final CompoundName C_D = CompoundName.from("d"); + private static final CompoundName C_f = CompoundName.from("f"); + private static final CompoundName C_g = CompoundName.from("g"); + private static final CompoundName C_I = CompoundName.from("i"); + private static final CompoundName C_L = CompoundName.from("l"); + private static final CompoundName C_M = CompoundName.from("m"); + private static final CompoundName C_N = CompoundName.from("n"); + private static final CompoundName C_o = CompoundName.from("o"); + private static final CompoundName C_x = CompoundName.from("x"); + private static final CompoundName C_none = CompoundName.from("none"); + + @Test void testProperties() { + Properties p = new PropertyMap(); p.set("a", "a1"); Request r = new Request(p); @@ -33,38 +52,38 @@ public class RequestTestCase { assertEquals("b1", r.properties().get("b", "default")); assertEquals("default", r.properties().get("c", "default")); assertNull(r.properties().get("c")); - assertEquals("b1", r.properties().get(new CompoundName("b"))); - assertEquals("b1", r.properties().get(new CompoundName("b"), "default")); - assertEquals("default", r.properties().get(new CompoundName("c"), "default")); - assertNull(r.properties().get(new CompoundName("c"))); + assertEquals("b1", r.properties().get(C_B)); + assertEquals("b1", r.properties().get(C_B, "default")); + assertEquals("default", r.properties().get(C_C, "default")); + assertNull(r.properties().get(C_C)); assertEquals("b1", r.properties().getString("b")); assertEquals("b1", r.properties().getString("b", "default")); assertEquals("default", r.properties().getString("c", "default")); assertNull(r.properties().getString("c")); - assertEquals("b1", r.properties().getString(new CompoundName("b"))); - assertEquals("b1", r.properties().getString(new CompoundName("b"), "default")); - assertEquals("default", r.properties().getString(new CompoundName("c"), "default")); - assertNull(r.properties().getString(new CompoundName("c"))); + assertEquals("b1", r.properties().getString(C_B)); + assertEquals("b1", r.properties().getString(C_B, "default")); + assertEquals("default", r.properties().getString(C_C, "default")); + assertNull(r.properties().getString(C_C)); r.properties().set("i", 7); assertEquals(7, (int) r.properties().getInteger("i")); assertEquals(7, (int) r.properties().getInteger("i", 3)); assertEquals(3, (int) r.properties().getInteger("n", 3)); assertNull(r.properties().getInteger("n")); - assertEquals(7, (int) r.properties().getInteger(new CompoundName("i"))); - assertEquals(7, (int) r.properties().getInteger(new CompoundName("i"), 3)); - assertEquals(3, (int) r.properties().getInteger(new CompoundName("n"), 3)); + assertEquals(7, (int) r.properties().getInteger(C_I)); + assertEquals(7, (int) r.properties().getInteger(C_I, 3)); + assertEquals(3, (int) r.properties().getInteger(C_N, 3)); assertNull(r.properties().getInteger("n")); - r.properties().set(new CompoundName("l"), 7); + r.properties().set(C_L, 7); assertEquals(7, (long) r.properties().getLong("l")); - assertEquals(7, (long) r.properties().getLong("l", 3l)); - assertEquals(3, (long) r.properties().getLong("m", 3l)); + assertEquals(7, (long) r.properties().getLong("l", 3L)); + assertEquals(3, (long) r.properties().getLong("m", 3L)); assertNull(r.properties().getInteger("m")); - assertEquals(7, (long) r.properties().getLong(new CompoundName("l"))); - assertEquals(7, (long) r.properties().getLong(new CompoundName("l"), 3l)); - assertEquals(3, (long) r.properties().getLong(new CompoundName("m"), 3l)); + assertEquals(7, (long) r.properties().getLong(C_L)); + assertEquals(7, (long) r.properties().getLong(C_L, 3L)); + assertEquals(3, (long) r.properties().getLong(C_M, 3L)); assertNull(r.properties().getInteger("m")); r.properties().set("d", 7.3); @@ -72,29 +91,29 @@ public class RequestTestCase { assertEquals(7.3, r.properties().getDouble("d", 3.4d), delta); assertEquals(3.4, r.properties().getDouble("f", 3.4d), delta); assertNull(r.properties().getDouble("f")); - assertEquals(7.3, r.properties().getDouble(new CompoundName("d")), delta); - assertEquals(7.3, r.properties().getDouble(new CompoundName("d"), 3.4d), delta); - assertEquals(3.4, r.properties().getDouble(new CompoundName("f"), 3.4d), delta); + assertEquals(7.3, r.properties().getDouble(C_D), delta); + assertEquals(7.3, r.properties().getDouble(C_D, 3.4d), delta); + assertEquals(3.4, r.properties().getDouble(C_f, 3.4d), delta); assertNull(r.properties().getDouble("f")); r.properties().set("o", true); - assertEquals(true, r.properties().getBoolean("o")); - assertEquals(true, r.properties().getBoolean("o", true)); - assertEquals(true, r.properties().getBoolean("g", true)); - assertEquals(false, r.properties().getBoolean("g")); - assertEquals(true, r.properties().getBoolean(new CompoundName("o"))); - assertEquals(true, r.properties().getBoolean(new CompoundName("o"), true)); - assertEquals(true, r.properties().getBoolean(new CompoundName("g"), true)); - assertEquals(false, r.properties().getBoolean("g")); - - r.properties().set(new CompoundName("x.y"), "x1.y1"); + assertTrue(r.properties().getBoolean("o")); + assertTrue(r.properties().getBoolean("o", true)); + assertTrue(r.properties().getBoolean("g", true)); + assertFalse(r.properties().getBoolean("g")); + assertTrue(r.properties().getBoolean(C_o)); + assertTrue(r.properties().getBoolean(C_o, true)); + assertTrue(r.properties().getBoolean(C_g, true)); + assertFalse(r.properties().getBoolean("g")); + + r.properties().set(CompoundName.from("x.y"), "x1.y1"); r.properties().set("x.z", "x1.z1"); assertEquals(8, r.properties().listProperties().size()); assertEquals(0, r.properties().listProperties("a").size()); - assertEquals(0, r.properties().listProperties(new CompoundName("a")).size()); - assertEquals(0, r.properties().listProperties(new CompoundName("none")).size()); - assertEquals(2, r.properties().listProperties(new CompoundName("x")).size()); + assertEquals(0, r.properties().listProperties(C_a).size()); + assertEquals(0, r.properties().listProperties(C_none).size()); + assertEquals(2, r.properties().listProperties(C_x).size()); assertEquals(2, r.properties().listProperties("x").size()); } diff --git a/container-search/src/main/java/com/yahoo/prelude/querytransform/NonPhrasingSearcher.java b/container-search/src/main/java/com/yahoo/prelude/querytransform/NonPhrasingSearcher.java index 6bae5175d84..1eb7eb8abe7 100644 --- a/container-search/src/main/java/com/yahoo/prelude/querytransform/NonPhrasingSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/querytransform/NonPhrasingSearcher.java @@ -22,7 +22,7 @@ import java.util.List; @Before("transformedQuery") public class NonPhrasingSearcher extends Searcher { - private static final CompoundName suggestonly=new CompoundName("suggestonly"); + private static final CompoundName suggestonly = CompoundName.from("suggestonly"); private PhraseMatcher phraseMatcher; diff --git a/container-search/src/main/java/com/yahoo/prelude/querytransform/PhrasingSearcher.java b/container-search/src/main/java/com/yahoo/prelude/querytransform/PhrasingSearcher.java index b67ddade7ee..4da61f5eeca 100644 --- a/container-search/src/main/java/com/yahoo/prelude/querytransform/PhrasingSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/querytransform/PhrasingSearcher.java @@ -29,7 +29,7 @@ import java.util.List; @Provides(PhrasingSearcher.PHRASE_REPLACEMENT) public class PhrasingSearcher extends Searcher { - private static final CompoundName suggestonly = new CompoundName("suggestonly"); + private static final CompoundName suggestonly = CompoundName.from("suggestonly"); public static final String PHRASE_REPLACEMENT = "PhraseReplacement"; diff --git a/container-search/src/main/java/com/yahoo/prelude/querytransform/RecallSearcher.java b/container-search/src/main/java/com/yahoo/prelude/querytransform/RecallSearcher.java index 2c7d78c0671..9f8facd2b28 100644 --- a/container-search/src/main/java/com/yahoo/prelude/querytransform/RecallSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/querytransform/RecallSearcher.java @@ -39,7 +39,7 @@ import static com.yahoo.prelude.querytransform.StemmingSearcher.STEMMING; @Before({STEMMING, ACCENT_REMOVAL}) public class RecallSearcher extends Searcher { - public static final CompoundName recallName=new CompoundName("recall"); + public static final CompoundName recallName = CompoundName.from("recall"); @Override public Result search(Query query, Execution execution) { diff --git a/container-search/src/main/java/com/yahoo/prelude/querytransform/StemmingSearcher.java b/container-search/src/main/java/com/yahoo/prelude/querytransform/StemmingSearcher.java index 6aa262ca49e..7c4bcb38c41 100644 --- a/container-search/src/main/java/com/yahoo/prelude/querytransform/StemmingSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/querytransform/StemmingSearcher.java @@ -9,11 +9,33 @@ import com.yahoo.language.Language; import com.yahoo.language.Linguistics; import com.yahoo.language.process.StemMode; import com.yahoo.language.process.StemList; + +import java.util.ArrayList; +import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.Set; import java.util.logging.Level; import com.yahoo.prelude.Index; import com.yahoo.prelude.IndexFacts; -import com.yahoo.prelude.query.*; +import com.yahoo.prelude.query.AndItem; +import com.yahoo.prelude.query.AndSegmentItem; +import com.yahoo.prelude.query.BlockItem; +import com.yahoo.prelude.query.CompositeItem; +import com.yahoo.prelude.query.Highlight; +import com.yahoo.prelude.query.Item; +import com.yahoo.prelude.query.PhraseItem; +import com.yahoo.prelude.query.PhraseSegmentItem; +import com.yahoo.prelude.query.PrefixItem; +import com.yahoo.prelude.query.SegmentingRule; +import com.yahoo.prelude.query.Substring; +import com.yahoo.prelude.query.TaggableItem; +import com.yahoo.prelude.query.TermItem; +import com.yahoo.prelude.query.WordAlternativesItem; import com.yahoo.prelude.query.WordAlternativesItem.Alternative; +import com.yahoo.prelude.query.WordItem; import com.yahoo.processing.request.CompoundName; import com.yahoo.search.Query; import com.yahoo.search.Result; @@ -21,7 +43,6 @@ import com.yahoo.search.Searcher; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.searchchain.PhaseNames; -import java.util.*; import static com.yahoo.prelude.querytransform.CJKSearcher.TERM_ORDER_RELAXATION; @@ -46,7 +67,7 @@ public class StemmingSearcher extends Searcher { } public static final String STEMMING = "Stemming"; - public static final CompoundName DISABLE = new CompoundName("nostemming"); + public static final CompoundName DISABLE = CompoundName.from("nostemming"); private final Linguistics linguistics; public StemmingSearcher(Linguistics linguistics) { @@ -107,15 +128,13 @@ public class StemmingSearcher extends Searcher { } private Map<Item, TaggableItem> populateReverseConnectivityMap(Item root, Map<Item, TaggableItem> reverseConnectivity) { - if (root instanceof TaggableItem) { - TaggableItem asTaggable = (TaggableItem) root; + if (root instanceof TaggableItem asTaggable) { Item connectsTo = asTaggable.getConnectedItem(); if (connectsTo != null) { reverseConnectivity.put(connectsTo, asTaggable); } } - if (root instanceof CompositeItem && !(root instanceof BlockItem)) { - CompositeItem c = (CompositeItem) root; + if (root instanceof CompositeItem c && !(root instanceof BlockItem)) { for (Iterator<Item> i = c.getItemIterator(); i.hasNext();) { Item item = i.next(); populateReverseConnectivityMap(item, reverseConnectivity); @@ -134,8 +153,7 @@ public class StemmingSearcher extends Searcher { } if (item instanceof BlockItem) { item = checkBlock((BlockItem) item, context); - } else if (item instanceof CompositeItem) { - CompositeItem comp = (CompositeItem) item; + } else if (item instanceof CompositeItem comp) { ListIterator<Item> i = comp.getItemIterator(); while (i.hasNext()) { @@ -220,8 +238,7 @@ public class StemmingSearcher extends Searcher { copyAttributes(blockAsItem, composite); composite.lock(); - if (composite instanceof PhraseSegmentItem) { - PhraseSegmentItem replacement = (PhraseSegmentItem) composite; + if (composite instanceof PhraseSegmentItem replacement) { setSignificance(replacement, current); phraseSegmentConnectivity(current, context.reverseConnectivity, replacement); } @@ -258,10 +275,9 @@ public class StemmingSearcher extends Searcher { } private Connectivity getConnectivity(BlockItem current) { - if (!(current instanceof TaggableItem)) { + if (!(current instanceof TaggableItem t)) { return null; } - TaggableItem t = (TaggableItem) current; if (t.getConnectedItem() == null) { return null; } @@ -294,7 +310,7 @@ public class StemmingSearcher extends Searcher { Substring substring, boolean insidePhrase) { String indexName = current.getIndexName(); - if (insidePhrase == false && ((index.getLiteralBoost() || index.getStemMode() == StemMode.ALL))) { + if (!insidePhrase && ((index.getLiteralBoost() || index.getStemMode() == StemMode.ALL))) { List<Alternative> terms = new ArrayList<>(segment.size() + 1); terms.add(new Alternative(current.stringValue(), 1.0d)); for (String term : segment) { @@ -305,8 +321,7 @@ public class StemmingSearcher extends Searcher { return alternatives; } } - WordItem first = singleStemSegment((Item) current, segment.get(0), indexName, substring); - return first; + return singleStemSegment((Item) current, segment.get(0), indexName, substring); } private void setMetaData(BlockItem current, Map<Item, TaggableItem> reverseConnectivity, TaggableItem replacement) { @@ -353,14 +368,13 @@ public class StemmingSearcher extends Searcher { if (current.getSegmentingRule() == SegmentingRule.LANGUAGE_DEFAULT) return chooseComposite(current, parent, indexName); - switch (current.getSegmentingRule()) { // TODO: Why for CJK only? The segmentingRule says nothing about being for CJK only - case PHRASE: return createPhraseSegment(current, indexName); - case BOOLEAN_AND: return createAndSegment(current); - default: - throw new IllegalArgumentException("Unknown segmenting rule: " + current.getSegmentingRule() + - ". This is a bug in Vespa, as the implementation has gotten out of sync." + - " Please create an issue."); - } + return switch (current.getSegmentingRule()) { // TODO: Why for CJK only? The segmentingRule says nothing about being for CJK only + case PHRASE -> createPhraseSegment(current, indexName); + case BOOLEAN_AND -> createAndSegment(current); + default -> throw new IllegalArgumentException("Unknown segmenting rule: " + current.getSegmentingRule() + + ". This is a bug in Vespa, as the implementation has gotten out of sync." + + " Please create an issue."); + }; } private AndSegmentItem createAndSegment(BlockItem current) { diff --git a/container-search/src/main/java/com/yahoo/prelude/searcher/FieldCollapsingSearcher.java b/container-search/src/main/java/com/yahoo/prelude/searcher/FieldCollapsingSearcher.java index ead6ad53715..9927880c476 100644 --- a/container-search/src/main/java/com/yahoo/prelude/searcher/FieldCollapsingSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/searcher/FieldCollapsingSearcher.java @@ -25,10 +25,10 @@ import java.util.Map; @Before(PhaseNames.TRANSFORMED_QUERY) public class FieldCollapsingSearcher extends Searcher { - private static final CompoundName collapse = new CompoundName("collapse"); - private static final CompoundName collapsefield = new CompoundName("collapsefield"); - private static final CompoundName collapsesize = new CompoundName("collapsesize"); - private static final CompoundName collapseSummaryName = new CompoundName("collapse.summary"); + private static final CompoundName collapse = CompoundName.from("collapse"); + private static final CompoundName collapsefield = CompoundName.from("collapsefield"); + private static final CompoundName collapsesize = CompoundName.from("collapsesize"); + private static final CompoundName collapseSummaryName = CompoundName.from("collapse.summary"); /** Maximum number of queries to send next searcher */ private static final int maxQueries = 4; diff --git a/container-search/src/main/java/com/yahoo/prelude/searcher/JSONDebugSearcher.java b/container-search/src/main/java/com/yahoo/prelude/searcher/JSONDebugSearcher.java index 409b502f086..7750bd17108 100644 --- a/container-search/src/main/java/com/yahoo/prelude/searcher/JSONDebugSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/searcher/JSONDebugSearcher.java @@ -25,7 +25,7 @@ public class JSONDebugSearcher extends Searcher { public static final String STRUCT_FIELD = "Structured data field (as json): "; public static final String FEATURE_FIELD = "Feature data field (as json): "; - private static final CompoundName PROPERTYNAME = new CompoundName("dumpjson"); + private static final CompoundName PROPERTYNAME = CompoundName.from("dumpjson"); @Override public Result search(Query query, Execution execution) { diff --git a/container-search/src/main/java/com/yahoo/prelude/searcher/MultipleResultsSearcher.java b/container-search/src/main/java/com/yahoo/prelude/searcher/MultipleResultsSearcher.java index 3c61a361cbb..dd2c4a1da7f 100644 --- a/container-search/src/main/java/com/yahoo/prelude/searcher/MultipleResultsSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/searcher/MultipleResultsSearcher.java @@ -10,7 +10,12 @@ import com.yahoo.search.result.Hit; import com.yahoo.search.result.HitGroup; import com.yahoo.search.searchchain.Execution; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * Groups hits according to document type. @@ -21,9 +26,9 @@ import java.util.*; public class MultipleResultsSearcher extends Searcher { private final static String propertyPrefix = "multipleresultsets."; - private static final CompoundName additionalHitsFactorName=new CompoundName(propertyPrefix + "additionalHitsFactor"); - private static final CompoundName maxTimesRetrieveHeterogeneousHitsName=new CompoundName(propertyPrefix + "maxTimesRetrieveHeterogeneousHits"); - private static final CompoundName numHits=new CompoundName(propertyPrefix + "numHits"); + private static final CompoundName additionalHitsFactorName = CompoundName.from(propertyPrefix + "additionalHitsFactor"); + private static final CompoundName maxTimesRetrieveHeterogeneousHitsName = CompoundName.from(propertyPrefix + "maxTimesRetrieveHeterogeneousHits"); + private static final CompoundName numHits = CompoundName.from(propertyPrefix + "numHits"); @Override public Result search(Query query, Execution e) { @@ -162,9 +167,9 @@ public class MultipleResultsSearcher extends Searcher { // Assumes that field sddocname is available private static class PartitionedResult { - private Map<String, HitGroup> resultSets = new HashMap<>(); + private final Map<String, HitGroup> resultSets = new HashMap<>(); - private List<Hit> otherHits = new ArrayList<>(); + private final List<Hit> otherHits = new ArrayList<>(); PartitionedResult(List<DocumentGroup> documentGroups,Result result) throws ParameterException { for (DocumentGroup group : documentGroups) @@ -174,9 +179,8 @@ public class MultipleResultsSearcher extends Searcher { } void addHits(Result result, boolean addOtherHits) { - Iterator<Hit> i = result.hits().iterator(); - while (i.hasNext()) { - add(i.next(), addOtherHits); + for (Hit hit : result.hits()) { + add(hit, addOtherHits); } } diff --git a/container-search/src/main/java/com/yahoo/prelude/searcher/PosSearcher.java b/container-search/src/main/java/com/yahoo/prelude/searcher/PosSearcher.java index 0df21df8842..fd4c9e89f3b 100644 --- a/container-search/src/main/java/com/yahoo/prelude/searcher/PosSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/searcher/PosSearcher.java @@ -37,12 +37,11 @@ public class PosSearcher extends Searcher { public static final String POSITION_PARSING = "PositionParsing"; - private static final CompoundName posBb = new CompoundName("pos.bb"); - private static final CompoundName posLl = new CompoundName("pos.ll"); - private static final CompoundName posXy = new CompoundName("pos.xy"); - private static final CompoundName posAttributeName = new CompoundName("pos.attribute"); - private static final CompoundName posRadius = new CompoundName("pos.radius"); - private static final CompoundName posUnits = new CompoundName("pos.units"); + private static final CompoundName posBb = CompoundName.from("pos.bb"); + private static final CompoundName posLl = CompoundName.from("pos.ll"); + private static final CompoundName posXy = CompoundName.from("pos.xy"); + private static final CompoundName posAttributeName = CompoundName.from("pos.attribute"); + private static final CompoundName posRadius = CompoundName.from("pos.radius"); // according to wikipedia: // Earth's equatorial radius = 6378137 meter - not used @@ -117,13 +116,13 @@ public class PosSearcher extends Searcher { if (radius == null) { radiusdegrees = 50.0 * km2deg; } else if (radius.endsWith("km")) { - double radiuskm = Double.valueOf(radius.substring(0, radius.length()-2)); + double radiuskm = Double.parseDouble(radius.substring(0, radius.length()-2)); radiusdegrees = radiuskm * km2deg; } else if (radius.endsWith("m")) { - double radiusm = Double.valueOf(radius.substring(0, radius.length()-1)); + double radiusm = Double.parseDouble(radius.substring(0, radius.length()-1)); radiusdegrees = radiusm * km2deg / 1000.0; } else if (radius.endsWith("mi")) { - double radiusmiles = Double.valueOf(radius.substring(0, radius.length()-2)); + double radiusmiles = Double.parseDouble(radius.substring(0, radius.length()-2)); radiusdegrees = radiusmiles * mi2deg; } else { radiusdegrees = Integer.parseInt(radius) * 0.000001; @@ -151,15 +150,15 @@ public class PosSearcher extends Searcher { double radiusdegrees = radiuskm * km2deg; radiusUnits = (int)(radiusdegrees * 1000000); } else if (radius.endsWith("km")) { - double radiuskm = Double.valueOf(radius.substring(0, radius.length()-2)); + double radiuskm = Double.parseDouble(radius.substring(0, radius.length()-2)); double radiusdegrees = radiuskm * km2deg; radiusUnits = (int)(radiusdegrees * 1000000); } else if (radius.endsWith("m")) { - double radiusm = Double.valueOf(radius.substring(0, radius.length()-1)); + double radiusm = Double.parseDouble(radius.substring(0, radius.length()-1)); double radiusdegrees = radiusm * km2deg / 1000.0; radiusUnits = (int)(radiusdegrees * 1000000); } else if (radius.endsWith("mi")) { - double radiusmiles = Double.valueOf(radius.substring(0, radius.length()-2)); + double radiusmiles = Double.parseDouble(radius.substring(0, radius.length()-2)); double radiusdegrees = radiusmiles * mi2deg; radiusUnits = (int)(radiusdegrees * 1000000); } else { diff --git a/container-search/src/main/java/com/yahoo/prelude/semantics/SemanticSearcher.java b/container-search/src/main/java/com/yahoo/prelude/semantics/SemanticSearcher.java index 42a2b4f4e9b..5b3806485b5 100644 --- a/container-search/src/main/java/com/yahoo/prelude/semantics/SemanticSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/semantics/SemanticSearcher.java @@ -29,9 +29,9 @@ import static com.yahoo.prelude.querytransform.StemmingSearcher.STEMMING; @Before({PhaseNames.TRANSFORMED_QUERY, STEMMING}) public class SemanticSearcher extends Searcher { - private static final CompoundName rulesRulebase = new CompoundName("rules.rulebase"); - private static final CompoundName rulesOff = new CompoundName("rules.off"); - private static final CompoundName tracelevelRules = new CompoundName("tracelevel.rules"); + private static final CompoundName rulesRulebase = CompoundName.from("rules.rulebase"); + private static final CompoundName rulesOff = CompoundName.from("rules.off"); + private static final CompoundName tracelevelRules = CompoundName.from("tracelevel.rules"); /** The default rule base of this */ private RuleBase defaultRuleBase; diff --git a/container-search/src/main/java/com/yahoo/prelude/statistics/StatisticsSearcher.java b/container-search/src/main/java/com/yahoo/prelude/statistics/StatisticsSearcher.java index c13bdff1f50..de24196327e 100644 --- a/container-search/src/main/java/com/yahoo/prelude/statistics/StatisticsSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/statistics/StatisticsSearcher.java @@ -56,7 +56,7 @@ import static com.yahoo.container.protect.Error.UNSPECIFIED; @Before(PhaseNames.RAW_QUERY) public class StatisticsSearcher extends Searcher { - private static final CompoundName IGNORE_QUERY = new CompoundName("metrics.ignore"); + private static final CompoundName IGNORE_QUERY = CompoundName.from("metrics.ignore"); private static final String MAX_QUERY_LATENCY_METRIC = ContainerMetrics.MAX_QUERY_LATENCY.baseName(); private static final String EMPTY_RESULTS_METRIC = ContainerMetrics.EMPTY_RESULTS.baseName(); private static final String HITS_PER_QUERY_METRIC = ContainerMetrics.HITS_PER_QUERY.baseName(); diff --git a/container-search/src/main/java/com/yahoo/search/Query.java b/container-search/src/main/java/com/yahoo/search/Query.java index 39fd372d2a7..a3b1e6b464b 100644 --- a/container-search/src/main/java/com/yahoo/search/Query.java +++ b/container-search/src/main/java/com/yahoo/search/Query.java @@ -180,23 +180,23 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { //---------------- Static property handling ------------------------------------ - public static final CompoundName OFFSET = new CompoundName("offset"); - public static final CompoundName HITS = new CompoundName("hits"); + public static final CompoundName OFFSET = CompoundName.from("offset"); + public static final CompoundName HITS = CompoundName.from("hits"); - public static final CompoundName QUERY_PROFILE = new CompoundName("queryProfile"); - public static final CompoundName SEARCH_CHAIN = new CompoundName("searchChain"); + public static final CompoundName QUERY_PROFILE = CompoundName.from("queryProfile"); + public static final CompoundName SEARCH_CHAIN = CompoundName.from("searchChain"); - public static final CompoundName NO_CACHE = new CompoundName("noCache"); - public static final CompoundName GROUPING_SESSION_CACHE = new CompoundName("groupingSessionCache"); - public static final CompoundName TIMEOUT = new CompoundName("timeout"); + public static final CompoundName NO_CACHE = CompoundName.from("noCache"); + public static final CompoundName GROUPING_SESSION_CACHE = CompoundName.from("groupingSessionCache"); + public static final CompoundName TIMEOUT = CompoundName.from("timeout"); /** @deprecated use Trace.LEVEL */ @Deprecated // TODO: Remove on Vespa 9 - public static final CompoundName TRACE_LEVEL = new CompoundName("traceLevel"); + public static final CompoundName TRACE_LEVEL = CompoundName.from("traceLevel"); /** @deprecated use Trace.EXPLAIN_LEVEL */ @Deprecated // TODO: Remove on Vespa 9 - public static final CompoundName EXPLAIN_LEVEL = new CompoundName("explainLevel"); + public static final CompoundName EXPLAIN_LEVEL = CompoundName.from("explainLevel"); private static final QueryProfileType argumentType; static { diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/CompressService.java b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/CompressService.java index 9e7fc9b5b29..c10375a3014 100644 --- a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/CompressService.java +++ b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/CompressService.java @@ -13,7 +13,7 @@ import com.yahoo.search.Query; */ public class CompressService implements CompressPayload { /** The compression method which will be used with rpc dispatch. "lz4" (default) and "none" is supported. */ - public final static CompoundName dispatchCompression = new CompoundName("dispatch.compression"); + public static final CompoundName dispatchCompression = CompoundName.from("dispatch.compression"); private final Compressor compressor = new Compressor(CompressionType.LZ4, 5, 0.95, 256); diff --git a/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java b/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java index 80a41ffdf22..b8be1dc210b 100644 --- a/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java @@ -70,8 +70,8 @@ public class FederationSearcher extends ForkingSearcher { private static final Logger log = Logger.getLogger(FederationSearcher.class.getName()); /** The name of the query property containing the source name added to the query to each source by this */ - public final static CompoundName SOURCENAME = new CompoundName("sourceName"); - public final static CompoundName PROVIDERNAME = new CompoundName("providerName"); + public static final CompoundName SOURCENAME = CompoundName.from("sourceName"); + public static final CompoundName PROVIDERNAME = CompoundName.from("providerName"); public static final String FEDERATION = "Federation"; public static final String LOG_COUNT_PREFIX = "count_"; @@ -686,33 +686,6 @@ public class FederationSearcher extends ForkingSearcher { } - private static class CompoundKey { - - private final String sourceName; - private final String propertyName; - - CompoundKey(String sourceName, String propertyName) { - this.sourceName = sourceName; - this.propertyName = propertyName; - } - - @Override - public int hashCode() { - return sourceName.hashCode() ^ propertyName.hashCode(); - } - - @Override - public boolean equals(Object o) { - CompoundKey rhs = (CompoundKey) o; - return sourceName.equals(rhs.sourceName) && propertyName.equals(rhs.propertyName); - } - - @Override - public String toString() { - return sourceName + '.' + propertyName; - } - } - private static class Window { private final int hits; diff --git a/container-search/src/main/java/com/yahoo/search/grouping/GroupingQueryParser.java b/container-search/src/main/java/com/yahoo/search/grouping/GroupingQueryParser.java index 54194221958..180687d5274 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/GroupingQueryParser.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/GroupingQueryParser.java @@ -38,13 +38,13 @@ import java.util.TimeZone; public class GroupingQueryParser extends Searcher { public static final String SELECT_PARAMETER_PARSING = "SelectParameterParsing"; - public static final CompoundName PARAM_CONTINUE = new CompoundName("continue"); - public static final CompoundName PARAM_REQUEST = new CompoundName(Select.SELECT); - public static final CompoundName PARAM_TIMEZONE = new CompoundName("timezone"); - @Beta public static final CompoundName PARAM_DEFAULT_MAX_HITS = new CompoundName("grouping.defaultMaxHits"); - @Beta public static final CompoundName PARAM_DEFAULT_MAX_GROUPS = new CompoundName("grouping.defaultMaxGroups"); - @Beta public static final CompoundName PARAM_DEFAULT_PRECISION_FACTOR = new CompoundName("grouping.defaultPrecisionFactor"); - @Beta public static final CompoundName GROUPING_GLOBAL_MAX_GROUPS = new CompoundName("grouping.globalMaxGroups"); + public static final CompoundName PARAM_CONTINUE = CompoundName.from("continue"); + public static final CompoundName PARAM_REQUEST = CompoundName.from(Select.SELECT); + public static final CompoundName PARAM_TIMEZONE = CompoundName.from("timezone"); + @Beta public static final CompoundName PARAM_DEFAULT_MAX_HITS = CompoundName.from("grouping.defaultMaxHits"); + @Beta public static final CompoundName PARAM_DEFAULT_MAX_GROUPS = CompoundName.from("grouping.defaultMaxGroups"); + @Beta public static final CompoundName PARAM_DEFAULT_PRECISION_FACTOR = CompoundName.from("grouping.defaultPrecisionFactor"); + @Beta public static final CompoundName GROUPING_GLOBAL_MAX_GROUPS = CompoundName.from("grouping.globalMaxGroups"); private static final ThreadLocal<ZoneCache> zoneCache = new ThreadLocal<>(); @Override @@ -121,7 +121,6 @@ public class GroupingQueryParser extends Searcher { return val != null ? OptionalDouble.of(val) : OptionalDouble.empty(); } - @SuppressWarnings("serial") private static class ZoneCache extends LinkedHashMap<String, TimeZone> { ZoneCache() { diff --git a/container-search/src/main/java/com/yahoo/search/grouping/GroupingValidator.java b/container-search/src/main/java/com/yahoo/search/grouping/GroupingValidator.java index 35cf72d6124..878fbbb733d 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/GroupingValidator.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/GroupingValidator.java @@ -37,7 +37,7 @@ import static com.yahoo.search.grouping.GroupingQueryParser.SELECT_PARAMETER_PAR public class GroupingValidator extends Searcher { public static final String GROUPING_VALIDATED = "GroupingValidated"; - public static final CompoundName PARAM_ENABLED = new CompoundName("validate_" + GroupingQueryParser.PARAM_REQUEST); + public static final CompoundName PARAM_ENABLED = CompoundName.from("validate_" + GroupingQueryParser.PARAM_REQUEST); private final HashMap<String, AttributesConfig.Attribute> attributes = new HashMap<>(); private final String clusterName; private final boolean enabled; diff --git a/container-search/src/main/java/com/yahoo/search/grouping/UniqueGroupingSearcher.java b/container-search/src/main/java/com/yahoo/search/grouping/UniqueGroupingSearcher.java index a1446367f79..27d8a76511d 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/UniqueGroupingSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/UniqueGroupingSearcher.java @@ -42,7 +42,7 @@ import java.util.logging.Logger; @Before(PhaseNames.TRANSFORMED_QUERY) public class UniqueGroupingSearcher extends Searcher { - public static final CompoundName PARAM_UNIQUE = new CompoundName("unique"); + public static final CompoundName PARAM_UNIQUE = CompoundName.from("unique"); private static final Logger log = Logger.getLogger(UniqueGroupingSearcher.class.getName()); private static final HitOrderer NOP_ORDERER = new HitOrderer() { @@ -144,17 +144,13 @@ public class UniqueGroupingSearcher extends Searcher { for (Sorting.FieldOrder fieldOrder : sortingSpec.fieldOrders()) { Sorting.Order sortOrder = fieldOrder.getSortOrder(); switch (sortOrder) { - case ASCENDING: - case UNDEFINED: - // When we want ascending order, the hit with the smallest value should come first (and be surfaced). - orderingClause.add(new MinAggregator(new AttributeValue(fieldOrder.getFieldName()))); - break; - case DESCENDING: - // When we sort in descending order, the hit with the largest value should come first (and be surfaced). - orderingClause.add(new NegFunction(new MaxAggregator(new AttributeValue(fieldOrder.getFieldName())))); - break; - default: - throw new UnsupportedOperationException("Can not handle sort order " + sortOrder + "."); + case ASCENDING, UNDEFINED -> + // When we want ascending order, the hit with the smallest value should come first (and be surfaced). + orderingClause.add(new MinAggregator(new AttributeValue(fieldOrder.getFieldName()))); + case DESCENDING -> + // When we sort in descending order, the hit with the largest value should come first (and be surfaced). + orderingClause.add(new NegFunction(new MaxAggregator(new AttributeValue(fieldOrder.getFieldName())))); + default -> throw new UnsupportedOperationException("Can not handle sort order " + sortOrder + "."); } } return orderingClause; @@ -170,18 +166,13 @@ public class UniqueGroupingSearcher extends Searcher { GroupingExpression groupingClause = null; for (Sorting.FieldOrder fieldOrder : sortingSpec.fieldOrders()) { Sorting.Order sortOrder = fieldOrder.getSortOrder(); - switch (sortOrder) { - case ASCENDING: - case UNDEFINED: - groupingClause = new AttributeValue(fieldOrder.getFieldName()); - break; - case DESCENDING: - // To sort descending, just take the negative. This is the most common case - groupingClause = new NegFunction(new AttributeValue(fieldOrder.getFieldName())); - break; - default: - throw new UnsupportedOperationException("Can not handle sort order " + sortOrder + "."); - } + groupingClause = switch (sortOrder) { + case ASCENDING, UNDEFINED -> new AttributeValue(fieldOrder.getFieldName()); + case DESCENDING -> + // To sort descending, just take the negative. This is the most common case + new NegFunction(new AttributeValue(fieldOrder.getFieldName())); + default -> throw new UnsupportedOperationException("Can not handle sort order " + sortOrder + "."); + }; } return groupingClause; } diff --git a/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java b/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java index fac6c598e4b..3b4d15f788f 100644 --- a/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java +++ b/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java @@ -75,8 +75,8 @@ public class SearchHandler extends LoggingRequestHandler { // max number of threads for the executor for this handler private final int maxThreads; - private static final CompoundName DETAILED_TIMING_LOGGING = new CompoundName("trace.timingDetails"); - private static final CompoundName FORCE_TIMESTAMPS = new CompoundName("trace.timestamps"); + private static final CompoundName DETAILED_TIMING_LOGGING = CompoundName.from("trace.timingDetails"); + private static final CompoundName FORCE_TIMESTAMPS = CompoundName.from("trace.timestamps"); /** Event name for number of connections to the search subsystem */ private static final String SEARCH_CONNECTIONS = "search_connections"; diff --git a/container-search/src/main/java/com/yahoo/search/intent/model/IntentModel.java b/container-search/src/main/java/com/yahoo/search/intent/model/IntentModel.java index 9aafd2c4693..0c4b22fbbf2 100644 --- a/container-search/src/main/java/com/yahoo/search/intent/model/IntentModel.java +++ b/container-search/src/main/java/com/yahoo/search/intent/model/IntentModel.java @@ -5,7 +5,12 @@ import com.yahoo.search.Query; import com.yahoo.processing.request.CompoundName; import com.yahoo.text.interpretation.Interpretation; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * This is the root node of an intent model. @@ -19,9 +24,9 @@ import java.util.*; public class IntentModel extends ParentNode<InterpretationNode> { /** The name of the property carrying the intent model string: intentModel */ - public static final CompoundName intentModelStringName=new CompoundName("intentModel"); + public static final CompoundName intentModelStringName = CompoundName.from("intentModel"); /** The name of the property carrying the intent model object: IntentModel */ - public static final CompoundName intentModelObjectName=new CompoundName("IntentModel"); + public static final CompoundName intentModelObjectName = CompoundName.from("IntentModel"); private static final InterpretationNodeComparator inodeComp = new InterpretationNodeComparator(); @@ -45,7 +50,7 @@ public class IntentModel extends ParentNode<InterpretationNode> { /** Sort interpretations by descending score order */ public void sortChildren() { - Collections.sort(children(), inodeComp); + children().sort(inodeComp); } /** diff --git a/container-search/src/main/java/com/yahoo/search/pagetemplates/PageTemplateSearcher.java b/container-search/src/main/java/com/yahoo/search/pagetemplates/PageTemplateSearcher.java index c23627accf4..5fef1821de2 100644 --- a/container-search/src/main/java/com/yahoo/search/pagetemplates/PageTemplateSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/pagetemplates/PageTemplateSearcher.java @@ -72,13 +72,13 @@ import java.util.Map; public class PageTemplateSearcher extends Searcher { /** The name of the query property containing the resolved candidate page template list */ - public static final CompoundName pagePageTemplateListName=new CompoundName("page.PageTemplateList"); + public static final CompoundName pagePageTemplateListName = CompoundName.from("page.PageTemplateList"); /** The name of the query property containing a list of candidate pages to consider */ - public static final CompoundName pageIdListName=new CompoundName("page.idList"); + public static final CompoundName pageIdListName = CompoundName.from("page.idList"); /** The name of the query property containing the page id to use */ - public static final CompoundName pageIdName=new CompoundName("page.id"); + public static final CompoundName pageIdName = CompoundName.from("page.id"); /** The name of the query property containing the resolver id to use */ - public static final CompoundName pageResolverName=new CompoundName("page.resolver"); + public static final CompoundName pageResolverName = CompoundName.from("page.resolver"); private final ResolverRegistry resolverRegistry; diff --git a/container-search/src/main/java/com/yahoo/search/query/Model.java b/container-search/src/main/java/com/yahoo/search/query/Model.java index 190ad675015..09b2f394f20 100644 --- a/container-search/src/main/java/com/yahoo/search/query/Model.java +++ b/container-search/src/main/java/com/yahoo/search/query/Model.java @@ -71,13 +71,13 @@ public class Model implements Cloneable { argumentType.addField(new FieldDescription(SEARCH_PATH, "string", "searchpath")); argumentType.addField(new FieldDescription(RESTRICT, "string", "restrict")); argumentType.freeze(); - argumentTypeName = new CompoundName(argumentType.getId().getName()); + argumentTypeName = CompoundName.from(argumentType.getId().getName()); } public static QueryProfileType getArgumentType() { return argumentType; } /** The name of the query property used for generating hit count estimate queries. */ - public static final CompoundName ESTIMATE = new CompoundName("hitcountestimate"); // TODO: Cleanup + public static final CompoundName ESTIMATE = CompoundName.from("hitcountestimate"); // TODO: Cleanup private String encoding = null; private String queryString = ""; diff --git a/container-search/src/main/java/com/yahoo/search/query/Ranking.java b/container-search/src/main/java/com/yahoo/search/query/Ranking.java index e8738a19412..5426268d173 100644 --- a/container-search/src/main/java/com/yahoo/search/query/Ranking.java +++ b/container-search/src/main/java/com/yahoo/search/query/Ranking.java @@ -27,7 +27,7 @@ import java.util.Objects; public class Ranking implements Cloneable { /** An alias for listing features */ - public static final CompoundName RANKFEATURES = new CompoundName("rankfeatures"); + public static final CompoundName RANKFEATURES = CompoundName.from("rankfeatures"); /** The type representing the property arguments consumed by this */ private static final QueryProfileType argumentType; @@ -70,7 +70,7 @@ public class Ranking implements Cloneable { argumentType.addField(new FieldDescription(FEATURES, "query-profile", "rankfeature input")); // Repeated at the end of RankFeatures argumentType.addField(new FieldDescription(PROPERTIES, "query-profile", "rankproperty")); argumentType.freeze(); - argumentTypeName = new CompoundName(argumentType.getId().getName()); + argumentTypeName = CompoundName.from(argumentType.getId().getName()); } public static QueryProfileType getArgumentType() { return argumentType; } diff --git a/container-search/src/main/java/com/yahoo/search/query/properties/DefaultProperties.java b/container-search/src/main/java/com/yahoo/search/query/properties/DefaultProperties.java index 221368afeb6..6ccf4792efb 100644 --- a/container-search/src/main/java/com/yahoo/search/query/properties/DefaultProperties.java +++ b/container-search/src/main/java/com/yahoo/search/query/properties/DefaultProperties.java @@ -16,9 +16,9 @@ import java.util.Map; */ public final class DefaultProperties extends Properties { - public static final CompoundName MAX_OFFSET = new CompoundName("maxOffset"); - public static final CompoundName MAX_HITS = new CompoundName("maxHits"); - public static final CompoundName MAX_QUERY_ITEMS = new CompoundName("maxQueryItems"); + public static final CompoundName MAX_OFFSET = CompoundName.from("maxOffset"); + public static final CompoundName MAX_HITS = CompoundName.from("maxHits"); + public static final CompoundName MAX_QUERY_ITEMS = CompoundName.from("maxQueryItems"); public static final QueryProfileType argumentType = new QueryProfileType("DefaultProperties"); diff --git a/container-search/src/main/java/com/yahoo/search/query/rewrite/RewriterConstants.java b/container-search/src/main/java/com/yahoo/search/query/rewrite/RewriterConstants.java index b0fce45de46..eeb8b675ae1 100644 --- a/container-search/src/main/java/com/yahoo/search/query/rewrite/RewriterConstants.java +++ b/container-search/src/main/java/com/yahoo/search/query/rewrite/RewriterConstants.java @@ -42,7 +42,7 @@ public class RewriterConstants { public static final String REWRITER_CHAIN = "QRWChain"; /** Name for rewrite metadata retrieval from query properties */ - public static final CompoundName REWRITE_META = new CompoundName("RewriteMeta"); + public static final CompoundName REWRITE_META = CompoundName.from("RewriteMeta"); /** Name for rewritten field retrieval from query properties */ public static final String REWRITTEN = "Rewritten"; diff --git a/container-search/src/main/java/com/yahoo/search/querytransform/BooleanSearcher.java b/container-search/src/main/java/com/yahoo/search/querytransform/BooleanSearcher.java index f43be20e0ac..91315fe1bb3 100644 --- a/container-search/src/main/java/com/yahoo/search/querytransform/BooleanSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/querytransform/BooleanSearcher.java @@ -28,9 +28,9 @@ import static com.yahoo.yolean.Exceptions.toMessageString; @Provides(BooleanSearcher.PREDICATE) public class BooleanSearcher extends Searcher { - private static final CompoundName FIELD = new CompoundName("boolean.field"); - private static final CompoundName ATTRIBUTES = new CompoundName("boolean.attributes"); - private static final CompoundName RANGE_ATTRIBUTES = new CompoundName("boolean.rangeAttributes"); + private static final CompoundName FIELD = CompoundName.from("boolean.field"); + private static final CompoundName ATTRIBUTES = CompoundName.from("boolean.attributes"); + private static final CompoundName RANGE_ATTRIBUTES = CompoundName.from("boolean.rangeAttributes"); public static final String PREDICATE = "predicate"; @Override diff --git a/container-search/src/main/java/com/yahoo/search/querytransform/SortingDegrader.java b/container-search/src/main/java/com/yahoo/search/querytransform/SortingDegrader.java index 75b06c29193..81881685a1d 100644 --- a/container-search/src/main/java/com/yahoo/search/querytransform/SortingDegrader.java +++ b/container-search/src/main/java/com/yahoo/search/querytransform/SortingDegrader.java @@ -41,9 +41,9 @@ public class SortingDegrader extends Searcher { /** Set this to false in query.properties to turn off degrading. Default: on */ // (this is not called ranking.sorting.degrading because it should not be part of the query object model - public static final CompoundName DEGRADING = new CompoundName("sorting.degrading"); + public static final CompoundName DEGRADING = CompoundName.from("sorting.degrading"); - public static final CompoundName PAGINATION = new CompoundName("to_be_removed_pagination"); + public static final CompoundName PAGINATION = CompoundName.from("to_be_removed_pagination"); @Override public Result search(Query query, Execution execution) { diff --git a/container-search/src/main/java/com/yahoo/search/querytransform/WandSearcher.java b/container-search/src/main/java/com/yahoo/search/querytransform/WandSearcher.java index 89245eaf137..bfac668b6c4 100644 --- a/container-search/src/main/java/com/yahoo/search/querytransform/WandSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/querytransform/WandSearcher.java @@ -63,12 +63,12 @@ public class WandSearcher extends Searcher { */ private static class InputResolver { - private static final CompoundName WAND_FIELD = new CompoundName("wand.field"); - private static final CompoundName WAND_TOKENS = new CompoundName("wand.tokens"); - private static final CompoundName WAND_HEAP_SIZE = new CompoundName("wand.heapSize"); - private static final CompoundName WAND_TYPE = new CompoundName("wand.type"); - private static final CompoundName WAND_SCORE_THRESHOLD = new CompoundName("wand.scoreThreshold"); - private static final CompoundName WAND_THRESHOLD_BOOST_FACTOR = new CompoundName("wand.thresholdBoostFactor"); + private static final CompoundName WAND_FIELD = CompoundName.from("wand.field"); + private static final CompoundName WAND_TOKENS = CompoundName.from("wand.tokens"); + private static final CompoundName WAND_HEAP_SIZE = CompoundName.from("wand.heapSize"); + private static final CompoundName WAND_TYPE = CompoundName.from("wand.type"); + private static final CompoundName WAND_SCORE_THRESHOLD = CompoundName.from("wand.scoreThreshold"); + private static final CompoundName WAND_THRESHOLD_BOOST_FACTOR = CompoundName.from("wand.thresholdBoostFactor"); private final String fieldName; private final WandType wandType; private final Map<Object, Integer> tokens; diff --git a/container-search/src/main/java/com/yahoo/search/querytransform/WeakAndReplacementSearcher.java b/container-search/src/main/java/com/yahoo/search/querytransform/WeakAndReplacementSearcher.java index 2d6e059342e..9aa7a9d998d 100644 --- a/container-search/src/main/java/com/yahoo/search/querytransform/WeakAndReplacementSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/querytransform/WeakAndReplacementSearcher.java @@ -21,8 +21,8 @@ import com.yahoo.yolean.chain.After; */ @After(MinimalQueryInserter.EXTERNAL_YQL) public class WeakAndReplacementSearcher extends Searcher { - static final CompoundName WEAKAND_REPLACE = new CompoundName("weakAnd.replace"); - static final CompoundName WAND_HITS = new CompoundName("wand.hits"); + static final CompoundName WEAKAND_REPLACE = CompoundName.from("weakAnd.replace"); + static final CompoundName WAND_HITS = CompoundName.from("wand.hits"); @Override public Result search(Query query, Execution execution) { if (!query.properties().getBoolean(WEAKAND_REPLACE)) { diff --git a/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java b/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java index 44620179c1d..b36c8788877 100644 --- a/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java +++ b/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java @@ -76,10 +76,10 @@ import static com.fasterxml.jackson.databind.SerializationFeature.FLUSH_AFTER_WR // NOTE: The JSON format is a public API. If new elements are added be sure to update the reference doc. public class JsonRenderer extends AsynchronousSectionedRenderer<Result> { - private static final CompoundName WRAP_DEEP_MAPS = new CompoundName("renderer.json.jsonMaps"); - private static final CompoundName WRAP_WSETS = new CompoundName("renderer.json.jsonWsets"); - private static final CompoundName DEBUG_RENDERING_KEY = new CompoundName("renderer.json.debug"); - private static final CompoundName JSON_CALLBACK = new CompoundName("jsoncallback"); + private static final CompoundName WRAP_DEEP_MAPS = CompoundName.from("renderer.json.jsonMaps"); + private static final CompoundName WRAP_WSETS = CompoundName.from("renderer.json.jsonWsets"); + private static final CompoundName DEBUG_RENDERING_KEY = CompoundName.from("renderer.json.debug"); + private static final CompoundName JSON_CALLBACK = CompoundName.from("jsoncallback"); // if this must be optimized, simply use com.fasterxml.jackson.core.SerializableString private static final String BUCKET_LIMITS = "limits"; diff --git a/container-search/src/main/java/com/yahoo/search/searchers/CacheControlSearcher.java b/container-search/src/main/java/com/yahoo/search/searchers/CacheControlSearcher.java index a4f03b088f2..29e8afa41ac 100644 --- a/container-search/src/main/java/com/yahoo/search/searchers/CacheControlSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/searchers/CacheControlSearcher.java @@ -32,9 +32,9 @@ import com.yahoo.search.searchchain.Execution; */ public class CacheControlSearcher extends Searcher { - private static final CompoundName cachecontrolNocache=new CompoundName("cachecontrol.nocache"); - private static final CompoundName cachecontrolMaxage=new CompoundName("cachecontrol.maxage"); - private static final CompoundName cachecontrolStaleage=new CompoundName("cachecontrol.staleage"); + private static final CompoundName cachecontrolNocache=CompoundName.from("cachecontrol.nocache"); + private static final CompoundName cachecontrolMaxage=CompoundName.from("cachecontrol.maxage"); + private static final CompoundName cachecontrolStaleage=CompoundName.from("cachecontrol.staleage"); public static final String CACHE_CONTROL_HEADER = "Cache-Control"; diff --git a/container-search/src/main/java/com/yahoo/search/searchers/ConnectionControlSearcher.java b/container-search/src/main/java/com/yahoo/search/searchers/ConnectionControlSearcher.java index 90cb05be1f8..18588b2026d 100644 --- a/container-search/src/main/java/com/yahoo/search/searchers/ConnectionControlSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/searchers/ConnectionControlSearcher.java @@ -49,7 +49,7 @@ public class ConnectionControlSearcher extends Searcher { private final LongSupplier clock; - private static final CompoundName KEEPALIVE_MAXLIFETIMESECONDS = new CompoundName("connectioncontrol.maxlifetime"); + private static final CompoundName KEEPALIVE_MAXLIFETIMESECONDS = CompoundName.from("connectioncontrol.maxlifetime"); private static final String HTTP_CONNECTION_HEADER_NAME = "Connection"; private static final String HTTP_CONNECTION_CLOSE_ARGUMENT = "Close"; diff --git a/container-search/src/main/java/com/yahoo/search/searchers/RateLimitingSearcher.java b/container-search/src/main/java/com/yahoo/search/searchers/RateLimitingSearcher.java index cf81f62f64d..35a3c86f763 100755 --- a/container-search/src/main/java/com/yahoo/search/searchers/RateLimitingSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/searchers/RateLimitingSearcher.java @@ -54,11 +54,11 @@ public class RateLimitingSearcher extends Searcher { /** Constant containing the name this Provides - "rateLimiting", for ordering constraints */ public static final String RATE_LIMITING = "rateLimiting"; - public static final CompoundName idKey = new CompoundName("rate.id"); - public static final CompoundName costKey = new CompoundName("rate.cost"); - public static final CompoundName quotaKey = new CompoundName("rate.quota"); - public static final CompoundName idDimensionKey = new CompoundName("rate.idDimension"); - public static final CompoundName dryRunKey = new CompoundName("rate.dryRun"); + public static final CompoundName idKey = CompoundName.from("rate.id"); + public static final CompoundName costKey = CompoundName.from("rate.cost"); + public static final CompoundName quotaKey = CompoundName.from("rate.quota"); + public static final CompoundName idDimensionKey = CompoundName.from("rate.idDimension"); + public static final CompoundName dryRunKey = CompoundName.from("rate.dryRun"); private static final String requestsOverQuotaMetricName = "requestsOverQuota"; diff --git a/container-search/src/main/java/com/yahoo/search/yql/FieldFiller.java b/container-search/src/main/java/com/yahoo/search/yql/FieldFiller.java index 833c1251a7b..6961a189d22 100644 --- a/container-search/src/main/java/com/yahoo/search/yql/FieldFiller.java +++ b/container-search/src/main/java/com/yahoo/search/yql/FieldFiller.java @@ -27,7 +27,7 @@ public class FieldFiller extends Searcher { private final Set<String> intersectionOfAttributes; private final SchemaInfo schemaInfo; - public static final CompoundName FIELD_FILLER_DISABLE = new CompoundName("FieldFiller.disable"); + public static final CompoundName FIELD_FILLER_DISABLE = CompoundName.from("FieldFiller.disable"); public FieldFiller(SchemaInfo schemaInfo) { this.schemaInfo = schemaInfo; diff --git a/container-search/src/main/java/com/yahoo/search/yql/FieldFilter.java b/container-search/src/main/java/com/yahoo/search/yql/FieldFilter.java index 8cc6a1b42b9..df9722d3214 100644 --- a/container-search/src/main/java/com/yahoo/search/yql/FieldFilter.java +++ b/container-search/src/main/java/com/yahoo/search/yql/FieldFilter.java @@ -2,13 +2,11 @@ package com.yahoo.search.yql; import java.util.Iterator; -import java.util.Map.Entry; import java.util.Set; import com.yahoo.api.annotations.Beta; import com.yahoo.component.chain.dependencies.After; import com.yahoo.component.chain.dependencies.Before; -import com.yahoo.prelude.fastsearch.FastHit; import com.yahoo.processing.request.CompoundName; import com.yahoo.search.Query; import com.yahoo.search.Result; @@ -27,7 +25,7 @@ import com.yahoo.search.searchchain.Execution; @Before("com.yahoo.search.yql.FieldFiller") public class FieldFilter extends Searcher { - public static final CompoundName FIELD_FILTER_DISABLE = new CompoundName("FieldFilter.disable"); + public static final CompoundName FIELD_FILTER_DISABLE = CompoundName.from("FieldFilter.disable"); /** Fields that should be kept even if not explicitly requested */ private static final Set<String> syntheticFields = Set.of("matchfeatures", "rankfeatures", "summaryfeatures"); diff --git a/container-search/src/main/java/com/yahoo/search/yql/MinimalQueryInserter.java b/container-search/src/main/java/com/yahoo/search/yql/MinimalQueryInserter.java index e844bac21e8..ee4f931d532 100644 --- a/container-search/src/main/java/com/yahoo/search/yql/MinimalQueryInserter.java +++ b/container-search/src/main/java/com/yahoo/search/yql/MinimalQueryInserter.java @@ -39,10 +39,10 @@ public class MinimalQueryInserter extends Searcher { public static final String EXTERNAL_YQL = "ExternalYql"; - public static final CompoundName YQL = new CompoundName("yql"); + public static final CompoundName YQL = CompoundName.from("yql"); - private static final CompoundName MAX_HITS = new CompoundName("maxHits"); - private static final CompoundName MAX_OFFSET = new CompoundName("maxOffset"); + private static final CompoundName MAX_HITS = CompoundName.from("maxHits"); + private static final CompoundName MAX_OFFSET = CompoundName.from("maxOffset"); private static final Logger log = Logger.getLogger(MinimalQueryInserter.class.getName()); @Inject diff --git a/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/MetricsSearcher.java b/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/MetricsSearcher.java index ab9da8ccee5..536355ab62d 100644 --- a/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/MetricsSearcher.java +++ b/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/MetricsSearcher.java @@ -22,8 +22,8 @@ import static com.yahoo.vespa.streamingvisitors.VdsStreamingSearcher.STREAMING_S */ public class MetricsSearcher extends Searcher { - private static final CompoundName metricsearcherId=new CompoundName("metricsearcher.id"); - private static final CompoundName streamingLoadtype=new CompoundName("streaming.loadtype"); + private static final CompoundName metricsearcherId = CompoundName.from("metricsearcher.id"); + private static final CompoundName streamingLoadtype = CompoundName.from("streaming.loadtype"); private static final Logger log = Logger.getLogger(MetricsSearcher.class.getName()); @@ -43,7 +43,8 @@ public class MetricsSearcher extends Searcher { public Result search(Query query, Execution execution) { long timeMs = System.currentTimeMillis(); - /** Backwards compatibility - convert metricsearcher.id to streaming.loadtype */ + // Backwards compatibility - convert metricsearcher.id to streaming.loadtype + // TODO Cleanup at some point String metricName = query.properties().getString(metricsearcherId); if (metricName != null) { query.properties().set(streamingLoadtype, metricName); diff --git a/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/VdsStreamingSearcher.java b/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/VdsStreamingSearcher.java index ca199f37dd7..524001748c5 100644 --- a/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/VdsStreamingSearcher.java +++ b/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/VdsStreamingSearcher.java @@ -45,9 +45,9 @@ import java.util.logging.Logger; */ public class VdsStreamingSearcher extends VespaBackEndSearcher { - private static final CompoundName streamingUserid = new CompoundName("streaming.userid"); - private static final CompoundName streamingGroupname = new CompoundName("streaming.groupname"); - private static final CompoundName streamingSelection = new CompoundName("streaming.selection"); + private static final CompoundName streamingUserid = CompoundName.from("streaming.userid"); + private static final CompoundName streamingGroupname = CompoundName.from("streaming.groupname"); + private static final CompoundName streamingSelection = CompoundName.from("streaming.selection"); static final String STREAMING_STATISTICS = "streaming.statistics"; private final VisitorFactory visitorFactory; diff --git a/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/VdsVisitor.java b/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/VdsVisitor.java index 85ef10b29f6..70dff6730ff 100644 --- a/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/VdsVisitor.java +++ b/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/VdsVisitor.java @@ -51,13 +51,13 @@ import java.util.logging.Level; */ class VdsVisitor extends VisitorDataHandler implements Visitor { - private static final CompoundName streamingUserid=new CompoundName("streaming.userid"); - private static final CompoundName streamingGroupname=new CompoundName("streaming.groupname"); - private static final CompoundName streamingSelection=new CompoundName("streaming.selection"); - private static final CompoundName streamingFromtimestamp=new CompoundName("streaming.fromtimestamp"); - private static final CompoundName streamingTotimestamp=new CompoundName("streaming.totimestamp"); - private static final CompoundName streamingPriority=new CompoundName("streaming.priority"); - private static final CompoundName streamingMaxbucketspervisitor=new CompoundName("streaming.maxbucketspervisitor"); + private static final CompoundName streamingUserid = CompoundName.from("streaming.userid"); + private static final CompoundName streamingGroupname = CompoundName.from("streaming.groupname"); + private static final CompoundName streamingSelection = CompoundName.from("streaming.selection"); + private static final CompoundName streamingFromtimestamp = CompoundName.from("streaming.fromtimestamp"); + private static final CompoundName streamingTotimestamp = CompoundName.from("streaming.totimestamp"); + private static final CompoundName streamingPriority = CompoundName.from("streaming.priority"); + private static final CompoundName streamingMaxbucketspervisitor = CompoundName.from("streaming.maxbucketspervisitor"); protected static final int MAX_BUCKETS_PER_VISITOR = 1024; diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java index dcb41dc5e31..326c7985a5f 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java @@ -3,10 +3,8 @@ package com.yahoo.search.query.profile.config.test; import com.yahoo.jdisc.http.HttpRequest.Method; import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.language.Language; import com.yahoo.language.process.Embedder; import com.yahoo.processing.request.CompoundName; -import com.yahoo.search.query.profile.types.test.QueryProfileTypeTestCase; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorType; import com.yahoo.yolean.Exceptions; @@ -25,7 +23,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * @author bratseth @@ -77,8 +79,8 @@ public class XmlReadingTestCase { CompiledQueryProfile defaultProfile = cRegistry.getComponent("default"); assertNull(defaultProfile.getType()); assertEquals("20", defaultProfile.get("hits")); - assertFalse(defaultProfile.isOverridable(new CompoundName("hits"), null)); - assertFalse(defaultProfile.isOverridable(new CompoundName("user.trusted"), null)); + assertFalse(defaultProfile.isOverridable(CompoundName.from("hits"), null)); + assertFalse(defaultProfile.isOverridable(CompoundName.from("user.trusted"), null)); assertEquals("false", defaultProfile.get("user.trusted")); CompiledQueryProfile referencingProfile = cRegistry.getComponent("referencingModelSettings"); @@ -97,7 +99,7 @@ public class XmlReadingTestCase { assertEquals("rootType", rootProfile.getType().getId().getName()); assertEquals(30, rootProfile.get("hits")); //assertEquals(3, rootProfile.get("traceLevel")); - assertTrue(rootProfile.isOverridable(new CompoundName("hits"), null)); + assertTrue(rootProfile.isOverridable(CompoundName.from("hits"), null)); query = new Query(request, rootProfile); assertEquals(3, query.getTrace().getLevel()); @@ -231,8 +233,8 @@ public class XmlReadingTestCase { assertEquals("a.b.c-value", new Query("?d1=d1v", profile).properties().get("a.b.c")); assertEquals("a.b.c-variant-value", new Query("?d1=d1v&d2=d2v", profile).properties().get("a.b.c")); - assertTrue(profile.isOverridable(new CompoundName("a.b.c"), Map.of("d1", "d1v"))); - assertFalse(profile.isOverridable(new CompoundName("a.b.c"), Map.of("d1", "d1v", "d2", "d2v"))); + assertTrue(profile.isOverridable(CompoundName.from("a.b.c"), Map.of("d1", "d1v"))); + assertFalse(profile.isOverridable(CompoundName.from("a.b.c"), Map.of("d1", "d1v", "d2", "d2v"))); } @Test @@ -479,18 +481,18 @@ public class XmlReadingTestCase { QueryProfileType type1 = registry.getTypeRegistry().getComponent("type1"); assertEquals(TensorType.fromSpec("tensor<float>(x[1])"), - type1.getFieldType(new CompoundName("ranking.features.query(tensor_1)")).asTensorType()); - assertNull(type1.getFieldType(new CompoundName("ranking.features.query(tensor_2)"))); - assertNull(type1.getFieldType(new CompoundName("ranking.features.query(tensor_3)"))); + type1.getFieldType(CompoundName.from("ranking.features.query(tensor_1)")).asTensorType()); + assertNull(type1.getFieldType(CompoundName.from("ranking.features.query(tensor_2)"))); + assertNull(type1.getFieldType(CompoundName.from("ranking.features.query(tensor_3)"))); assertEquals(TensorType.fromSpec("tensor(key{})"), - type1.getFieldType(new CompoundName("ranking.features.query(tensor_4)")).asTensorType()); + type1.getFieldType(CompoundName.from("ranking.features.query(tensor_4)")).asTensorType()); QueryProfileType type2 = registry.getTypeRegistry().getComponent("type2"); - assertNull(type2.getFieldType(new CompoundName("ranking.features.query(tensor_1)"))); + assertNull(type2.getFieldType(CompoundName.from("ranking.features.query(tensor_1)"))); assertEquals(TensorType.fromSpec("tensor<float>(x[2])"), - type2.getFieldType(new CompoundName("ranking.features.query(tensor_2)")).asTensorType()); + type2.getFieldType(CompoundName.from("ranking.features.query(tensor_2)")).asTensorType()); assertEquals(TensorType.fromSpec("tensor<float>(x[3])"), - type2.getFieldType(new CompoundName("ranking.features.query(tensor_3)")).asTensorType()); + type2.getFieldType(CompoundName.from("ranking.features.query(tensor_3)")).asTensorType()); Query queryProfile1 = new Query.Builder().setQueryProfile(registry.getComponent("profile1")) .setRequest("?query=test&ranking.features.query(tensor_1)=[1.200]") diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileGetInComplexStructureMicroBenchmark.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileGetInComplexStructureMicroBenchmark.java index cd5a8e08aa9..080aef25c5f 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileGetInComplexStructureMicroBenchmark.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileGetInComplexStructureMicroBenchmark.java @@ -65,8 +65,8 @@ public class QueryProfileGetInComplexStructureMicroBenchmark { Map<String,String> dimensionValues=createDimensionValueMap(); String prefix=generatePrefix(); final int dotInterval=1000000; - final CompoundName found = new CompoundName(prefix + "a"); - final CompoundName notFound = new CompoundName(prefix + "nonexisting"); + final CompoundName found = CompoundName.from(prefix + "a"); + final CompoundName notFound = CompoundName.from(prefix + "nonexisting"); for (int i=0; i<count; i++) { if (count>dotInterval && i%(dotInterval)==0) System.out.print("."); diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileGetMicroBenchmark.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileGetMicroBenchmark.java index d38a1d64910..1123feb1b01 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileGetMicroBenchmark.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileGetMicroBenchmark.java @@ -57,8 +57,8 @@ public class QueryProfileGetMicroBenchmark { private void getValues(int count,Query query) { final int dotInterval=10000000; - CompoundName found = new CompoundName(propertyPrefix + "property1"); - CompoundName notFound = new CompoundName(propertyPrefix + "nonExisting"); + CompoundName found = CompoundName.from(propertyPrefix + "property1"); + CompoundName notFound = CompoundName.from(propertyPrefix + "nonExisting"); for (int i=0; i<count; i++) { if (count>dotInterval && i%(count/dotInterval)==0) System.out.print("."); diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileTestCase.java index cd4cb32df2e..7d5a2137770 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileTestCase.java @@ -534,7 +534,7 @@ public class QueryProfileTestCase { p.set("a.b", "a.b-value", null); { - Map<String, ValueWithSource> values = p.compile(null).listValuesWithSources(new CompoundName(""), new HashMap<>(), null); + Map<String, ValueWithSource> values = p.compile(null).listValuesWithSources(CompoundName.empty, new HashMap<>(), null); assertEquals(2, values.size()); assertEquals("a-value", values.get("a").value()); assertEquals("test", values.get("a").source()); @@ -543,7 +543,7 @@ public class QueryProfileTestCase { } { - Map<String, ValueWithSource> values = p.compile(null).listValuesWithSources(new CompoundName("a"), new HashMap<>(), null); + Map<String, ValueWithSource> values = p.compile(null).listValuesWithSources(CompoundName.from("a"), new HashMap<>(), null); assertEquals(1, values.size()); assertEquals("a.b-value", values.get("b").value()); assertEquals("test", values.get("b").source()); diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java index 1a6cfee75a5..36ff33ffd97 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java @@ -5,7 +5,6 @@ import ai.vespa.cloud.ApplicationId; import ai.vespa.cloud.Environment; import ai.vespa.cloud.Zone; import ai.vespa.cloud.ZoneInfo; -import com.yahoo.jdisc.application.Application; import com.yahoo.jdisc.http.HttpRequest.Method; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.processing.request.CompoundName; @@ -28,7 +27,9 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author bratseth @@ -133,7 +134,7 @@ public class QueryProfileVariantsTestCase { base.set("a.b", 1, new String[]{null, null, "d3-val"}, registry); QueryProfileVariant aVariants = base.getVariants().getVariants().get(0); assertEquals("[d1, d2, d3]", - ((QueryProfile) base.getVariants().getVariants().get(0).values().get("a")).getDimensions().toString(), + ((QueryProfile) aVariants.values().get("a")).getDimensions().toString(), "Variant dimensions are not overridden by the referenced dimensions"); } @@ -184,7 +185,7 @@ public class QueryProfileVariantsTestCase { { Map<String, ValueWithSource> values = cRegistry.findQueryProfile("test") - .listValuesWithSources(new CompoundName(""), + .listValuesWithSources(CompoundName.empty, new HashMap<>(), null); assertEquals(1, values.size()); @@ -195,7 +196,7 @@ public class QueryProfileVariantsTestCase { { Map<String, ValueWithSource> values = cRegistry.findQueryProfile("test") - .listValuesWithSources(new CompoundName(""), + .listValuesWithSources(CompoundName.empty, toMap("x=x1", "y=y1", "z=z1"), null); assertEquals(2, values.size()); @@ -1456,7 +1457,7 @@ public class QueryProfileVariantsTestCase { return context; } - public static final Map<String, String> toMap(String... bindings) { + public static Map<String, String> toMap(String... bindings) { Map<String, String> context = new HashMap<>(); for (String binding : bindings) { String[] entry = binding.split("="); diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java index 37991f7f14f..982ebd80fbd 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java @@ -55,7 +55,7 @@ public class NameTestCase { @Test void testComponentIdAsCompoundName() { String name = "a/b"; - assertEquals(new CompoundName(name), new QueryProfileType(name).getComponentIdAsCompoundName()); + assertEquals(CompoundName.from(name), new QueryProfileType(name).getComponentIdAsCompoundName()); } private void assertLegalName(String name) { @@ -89,10 +89,6 @@ public class NameTestCase { } } - private void assertIllegalFieldName(String name) { - assertIllegalFieldName(name,"Could not set '" + name + "' to 'anyValue'","Illegal name '" + name + "'"); - } - /** Checks that this is illegal both for profiles and types */ private void assertIllegalFieldName(String name, String expectedHighError, String expectedLowError) { try { diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java index 21a9b2fe399..4000c48bfed 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java @@ -761,7 +761,7 @@ public class QueryProfileTypeTestCase { } private void assertNotPermitted(QueryProfile profile,String name,Object value) { - String localName = new CompoundName(name).last(); + String localName = CompoundName.from(name).last(); try { profile.set(name, value, registry); fail("Should fail setting " + name + " to " + value); 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 748a20801d1..63655da0784 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 @@ -2,7 +2,6 @@ package com.yahoo.search.test; import com.yahoo.component.chain.Chain; -import com.yahoo.data.JsonProducer; import com.yahoo.language.Language; import com.yahoo.language.Linguistics; import com.yahoo.language.detect.Detection; @@ -16,7 +15,6 @@ import com.yahoo.prelude.Index; import com.yahoo.prelude.IndexFacts; import com.yahoo.prelude.IndexModel; import com.yahoo.prelude.SearchDefinition; -import com.yahoo.prelude.fastsearch.FastHit; import com.yahoo.prelude.query.AndItem; import com.yahoo.prelude.query.AndSegmentItem; import com.yahoo.prelude.query.CompositeItem; @@ -145,7 +143,7 @@ public class QueryTestCase { @Test void testCloneWithConnectivity() { List<String> l = List.of("a", "b", "c", "a"); - printIt(l.stream().filter(i -> isA(i)).toList()); + printIt(l.stream().filter(this::isA).toList()); printIt(l.stream().filter(i -> !isA(i)).toList()); Query q = new Query(); @@ -314,7 +312,7 @@ public class QueryTestCase { profile.set("myField", "Profile: %{queryProfile}", null); Query query = new Query(QueryTestCase.httpEncode("/search?queryProfile=myProfile"), profile.compile(null)); - String source = query.properties().getInstance(com.yahoo.search.query.profile.QueryProfileProperties.class).getQueryProfile().listValuesWithSources(new CompoundName(""), query.getHttpRequest().propertyMap(), query.properties()).get("myField").source(); + String source = query.properties().getInstance(com.yahoo.search.query.profile.QueryProfileProperties.class).getQueryProfile().listValuesWithSources(CompoundName.empty, query.getHttpRequest().propertyMap(), query.properties()).get("myField").source(); assertEquals("myProfile", source); } |