Skip to content

Commit

Permalink
Fix autosuggest for complex fields foo.bar.zoo
Browse files Browse the repository at this point in the history
Recursively parse object to find all suggestions.
  • Loading branch information
ArpiJakab committed Mar 30, 2018
1 parent 9fa6092 commit a7fd7d5
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/utils/suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ const getSuggestions = (fields, suggestions, currentValue) => {
}
};

suggestions.forEach((item) => {
fields.forEach((field) => {
const label = item._source[field];
if (label) {
const parseField = (source, field) => {
const fieldNodes = field.split('.');
const label = source[fieldNodes[0]];
if (label) {
if (fieldNodes.length > 1) {
// nested fields of the 'foo.bar.zoo' variety
const children = field.substring(fieldNodes[0].length + 1);
if (Array.isArray(label)) {
label.forEach((arrayItem) => { parseField(arrayItem, children); });
} else {
parseField(label, children);
}
} else {
const val = extractSuggestion(label);
if (val) {
if (Array.isArray(val)) {
Expand All @@ -50,7 +59,11 @@ const getSuggestions = (fields, suggestions, currentValue) => {
}
}
}
});
}
};

suggestions.forEach((item) => {
fields.forEach((field) => { parseField(item._source, field); });
});

return suggestionsList;
Expand Down

0 comments on commit a7fd7d5

Please sign in to comment.