Skip to content

Commit

Permalink
Issue #543: fix mapping for search_as_you_type
Browse files Browse the repository at this point in the history
  • Loading branch information
mrk-vi committed Aug 25, 2023
1 parent a8ac952 commit f308a96
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ private static Map<MappingsKey, Object> createMappingsFlat_(
String currentFieldName = fieldNamesArray[i];

boolean isLast = i == fieldNamesArray.length - 1;
boolean isFields = isKeyword && i == fieldNamesArray.length - 2;
boolean isFields =
(fieldType == FieldType.KEYWORD || fieldType == FieldType.SEARCH_AS_YOU_TYPE)
&& i == fieldNamesArray.length - 2;

current = (Map<MappingsKey, Object>) current.computeIfAbsent(
new MappingsKey(currentFieldName), k -> new LinkedHashMap<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -66,7 +65,13 @@ private static DocType aDocTypeWithHierarchy() {
streetKeyword.setFieldType(FieldType.KEYWORD);
streetKeyword.setParentDocTypeField(street);

street.setSubDocTypeFields(Set.of(streetKeyword));
DocTypeField streetSearchAsYouType = new DocTypeField();
streetSearchAsYouType.setDocType(docType);
streetSearchAsYouType.setFieldName("address.street.search_as_you_type");
streetSearchAsYouType.setFieldType(FieldType.SEARCH_AS_YOU_TYPE);
streetSearchAsYouType.setParentDocTypeField(street);

street.setSubDocTypeFields(Set.of(streetKeyword, streetSearchAsYouType));

DocTypeField number = new DocTypeField();
number.setDocType(docType);
Expand Down Expand Up @@ -168,6 +173,11 @@ private static DocType aDocTypeWithFlatFields() {
streetKeyword.setFieldName("address.street.keyword");
streetKeyword.setFieldType(FieldType.KEYWORD);

DocTypeField streetSearchAsYouType = new DocTypeField();
streetSearchAsYouType.setDocType(docType);
streetSearchAsYouType.setFieldName("address.street.search_as_you_type");
streetSearchAsYouType.setFieldType(FieldType.SEARCH_AS_YOU_TYPE);

DocTypeField number = new DocTypeField();
number.setDocType(docType);
number.setFieldName("address.number");
Expand Down Expand Up @@ -219,6 +229,7 @@ private static DocType aDocTypeWithFlatFields() {
address,
street,
streetKeyword,
streetSearchAsYouType,
number,
description,
descriptionBase,
Expand All @@ -233,50 +244,42 @@ private static DocType aDocTypeWithFlatFields() {

private static Object expectedJson() {
return Json.decodeValue("""
{
"properties": {
"complexNumber": {
"properties": {
"realPart": {
"type": "integer"
},
"imaginaryPart": {
"type": "integer"
}
}
},
"title": {
"type": "text"
},
"address": {
{
"properties": {
"street": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
"complexNumber": {
"properties": {
"realPart": {
"type": "integer"
},
"imaginaryPart": {
"type": "integer"
}
}
},
"title": {
"type": "text"
},
"number": {
"type": "integer"
}
}
},
"description": {
"properties": {
"base": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
"address": {
"properties": {
"street": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
},
"search_as_you_type": {
"type": "search_as_you_type"
}
}
},
"number": {
"type": "integer"
}
}
},
"i18n": {
"description": {
"properties": {
"en_US": {
"base": {
"type": "text",
"fields": {
"keyword": {
Expand All @@ -285,22 +288,33 @@ private static Object expectedJson() {
}
}
},
"de_DE": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
"i18n": {
"properties": {
"en_US": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"de_DE": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
}
}
}
""");
""");
}

}

0 comments on commit f308a96

Please sign in to comment.