Skip to content

Commit f192bf7

Browse files
committed
qualify separate occurrences of same lvl0 title in search results so order of results is preserved
1 parent f18f3d3 commit f192bf7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/js/vendor/docsearch.bundle.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
inputSelector: '#search-query',
1919
autocompleteOptions: { autoselect: true, debug: true, hint: false, keyboardShortcuts: ['s'], minLength: 2 },
2020
algoliaOptions: algoliaOptions,
21+
transformData: transformData,
2122
})
2223
var eventEmitter = controller.autocomplete
2324
var autocomplete = eventEmitter.autocomplete
@@ -63,4 +64,18 @@
6364
this.close()
6465
this.setVal()
6566
}
67+
68+
// qualify separate occurrences of the same lvl0 title so that the order of results is preserved
69+
function transformData (hits) {
70+
var prevLvl0Title
71+
var qualifiers = {}
72+
return hits.map(function (hit) {
73+
var lvl0Title = hit.hierarchy.lvl0
74+
var qualifier = qualifiers[lvl0Title]
75+
if (lvl0Title !== prevLvl0Title) qualifiers[lvl0Title] = qualifier == null ? '' : (qualifier += ' ')
76+
if (qualifier) hit.hierarchy.lvl0 = lvl0Title + qualifier
77+
prevLvl0Title = lvl0Title
78+
return hit
79+
})
80+
}
6681
})()

0 commit comments

Comments
 (0)