summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/query/Model.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/query/Model.java')
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/Model.java33
1 files changed, 28 insertions, 5 deletions
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 f01951047d0..4e05b44b087 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
@@ -1,6 +1,8 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query;
+import ai.vespa.searchlib.searchprotocol.protobuf.Search;
+import com.google.protobuf.ByteString;
import com.yahoo.language.Language;
import com.yahoo.language.Linguistics;
import com.yahoo.language.LocaleFactory;
@@ -17,6 +19,7 @@ import com.yahoo.search.query.profile.types.FieldDescription;
import com.yahoo.search.query.profile.types.QueryProfileType;
import com.yahoo.search.searchchain.Execution;
+import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -34,6 +37,7 @@ import static com.yahoo.text.Lowercase.toLowerCase;
* @author bratseth
*/
public class Model implements Cloneable {
+ private static final int INITIAL_SERIALIZATION_BUFFER_SIZE = 10 * 1024;
/** The type representing the property arguments consumed by this */
private static final QueryProfileType argumentType;
@@ -101,9 +105,9 @@ public class Model implements Cloneable {
/**
* Gets the language to use for parsing. If this is explicitly set in the model, that language is returned.
- * Otherwise, if a query tree is already produced and any node in it specifies a language the first such
- * node encountered in a depth first
- * left to right search is returned. Otherwise the language is guessed from the query string.
+ * Otherwise, if a query tree is already produced and any node in it specifies a language the first such
+ * node encountered in a depth first
+ * left to right search is returned. Otherwise the language is guessed from the query string.
* If this does not yield an actual language, English is returned as the default.
*
* @return the language determined, never null
@@ -121,7 +125,7 @@ public class Model implements Cloneable {
if (queryTree != null)
language = languageBelow(queryTree);
if (language != Language.UNKNOWN) return language;
-
+
Linguistics linguistics = execution.context().getLinguistics();
if (linguistics != null)
language = linguistics.getDetector().detect(languageDetectionText, null).getLanguage(); // TODO: Set language if detected
@@ -129,7 +133,7 @@ public class Model implements Cloneable {
return Language.ENGLISH;
}
-
+
private Language languageBelow(Item item) {
if (item.getLanguage() != Language.UNKNOWN) return item.getLanguage();
if (item instanceof CompositeItem) {
@@ -509,4 +513,23 @@ public class Model implements Cloneable {
return false;
}
+ public void addToProtobuf(Search.Request.Builder builder, boolean encodeQueryData) {
+ if (documentDbName != null) {
+ builder.setDocumentType(documentDbName);
+ }
+ int bufferSize = INITIAL_SERIALIZATION_BUFFER_SIZE;
+ boolean success = false;
+ while(!success) {
+ try {
+ ByteBuffer treeBuffer = ByteBuffer.allocate(bufferSize);
+ getQueryTree().encode(treeBuffer);
+ treeBuffer.flip();
+ builder.setQueryTreeBlob(ByteString.copyFrom(treeBuffer));
+ success = true;
+ } catch(java.nio.BufferOverflowException e) {
+ bufferSize *= 2;
+ }
+ }
+ }
+
}