Skip to content

Commit

Permalink
Smart subfield selection.
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com>
  • Loading branch information
Yury-Fridlyand committed Jul 28, 2023
1 parent 5232ad2 commit 8b0671c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ public String convertFieldForSearchQuery(String fieldName) {
if (fields.size() == 0) {
return fieldName;
}
// Pick first field. What to do if there are multiple fields?
// Pick first string subfield (if present) otherwise pick first subfield.
// Multi-field text support requested in https://github.com/opensearch-project/sql/issues/1887
return String.format("%s.%s", fieldName, fields.keySet().toArray()[0]);
String subField = fields.entrySet().stream()
.filter(e -> e.getValue().getExprType().equals(STRING))
.map(Map.Entry::getKey)
.findFirst()
.orElseGet(() -> fields.keySet().toArray(String[]::new)[0]);
return String.format("%s.%s", fieldName, subField);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void convertFieldForSearchQuery() {
OpenSearchTextType.of(fieldsWithKeyword).convertFieldForSearchQuery("field")),
() -> assertEquals("field.numbers",
OpenSearchTextType.of(fieldsWithNumber).convertFieldForSearchQuery("field")),
() -> assertEquals("field.numbers",
() -> assertEquals("field.words",
OpenSearchTextType.of(fieldsWithMixed).convertFieldForSearchQuery("field"))
);
}
Expand Down

0 comments on commit 8b0671c

Please sign in to comment.