summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Meland <bjormel@users.noreply.github.com>2022-07-27 12:14:06 +0200
committerGitHub <noreply@github.com>2022-07-27 12:14:06 +0200
commit1031189457abd27d5dfbdf9590e7b32372f7e2ca (patch)
tree16bec2a4af9938ae3d5721ffa75197c3e9121ef1
parentab02611dc0236355ff4fe3dd0cce641750d44094 (diff)
parent1ff6fcce424328bb99b8eeb89c1df8c5cc4ca60a (diff)
Merge pull request #23541 from vespa-engine/bjormel/add-queryProfileRegistry-to-Application
Add query profile registry to application
-rw-r--r--application/abi-spec.json1
-rw-r--r--application/src/main/java/com/yahoo/application/Application.java19
-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
6 files changed, 84 insertions, 5 deletions
diff --git a/application/abi-spec.json b/application/abi-spec.json
index 2053eabd9ad..75ae9842982 100644
--- a/application/abi-spec.json
+++ b/application/abi-spec.json
@@ -57,6 +57,7 @@
"public static com.yahoo.application.Application fromApplicationPackage(java.nio.file.Path, com.yahoo.application.Networking)",
"public static com.yahoo.application.Application fromApplicationPackage(java.io.File, com.yahoo.application.Networking)",
"public com.yahoo.application.container.JDisc getJDisc(java.lang.String)",
+ "public com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry getCompiledQueryProfileRegistry()",
"public void close()"
],
"fields": [
diff --git a/application/src/main/java/com/yahoo/application/Application.java b/application/src/main/java/com/yahoo/application/Application.java
index 1b81897b230..5d8123de48f 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,7 @@ public final class Application implements AutoCloseable {
this.deletePathWhenClosing = deletePathWhenClosing;
contentClusters = ContentCluster.fromPath(path);
container = JDisc.fromPath(path, networking, createVespaModel().configModelRepo());
+ compiledQueryProfileRegistry = readQueryProfilesFromApplicationPackage(path);
}
@Beta
@@ -123,6 +127,17 @@ public final class Application implements AutoCloseable {
return fromApplicationPackage(file.toPath(), networking);
}
+ private CompiledQueryProfileRegistry readQueryProfilesFromApplicationPackage(Path path) {
+ String queryProfilePath = path + "/search/query-profiles";
+ QueryProfileXMLReader queryProfileXMLReader = new QueryProfileXMLReader();
+
+ File f = new File(queryProfilePath);
+ if(f.exists() && f.isDirectory()) {
+ return queryProfileXMLReader.read(queryProfilePath).compile();
+ }
+ return CompiledQueryProfileRegistry.empty;
+ }
+
private VespaModel createVespaModel() {
try {
List<MlModelImporter> modelImporters = List.of(new VespaImporter(),
@@ -149,6 +164,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);