Skip to content

Commit

Permalink
Allow array as selected values in search results (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
CGamesPlay authored Apr 16, 2020
1 parent c7930a9 commit 12c0266
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions services/normalDocSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ angular.module('o19s.splainer-search')
// returns: obj['a']['b'] => c
//
var multiIndex = function(obj, keys) {
return keys.length ? multiIndex(obj[keys[0]], keys.slice(1)) : obj;
if (keys.length === 0) {
return obj;
} else if (Array.isArray(obj)) {
return obj.map(function(child) {
return multiIndex(child, keys);
});
} else {
return multiIndex(obj[keys[0]], keys.slice(1));
}
};

//
Expand Down Expand Up @@ -105,6 +113,7 @@ angular.module('o19s.splainer-search')
var value = pathIndex(doc, subFieldName);
normalDoc.subs[subFieldName] = parseValue(value);
} catch (e) {
console.error(e);
normalDoc.subs[subFieldName] = '';
}
} else if ( doc.hasOwnProperty(subFieldName) ) {
Expand Down Expand Up @@ -167,7 +176,7 @@ angular.module('o19s.splainer-search')
doc.subSnippets = function(hlPre, hlPost) {
if (lastHlPre !== hlPre || lastHlPost !== hlPost) {
angular.forEach(doc.subs, function(subFieldValue, subFieldName) {
if ( typeof subFieldValue === 'object' && !(subFieldValue instanceof Array)) {
if ( typeof subFieldValue === 'object' ) {
lastSubSnips[subFieldName] = subFieldValue;
} else {
var snip = aDoc.highlight(
Expand Down

0 comments on commit 12c0266

Please sign in to comment.