diff --git a/content/search.html.erb b/content/search.html.erb
index e0059cc..8257432 100644
--- a/content/search.html.erb
+++ b/content/search.html.erb
@@ -1,8 +1,8 @@
@@ -52,6 +52,32 @@ function resetFromUrl() {
}
function ready() {
+ Array.prototype.stableSort = function(cmp) {
+ cmp = !!cmp ? cmp : (a, b) => {
+ if (a < b) return -1;
+ if (a > b) return 1;
+ return 0;
+ };
+ let stabilizedThis = this.map((el, index) => [el, index]);
+ let stableCmp = (a, b) => {
+ let order = cmp(a[0], b[0]);
+ if (order != 0) return order;
+ return a[1] - b[1];
+ }
+ stabilizedThis.sort(stableCmp);
+ for (let i=0; i
y) ? 1 : 0));
+ });
+ }
+
function render_results(div, partials) {
const create_wrapper= document.createElement('div');
for(let partial of partials) {
@@ -92,7 +118,7 @@ function ready() {
doSearch = (query) => {
clearDiv(wrapper);
- render_results(wrapper, index.search(query).map(i => partials[i.ref]));
+ render_results(wrapper, index.search(query).sortByKey(i => partials[i.ref].titel).stableSort((a, b) => b.score - a.score).map(i => partials[i.ref]));
window.history.pushState("search state", "", window.location.pathname + "?q="+query);
};