summaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-11-10 20:59:00 +0100
committerJon Bratseth <bratseth@gmail.com>2022-11-10 20:59:00 +0100
commit15b3db0dfa32b87df0e24a968335ccf5d690ed16 (patch)
treea7b3fc8458a6cb3e621fa084f4b3f6f94b834a09 /container-search
parentb26cbb29aec75b76767e6e1631eae2a11f035823 (diff)
Don't interpret ref: as a query profile ref unnecessarily
Diffstat (limited to 'container-search')
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/query/parser/AbstractParser.java4
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java8
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParseTestCase.java3
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParsingTester.java6
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileTestCase.java20
5 files changed, 30 insertions, 11 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/parser/AbstractParser.java b/container-search/src/main/java/com/yahoo/prelude/query/parser/AbstractParser.java
index 5da1f1a07be..5c19319fd0c 100644
--- a/container-search/src/main/java/com/yahoo/prelude/query/parser/AbstractParser.java
+++ b/container-search/src/main/java/com/yahoo/prelude/query/parser/AbstractParser.java
@@ -244,9 +244,7 @@ public abstract class AbstractParser implements CustomParser {
private static void assignDefaultIndex(String defaultIndex, Item item) {
if (defaultIndex == null || item == null) return;
- if (item instanceof IndexedItem) {
- IndexedItem indexName = (IndexedItem) item;
-
+ if (item instanceof IndexedItem indexName) {
if ("".equals(indexName.getIndexName()))
indexName.setIndexName(defaultIndex);
}
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java
index f5d797b4b9f..f73ed52246c 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java
@@ -139,14 +139,15 @@ public class QueryProfileProperties extends Properties {
if ( ! profile.getTypes().isEmpty())
value = convertByType(name, value, context);
+ // TODO: On Vespa 9, only support this when the profile is typed and this field has a query profile type
if (value instanceof String && value.toString().startsWith("ref:")) {
if (profile.getRegistry() == null)
throw new IllegalInputException("Runtime query profile references does not work when the " +
"QueryProfileProperties are constructed without a registry");
String queryProfileId = value.toString().substring(4);
- value = profile.getRegistry().findQueryProfile(queryProfileId);
- if (value == null)
- throw new IllegalInputException("Query profile '" + queryProfileId + "' is not found");
+ var referencedProfile = profile.getRegistry().findQueryProfile(queryProfileId);
+ if (referencedProfile != null)
+ value = referencedProfile;
}
if (set) {
@@ -168,6 +169,7 @@ public class QueryProfileProperties extends Properties {
}
private String toShortString(Object value) {
+ if (value == null) return "null";
if ( ! (value instanceof Tensor)) return value.toString();
return ((Tensor)value).toAbbreviatedString();
}
diff --git a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParseTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParseTestCase.java
index bd6b2f1f21d..583e89bacd6 100644
--- a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParseTestCase.java
+++ b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParseTestCase.java
@@ -12,6 +12,7 @@ import com.yahoo.prelude.query.CompositeItem;
import com.yahoo.prelude.query.IntItem;
import com.yahoo.prelude.query.Item;
import com.yahoo.prelude.query.NotItem;
+import com.yahoo.prelude.query.NullItem;
import com.yahoo.prelude.query.OrItem;
import com.yahoo.prelude.query.PhraseItem;
import com.yahoo.prelude.query.PhraseSegmentItem;
@@ -1475,7 +1476,7 @@ public class ParseTestCase {
@Test
void testLoneStar() {
- assertNull(tester.parseQuery("*", null, Language.UNKNOWN, Query.Type.ANY, TestLinguistics.INSTANCE));
+ assertTrue(tester.parseQuery("*", null, Language.UNKNOWN, Query.Type.ANY, TestLinguistics.INSTANCE) instanceof NullItem);
}
@Test
diff --git a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParsingTester.java b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParsingTester.java
index ab314c4c1e7..e37c5c03807 100644
--- a/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParsingTester.java
+++ b/container-search/src/test/java/com/yahoo/prelude/query/parser/test/ParsingTester.java
@@ -117,7 +117,7 @@ public class ParsingTester {
Language language, Linguistics linguistics) {
Item root = parseQuery(toParse, filter, language, mode, linguistics);
if (parsed == null) {
- assertNull(root);
+ assertTrue(root instanceof NullItem, "root is " + root);
} else {
assertNotNull(root, "Got null from parsing " + toParse);
assertEquals(parsed, root.toString(), "Parse of '" + toParse + "'");
@@ -135,9 +135,7 @@ public class ParsingTester {
.setLinguistics(linguistics)
.setSpecialTokens(tokenRegistry.getSpecialTokens("default")));
Item root = parser.parse(new Parsable().setQuery(query).setFilter(filter).setLanguage(language)).getRoot();
- if (root instanceof NullItem) {
- return null;
- }
+ if (root == null) throw new NullPointerException(); // Should be NullItem
return root;
}
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 7a4247f2584..c4541fe9f58 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
@@ -3,6 +3,10 @@ package com.yahoo.search.query.profile.test;
import com.yahoo.jdisc.http.HttpRequest.Method;
import com.yahoo.container.jdisc.HttpRequest;
+import com.yahoo.prelude.Index;
+import com.yahoo.prelude.IndexFacts;
+import com.yahoo.prelude.IndexModel;
+import com.yahoo.prelude.SearchDefinition;
import com.yahoo.processing.request.CompoundName;
import com.yahoo.processing.request.Properties;
import com.yahoo.search.Query;
@@ -12,6 +16,7 @@ import com.yahoo.search.query.profile.QueryProfileProperties;
import com.yahoo.search.query.profile.QueryProfileRegistry;
import com.yahoo.search.query.profile.compiled.CompiledQueryProfile;
import com.yahoo.search.query.profile.compiled.ValueWithSource;
+import com.yahoo.search.searchchain.Execution;
import com.yahoo.yolean.trace.TraceNode;
import org.junit.jupiter.api.Test;
@@ -342,6 +347,21 @@ public class QueryProfileTestCase {
assertEquals("de", query.getModel().getLanguage().languageCode());
}
+ /** Tests that the ref: here is not mistaken for a query profile reference. */
+ @Test
+ void testReferenceAsQueryString() {
+ SearchDefinition sd = new SearchDefinition("test");
+ sd.addIndex(new Index("someField"));
+ IndexFacts facts = new IndexFacts(new IndexModel(sd));
+
+ var profile = new QueryProfile("test");
+ var registry = new QueryProfileRegistry();
+ registry.register(profile);
+ var query = new Query("?query=ref:", registry.compile().findQueryProfile("test"));
+ query.getModel().setExecution(new Execution(Execution.Context.createContextStub(facts)));
+ assertEquals("WEAKAND(100) ref", query.getModel().getQueryTree().getRoot().toString());
+ }
+
/** Dots are followed when setting overridability, also with variants */
@Test
void testInstanceOverridableWithVariants() {