diff options
Diffstat (limited to 'config-model/src/main/java/com/yahoo/schema')
3 files changed, 42 insertions, 103 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..34f485b7f02 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 @@ -25,6 +25,7 @@ import com.yahoo.vespa.documentmodel.SummaryField; import com.yahoo.search.config.IndexInfoConfig; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -238,12 +239,8 @@ public class IndexInfo extends Derived implements IndexInfoConfig.Producer { if (DataType.URI.equals(fieldType)) { return true; } - if (fieldType instanceof CollectionDataType && - DataType.URI.equals(((CollectionDataType)fieldType).getNestedType())) - { - return true; - } - return false; + return (fieldType instanceof CollectionDataType collectionFieldType) && + DataType.URI.equals(collectionFieldType.getNestedType()); } private void addUriIndexCommands(ImmutableSDField field) { @@ -310,7 +307,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; } } @@ -322,10 +319,7 @@ public class IndexInfo extends Derived implements IndexInfoConfig.Producer { IndexInfoConfig.Indexinfo.Builder iiB = new IndexInfoConfig.Indexinfo.Builder(); iiB.name(getName()); for (IndexCommand command : commands) { - iiB.command( - new IndexInfoConfig.Indexinfo.Command.Builder() - .indexname(command.getIndex()) - .command(command.getCommand())); + addIndexCommand(iiB, command.index(), command.command()); } // Make user defined field sets searchable for (FieldSet fieldSet : fieldSets.values()) { @@ -335,18 +329,16 @@ public class IndexInfo extends Derived implements IndexInfoConfig.Producer { } for (Map.Entry<String, String> e : aliases.entrySet()) { - iiB.alias( - new IndexInfoConfig.Indexinfo.Alias.Builder() - .alias(e.getKey()) - .indexname(e.getValue())); + iiB.alias(new IndexInfoConfig.Indexinfo.Alias.Builder().alias(e.getKey()).indexname(e.getValue())); } builder.indexinfo(iiB); } // TODO: Move this to the FieldSetSettings processor (and rename it) as that already has to look at this. private void addFieldSetCommands(IndexInfoConfig.Indexinfo.Builder iiB, FieldSet fieldSet) { - for (String qc : fieldSet.queryCommands()) - iiB.command(new IndexInfoConfig.Indexinfo.Command.Builder().indexname(fieldSet.getName()).command(qc)); + for (String qc : fieldSet.queryCommands()) { + addIndexCommand(iiB, fieldSet.getName(), qc); + } boolean anyIndexing = false; boolean anyAttributing = false; boolean anyLowerCasing = false; @@ -397,57 +389,29 @@ public class IndexInfo extends Derived implements IndexInfoConfig.Producer { fieldSetMatching = new Matching(); } if (anyLowerCasing) { - iiB.command( - new IndexInfoConfig.Indexinfo.Command.Builder() - .indexname(fieldSet.getName()) - .command(CMD_LOWERCASE)); + addIndexCommand(iiB, fieldSet.getName(), CMD_LOWERCASE); } if (hasMultiValueField(fieldSet)) { - iiB.command( - new IndexInfoConfig.Indexinfo.Command.Builder() - .indexname(fieldSet.getName()) - .command(CMD_MULTIVALUE)); + addIndexCommand(iiB, fieldSet.getName(), CMD_MULTIVALUE); } if (anyIndexing) { - iiB.command( - new IndexInfoConfig.Indexinfo.Command.Builder() - .indexname(fieldSet.getName()) - .command(CMD_INDEX)); + addIndexCommand(iiB, fieldSet.getName(), CMD_INDEX); if ( ! isExactMatch(fieldSetMatching)) { if (fieldSetMatching == null || fieldSetMatching.getType().equals(MatchType.TEXT)) { - iiB.command( - new IndexInfoConfig.Indexinfo.Command.Builder() - .indexname(fieldSet.getName()) - .command(CMD_PLAIN_TOKENS)); + addIndexCommand(iiB, fieldSet.getName(), CMD_PLAIN_TOKENS); } if (anyStemming) { - iiB.command( - new IndexInfoConfig.Indexinfo.Command.Builder() - .indexname(fieldSet.getName()) - .command(stemmingCommand)); + addIndexCommand(iiB, fieldSet.getName(), stemmingCommand); } if (anyNormalizing) - iiB.command( - new IndexInfoConfig.Indexinfo.Command.Builder() - .indexname(fieldSet.getName()) - .command(CMD_NORMALIZE)); + addIndexCommand(iiB, fieldSet.getName(), CMD_NORMALIZE); if (phraseSegmentingCommand != null) - iiB.command( - new IndexInfoConfig.Indexinfo.Command.Builder() - .indexname(fieldSet.getName()) - .command(phraseSegmentingCommand)); + addIndexCommand(iiB, fieldSet.getName(), phraseSegmentingCommand); } } else { // Assume only attribute fields - iiB - .command( - new IndexInfoConfig.Indexinfo.Command.Builder() - .indexname(fieldSet.getName()) - .command(CMD_ATTRIBUTE)) - .command( - new IndexInfoConfig.Indexinfo.Command.Builder() - .indexname(fieldSet.getName()) - .command(CMD_INDEX)); + addIndexCommand(iiB, fieldSet.getName(), CMD_ATTRIBUTE); + addIndexCommand(iiB, fieldSet.getName(), CMD_INDEX); } if (anyString) { addIndexCommand(iiB, fieldSet.getName(), CMD_STRING); @@ -460,20 +424,11 @@ public class IndexInfo extends Derived implements IndexInfoConfig.Producer { if (fieldSetMatching.getType().equals(MatchType.EXACT)) { String term = fieldSetMatching.getExactMatchTerminator(); if (term==null) term=ExactMatch.DEFAULT_EXACT_TERMINATOR; - iiB.command( - new IndexInfoConfig.Indexinfo.Command.Builder() - .indexname(fieldSet.getName()) - .command("exact "+term)); + addIndexCommand(iiB, fieldSet.getName(), "exact "+term); } else if (fieldSetMatching.getType().equals(MatchType.WORD)) { - iiB.command( - new IndexInfoConfig.Indexinfo.Command.Builder() - .indexname(fieldSet.getName()) - .command(CMD_WORD)); + addIndexCommand(iiB, fieldSet.getName(), CMD_WORD); } else if (fieldSetMatching.getType().equals(MatchType.GRAM)) { - iiB.command( - new IndexInfoConfig.Indexinfo.Command.Builder() - .indexname(fieldSet.getName()) - .command("ngram " + fieldSetMatching.getGramSize().orElse(NGramMatch.DEFAULT_GRAM_SIZE))); + addIndexCommand(iiB, fieldSet.getName(), "ngram " + fieldSetMatching.getGramSize().orElse(NGramMatch.DEFAULT_GRAM_SIZE)); } else if (fieldSetMatching.getType().equals(MatchType.TEXT)) { } @@ -495,10 +450,7 @@ public class IndexInfo extends Derived implements IndexInfoConfig.Producer { active = field.getIndex(field.getName()).getStemming(); } } - if (active != null) { - return active; - } - return Stemming.BEST; // assume default + return Objects.requireNonNullElse(active, Stemming.BEST); } private boolean stemming(ImmutableSDField field) { @@ -514,9 +466,7 @@ public class IndexInfo extends Derived implements IndexInfoConfig.Producer { private boolean isExactMatch(Matching m) { if (m == null) return false; - if (m.getType().equals(MatchType.EXACT)) return true; - if (m.getType().equals(MatchType.WORD)) return true; - return false; + return m.getType().equals(MatchType.EXACT) || m.getType().equals(MatchType.WORD); } @Override @@ -528,34 +478,13 @@ 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; - } + 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) { @@ -564,7 +493,7 @@ public class IndexInfo extends Derived implements IndexInfoConfig.Producer { } return other.index.equals(this.index) && - other.command.equals(this.command); + other.command.equals(this.command); } public String toString() { @@ -616,9 +545,7 @@ public class IndexInfo extends Derived implements IndexInfoConfig.Producer { return false; } - if (Stemming.NONE.equals(indexStemming)) { - // Add nothing - } else { + if ( ! Stemming.NONE.equals(indexStemming)) { owner.addIndexCommand(indexName, CMD_STEM + ":" + indexStemming.toStemMode()); } return true; 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 diff --git a/config-model/src/main/java/com/yahoo/schema/document/Matching.java b/config-model/src/main/java/com/yahoo/schema/document/Matching.java index 0b542f134ad..9d68553fa80 100644 --- a/config-model/src/main/java/com/yahoo/schema/document/Matching.java +++ b/config-model/src/main/java/com/yahoo/schema/document/Matching.java @@ -46,12 +46,16 @@ public class Matching implements Cloneable, Serializable { public MatchType getType() { return type; } public Case getCase() { return casing; } - public void setType(MatchType type) { + public Matching setType(MatchType type) { this.type = type; typeUserSet = true; + return this; } - public void setCase(Case casing) { this.casing = casing; } + public Matching setCase(Case casing) { + this.casing = casing; + return this; + } public Integer maxLength() { return maxLength; } public Matching maxLength(int maxLength) { this.maxLength = maxLength; return this; } |