aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/schema/derived
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2024-01-10 10:17:50 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2024-01-10 10:17:50 +0100
commit3f7017773ce147a2d65a9835acdfd682dfafd54a (patch)
treef3f67620ecb19db0ef7a6ce0150abcfe407d9199 /config-model/src/main/java/com/yahoo/schema/derived
parent02c5bce07737a899726097e577c6dd1121ca5a7c (diff)
Generate correct vsmfields config for cased search.
Diffstat (limited to 'config-model/src/main/java/com/yahoo/schema/derived')
-rw-r--r--config-model/src/main/java/com/yahoo/schema/derived/IndexInfo.java55
-rw-r--r--config-model/src/main/java/com/yahoo/schema/derived/VsmFields.java10
2 files changed, 26 insertions, 39 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/derived/IndexInfo.java b/config-model/src/main/java/com/yahoo/schema/derived/IndexInfo.java
index 7532dec5187..0ee675cb36d 100644
--- a/config-model/src/main/java/com/yahoo/schema/derived/IndexInfo.java
+++ b/config-model/src/main/java/com/yahoo/schema/derived/IndexInfo.java
@@ -310,7 +310,7 @@ public class IndexInfo extends Derived implements IndexInfoConfig.Producer {
private boolean notInCommands(String index) {
for (IndexCommand command : commands) {
- if (command.getIndex().equals(index)) {
+ if (command.index().equals(index)) {
return false;
}
}
@@ -324,8 +324,8 @@ public class IndexInfo extends Derived implements IndexInfoConfig.Producer {
for (IndexCommand command : commands) {
iiB.command(
new IndexInfoConfig.Indexinfo.Command.Builder()
- .indexname(command.getIndex())
- .command(command.getCommand()));
+ .indexname(command.index())
+ .command(command.command()));
}
// Make user defined field sets searchable
for (FieldSet fieldSet : fieldSets.values()) {
@@ -525,54 +525,33 @@ public class IndexInfo extends Derived implements IndexInfoConfig.Producer {
}
/**
- * An index command. Null commands are also represented, to detect consistency issues. This is an (immutable) value
- * object.
- */
- public static class IndexCommand {
-
- private final String index;
-
- private final String command;
-
- public IndexCommand(String index, String command) {
- this.index = index;
- this.command = command;
- }
-
- public String getIndex() {
- return index;
- }
-
- public String getCommand() {
- return command;
- }
+ * An index command. Null commands are also represented, to detect consistency issues. This is an (immutable) value
+ * object.
+ */
+ public record IndexCommand(String index, String command) {
/**
* Returns true if this is the null command (do nothing)
*/
public boolean isNull() {
- return command.equals("");
- }
-
- public int hashCode() {
- return index.hashCode() + 17 * command.hashCode();
+ return command.isEmpty();
}
public boolean equals(Object object) {
- if (!(object instanceof IndexCommand other)) {
- return false;
+ if (!(object instanceof IndexCommand other)) {
+ return false;
+ }
+
+ return other.index.equals(this.index) &&
+ other.command.equals(this.command);
}
- return other.index.equals(this.index) &&
- other.command.equals(this.command);
- }
+ public String toString() {
+ return "index command " + command + " on index " + index;
+ }
- public String toString() {
- return "index command " + command + " on index " + index;
}
- }
-
/**
* A command which may override the command setting of a field for a particular index
*/
diff --git a/config-model/src/main/java/com/yahoo/schema/derived/VsmFields.java b/config-model/src/main/java/com/yahoo/schema/derived/VsmFields.java
index cb806d8596e..564161b725d 100644
--- a/config-model/src/main/java/com/yahoo/schema/derived/VsmFields.java
+++ b/config-model/src/main/java/com/yahoo/schema/derived/VsmFields.java
@@ -14,6 +14,7 @@ import com.yahoo.document.datatypes.TensorFieldValue;
import com.yahoo.schema.FieldSets;
import com.yahoo.schema.Schema;
import com.yahoo.schema.document.Attribute;
+import com.yahoo.schema.document.Case;
import com.yahoo.schema.document.FieldSet;
import com.yahoo.schema.document.GeoPos;
import com.yahoo.schema.document.Matching;
@@ -144,7 +145,7 @@ public class VsmFields extends Derived implements VsmfieldsConfig.Producer {
public static Type GEO_POSITION = new Type("GEOPOS");
public static Type NEAREST_NEIGHBOR = new Type("NEAREST_NEIGHBOR");
- private String searchMethod;
+ private final String searchMethod;
private Type(String searchMethod) {
this.searchMethod = searchMethod;
@@ -261,10 +262,17 @@ public class VsmFields extends Derived implements VsmfieldsConfig.Producer {
return getMatchingName();
}
+ private static VsmfieldsConfig.Fieldspec.Normalize.Enum toNormalize(Matching matching) {
+ if (matching.getType() == MatchType.EXACT) return VsmfieldsConfig.Fieldspec.Normalize.Enum.LOWERCASE;
+ if (matching.getCase() == Case.CASED) return VsmfieldsConfig.Fieldspec.Normalize.Enum.NONE;
+ return VsmfieldsConfig.Fieldspec.Normalize.LOWERCASE_AND_FOLD;
+ }
+
public VsmfieldsConfig.Fieldspec.Builder getFieldSpecConfig() {
var fB = new VsmfieldsConfig.Fieldspec.Builder();
fB.name(getName())
.searchmethod(VsmfieldsConfig.Fieldspec.Searchmethod.Enum.valueOf(type.getSearchMethod()))
+ .normalize(toNormalize(matching))
.arg1(getArg1())
.fieldtype(isAttribute
? VsmfieldsConfig.Fieldspec.Fieldtype.ATTRIBUTE