Skip to content

Commit

Permalink
Merge pull request #32655 from vespa-engine/arnej/match-cased-implies…
Browse files Browse the repository at this point in the history
…-dictionary-cased

"match: cased" should imply "dictionary: cased"
  • Loading branch information
arnej27959 authored Oct 31, 2024
2 parents 562712d + ec2b590 commit 136687c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void updateType(Type type) {
}
}
public void updateMatch(Case casing) {
if (this.casing != null) {
if (this.casing != null && this.casing != casing) {
throw new IllegalArgumentException("dictionary match mode has already been set to " + this.casing);
}
this.casing = casing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,17 @@ public class ConvertParsedFields {
this.structProxies = structProxies;
}

static void caseHandling(SDField field, Case casing) {
field.setMatchingCase(casing);
if (casing == Case.CASED) {
var dictionary = field.getOrSetDictionary();
dictionary.updateMatch(casing);
}
}

static void convertMatchSettings(SDField field, ParsedMatchSettings parsed) {
parsed.getMatchType().ifPresent(matchingType -> field.setMatchingType(matchingType));
parsed.getMatchCase().ifPresent(casing -> field.setMatchingCase(casing));
parsed.getMatchCase().ifPresent(casing -> caseHandling(field, casing));
parsed.getGramSize().ifPresent(gramSize -> field.getMatching().setGramSize(gramSize));
parsed.getMaxLength().ifPresent(maxLength -> field.getMatching().maxLength(maxLength));
parsed.getMaxTermOccurrences().ifPresent(maxTermOccurrences -> field.getMatching().maxTermOccurrences(maxTermOccurrences));
Expand Down Expand Up @@ -290,21 +298,29 @@ private void convertIndexSettings(Index index, ParsedIndex parsed) {

SDField convertDocumentField(Schema schema, SDDocumentType document, ParsedField parsed) {
String name = parsed.name();
DataType dataType = context.resolveType(parsed.getType());
var field = new SDField(document, name, dataType);
convertCommonFieldSettings(schema, field, parsed);
convertExtraFieldSettings(schema, field, parsed);
document.addField(field);
return field;
try {
DataType dataType = context.resolveType(parsed.getType());
var field = new SDField(document, name, dataType);
convertCommonFieldSettings(schema, field, parsed);
convertExtraFieldSettings(schema, field, parsed);
document.addField(field);
return field;
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("For schema '" + schema.getName() + "', field '" + name + "': " + e.getMessage());
}
}

void convertExtraField(Schema schema, ParsedField parsed) {
String name = parsed.name();
DataType dataType = context.resolveType(parsed.getType());
var field = new SDField(schema.getDocument(), name, dataType);
convertCommonFieldSettings(schema, field, parsed);
convertExtraFieldSettings(schema, field, parsed);
schema.addExtraField(field);
try {
DataType dataType = context.resolveType(parsed.getType());
var field = new SDField(schema.getDocument(), name, dataType);
convertCommonFieldSettings(schema, field, parsed);
convertExtraFieldSettings(schema, field, parsed);
schema.addExtraField(field);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("For schema '" + schema.getName() + "', field '" + name + "': " + e.getMessage());
}
}

void convertExtraIndex(Schema schema, ParsedIndex parsed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ void testStringBtreeUnCasedSettings() throws ParseException {
@Test
void testStringBtreeCasedSettings() throws ParseException {
verifyStringDictionaryControl(Dictionary.Type.BTREE, Case.CASED, Case.CASED, "dictionary { btree\ncased\n}", "match:cased");
verifyStringDictionaryControl(Dictionary.Type.BTREE, Case.CASED, Case.CASED, "dictionary: btree", "match: cased");
try {
verifyStringDictionaryControl(Dictionary.Type.BTREE, Case.UNCASED, Case.CASED, "dictionary { hash\nuncased\n}", "match: cased");
} catch (IllegalArgumentException e) {
assertEquals("For schema 'test', field 'n1': dictionary match mode has already been set to CASED", e.getMessage());
}
}

@Test
Expand Down

0 comments on commit 136687c

Please sign in to comment.