summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorbjormel <bjormel@verizonmedia.com>2022-07-26 18:21:27 +0200
committerbjormel <bjormel@verizonmedia.com>2022-07-26 18:21:27 +0200
commita12a6098dad556b135509c9d30f945fb6b348c11 (patch)
tree6e329fe35598b6ec548933d98c0ae8487a9c43dc /application
parentab02611dc0236355ff4fe3dd0cce641750d44094 (diff)
Attempt to use query profiles from application
Diffstat (limited to 'application')
-rw-r--r--application/src/main/java/com/yahoo/application/Application.java9
-rw-r--r--application/src/test/app-packages/withqueryprofile/schemas/mydoc.sd17
-rw-r--r--application/src/test/app-packages/withqueryprofile/search/query-profiles/default.xml3
-rw-r--r--application/src/test/app-packages/withqueryprofile/services.xml29
-rw-r--r--application/src/test/java/com/yahoo/application/ApplicationTest.java20
5 files changed, 73 insertions, 5 deletions
diff --git a/application/src/main/java/com/yahoo/application/Application.java b/application/src/main/java/com/yahoo/application/Application.java
index 1b81897b230..899e9d8675c 100644
--- a/application/src/main/java/com/yahoo/application/Application.java
+++ b/application/src/main/java/com/yahoo/application/Application.java
@@ -26,6 +26,8 @@ import com.yahoo.jdisc.handler.RequestHandler;
import com.yahoo.jdisc.service.ClientProvider;
import com.yahoo.jdisc.service.ServerProvider;
import com.yahoo.search.Searcher;
+import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry;
+import com.yahoo.search.query.profile.config.QueryProfileXMLReader;
import com.yahoo.search.rendering.Renderer;
import com.yahoo.text.StringUtilities;
import com.yahoo.text.Utf8;
@@ -71,6 +73,7 @@ public final class Application implements AutoCloseable {
private final List<ContentCluster> contentClusters;
private final Path path;
private final boolean deletePathWhenClosing;
+ private final CompiledQueryProfileRegistry compiledQueryProfileRegistry;
// For internal use only
Application(Path path, Networking networking, boolean deletePathWhenClosing) {
@@ -79,6 +82,8 @@ public final class Application implements AutoCloseable {
this.deletePathWhenClosing = deletePathWhenClosing;
contentClusters = ContentCluster.fromPath(path);
container = JDisc.fromPath(path, networking, createVespaModel().configModelRepo());
+ QueryProfileXMLReader queryProfileXMLReader = new QueryProfileXMLReader();
+ compiledQueryProfileRegistry = queryProfileXMLReader.read(path + "/search/query-profiles").compile();
}
@Beta
@@ -149,6 +154,10 @@ public final class Application implements AutoCloseable {
return container;
}
+ public CompiledQueryProfileRegistry getCompiledQueryProfileRegistry() {
+ return compiledQueryProfileRegistry;
+ }
+
/**
* Shuts down all services.
*/
diff --git a/application/src/test/app-packages/withqueryprofile/schemas/mydoc.sd b/application/src/test/app-packages/withqueryprofile/schemas/mydoc.sd
new file mode 100644
index 00000000000..ca6fa37a8e6
--- /dev/null
+++ b/application/src/test/app-packages/withqueryprofile/schemas/mydoc.sd
@@ -0,0 +1,17 @@
+# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+search mydoc {
+
+ document mydoc {
+
+ field title type string {
+ indexing: index
+ }
+
+ field substring type string {
+ indexing: index
+ match: gram
+ }
+
+ }
+
+}
diff --git a/application/src/test/app-packages/withqueryprofile/search/query-profiles/default.xml b/application/src/test/app-packages/withqueryprofile/search/query-profiles/default.xml
new file mode 100644
index 00000000000..c9ed6ab3d12
--- /dev/null
+++ b/application/src/test/app-packages/withqueryprofile/search/query-profiles/default.xml
@@ -0,0 +1,3 @@
+<query-profile id="default">
+ <field name="hits">2</field>
+</query-profile>
diff --git a/application/src/test/app-packages/withqueryprofile/services.xml b/application/src/test/app-packages/withqueryprofile/services.xml
new file mode 100644
index 00000000000..028ca561160
--- /dev/null
+++ b/application/src/test/app-packages/withqueryprofile/services.xml
@@ -0,0 +1,29 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
+<services>
+
+ <container version="1.0">
+ <!-- Avoid using DefaultLinguisticsProvider -->
+ <component id="com.yahoo.language.simple.SimpleLinguistics" />
+
+ <search>
+ <chain id="default" inherits="vespa"/>
+ <provider id="bar" type="local" cluster="foo">
+ <searcher id="MockResultSearcher" class="com.yahoo.application.MockResultSearcher"/>
+ </provider>
+ </search>
+
+ <accesslog type="disabled" />
+ </container>
+
+ <content version="1.0" id="foo">
+ <redundancy>2</redundancy>
+ <documents>
+ <document type="mydoc" mode="index"/>
+ </documents>
+ <nodes>
+ <node hostalias="node1" distribution-key="1"/>
+ </nodes>
+ </content>
+
+</services>
diff --git a/application/src/test/java/com/yahoo/application/ApplicationTest.java b/application/src/test/java/com/yahoo/application/ApplicationTest.java
index 6ae49cc4802..7b7ad4ad002 100644
--- a/application/src/test/java/com/yahoo/application/ApplicationTest.java
+++ b/application/src/test/java/com/yahoo/application/ApplicationTest.java
@@ -1,9 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.application;
-import com.yahoo.application.container.MockClient;
import com.yahoo.application.container.MockServer;
-import com.yahoo.application.container.docprocs.MockDispatchDocproc;
import com.yahoo.application.container.docprocs.MockDocproc;
import com.yahoo.application.container.handler.Request;
import com.yahoo.application.container.handler.Response;
@@ -12,10 +10,8 @@ import com.yahoo.application.container.renderers.MockRenderer;
import com.yahoo.application.container.searchers.MockSearcher;
import com.yahoo.component.Component;
import com.yahoo.component.ComponentSpecification;
-import com.yahoo.docproc.DocumentProcessor;
+import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.docproc.Processing;
-import com.yahoo.document.Document;
-import com.yahoo.document.DocumentPut;
import com.yahoo.document.DocumentRemove;
import com.yahoo.document.DocumentType;
import com.yahoo.jdisc.handler.RequestHandler;
@@ -67,6 +63,20 @@ public class ApplicationTest {
}
}
+ /** Tests that an application with query profile sets up the QueryProfileRegistry */
+ @Test
+ public void container_and_query_profile() {
+ try (Application application =
+ Application.fromApplicationPackage(new File("src/test/app-packages/withqueryprofile"), Networking.disable)) {
+ Query query = new Query(HttpRequest.createTestRequest("?query=substring:foobar&timeout=20000", com.yahoo.jdisc.http.HttpRequest.Method.GET), application.getCompiledQueryProfileRegistry().findQueryProfile("default"));
+ Result result = application.getJDisc("default").search().process(new ComponentSpecification("default"), query);
+
+ assertEquals("WEAKAND(100) (AND substring:fo substring:oo substring:ob substring:ba substring:ar)",
+ result.hits().get("hasQuery").getQuery().getModel().getQueryTree().toString());
+ assertEquals("2", application.getCompiledQueryProfileRegistry().findQueryProfile("default").get("hits"));
+ assertEquals("select * from sources * where weakAnd(substring contains \"foobar\") limit 2 timeout 20000000", result.getQuery().yqlRepresentation(true));
+ }
+ }
private void printTrace(Result result) {
for (String message : result.getQuery().getContext(true).getTrace().traceNode().descendants(String.class))
System.out.println(message);