From 458e61bac0d6a5e2f964c38c9fdce6983c46a123 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Thu, 15 Aug 2024 10:13:06 +0200 Subject: [PATCH] Add Chinese query test --- .../yahoo/config/provision/SystemName.java | 31 +++++++++---------- .../search/query/context/QueryContext.java | 2 +- .../com/yahoo/search/test/QueryTestCase.java | 13 ++++++++ .../java/com/yahoo/vespa/flags/Flags.java | 2 +- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/SystemName.java b/config-provisioning/src/main/java/com/yahoo/config/provision/SystemName.java index f73fec3ec68e..c1567d1f8339 100644 --- a/config-provisioning/src/main/java/com/yahoo/config/provision/SystemName.java +++ b/config-provisioning/src/main/java/com/yahoo/config/provision/SystemName.java @@ -42,25 +42,24 @@ public static SystemName defaultSystem() { } public static SystemName from(String value) { - switch (value.toLowerCase()) { - case "dev": return dev; - case "cd": return cd; - case "main": return main; - case "public": return Public; - case "publiccd": return PublicCd; - default: throw new IllegalArgumentException(String.format("'%s' is not a valid system", value)); - } + return switch (value.toLowerCase()) { + case "dev" -> dev; + case "cd" -> cd; + case "main" -> main; + case "public" -> Public; + case "publiccd" -> PublicCd; + default -> throw new IllegalArgumentException(String.format("'%s' is not a valid system", value)); + }; } public String value() { - switch (this) { - case dev: return "dev"; - case cd: return "cd"; - case main: return "main"; - case Public: return "public"; - case PublicCd: return "publiccd"; - default : throw new IllegalStateException(); - } + return switch (this) { + case dev -> "dev"; + case cd -> "cd"; + case main -> "main"; + case Public -> "public"; + case PublicCd -> "publiccd"; + }; } /** Whether the system is similar to Public, e.g. PublicCd. */ diff --git a/container-search/src/main/java/com/yahoo/search/query/context/QueryContext.java b/container-search/src/main/java/com/yahoo/search/query/context/QueryContext.java index 97a7634aa17e..449607b0a07f 100644 --- a/container-search/src/main/java/com/yahoo/search/query/context/QueryContext.java +++ b/container-search/src/main/java/com/yahoo/search/query/context/QueryContext.java @@ -63,7 +63,7 @@ public Iterator logValueIterator() { * @param name the name of the property * @param value the value of the property, or null to set this property to null */ - public void setProperty(String name,Object value) { + public void setProperty(String name, Object value) { owner.getModel().getExecution().trace().setProperty(name,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 ddadf0fa042f..74b9a59257ba 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 @@ -1,12 +1,14 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.test; +import ai.vespa.opennlp.OpenNlpConfig; import com.yahoo.component.chain.Chain; import com.yahoo.language.Language; import com.yahoo.language.Linguistics; import com.yahoo.language.detect.Detection; import com.yahoo.language.detect.Detector; import com.yahoo.language.detect.Hint; +import com.yahoo.language.opennlp.OpenNlpLinguistics; import com.yahoo.language.process.StemMode; import com.yahoo.language.process.Token; import com.yahoo.language.simple.SimpleDetector; @@ -1257,6 +1259,17 @@ void testSettingNativeQueryProfileValueInQueryProfile() { } } + @Test + public void testChinese() { + var query = new Query(httpEncode("?query=中村靖日驟逝"), null); + var execution = new Execution(Execution.Context.createContextStub(null, new IndexFacts(), + new OpenNlpLinguistics(new OpenNlpConfig.Builder().cjk(true) + .createCjkGrams(true) + .snowballStemmingForEnglish(true).build()))); + query.getModel().setExecution(execution); + assertEquals("WEAKAND(100) 中村靖 日驟 逝", query.getModel().getQueryTree().toString()); + } + private void assertDetectionText(String expectedDetectionText, String queryString, String ... indexSpecs) { Query q = new Query(httpEncode("/?query=" + queryString)); SearchDefinition sd = new SearchDefinition("testSearchDefinition"); diff --git a/flags/src/main/java/com/yahoo/vespa/flags/Flags.java b/flags/src/main/java/com/yahoo/vespa/flags/Flags.java index 72d96b238f6d..1a02dbe3ccfa 100644 --- a/flags/src/main/java/com/yahoo/vespa/flags/Flags.java +++ b/flags/src/main/java/com/yahoo/vespa/flags/Flags.java @@ -510,7 +510,7 @@ public class Flags { public static final UnboundBooleanFlag USE_LEGACY_WAND_QUERY_PARSING = defineFeatureFlag( "use-legacy-wand-query-parsing", true, List.of("arnej"), "2023-07-26", "2025-12-31", - "If true, force leagy mode for weakAnd query parsing", + "If true, force legacy mode for weakAnd query parsing", "Takes effect at redeployment", INSTANCE_ID);