From 3ce898464ff589a85f95e02f8b5d6224d543bd1a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ole=20Volds=C3=A6ter?= <ole.voldsater@uib.no>
Date: Tue, 6 Apr 2021 14:27:07 +0200
Subject: [PATCH] fikser meta#318

---
 src/components/DictionaryView.vue | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/components/DictionaryView.vue b/src/components/DictionaryView.vue
index 152b76e9..c5ab0176 100644
--- a/src/components/DictionaryView.vue
+++ b/src/components/DictionaryView.vue
@@ -74,6 +74,15 @@ import Autocomplete from './Autocomplete.vue'
 
 var api_endpoint = 'https://beta.ordbok.uib.no/api/dict'
 
+function compare_by_hgno(lemma_text) {
+  return function(art1, art2) {
+    let lemma1 = art1.lemmas.filter(lemma => lemma.lemma == lemma_text)[0]
+    let lemma2 = art2.lemmas.filter(lemma => lemma.lemma == lemma_text)[0]
+
+    return lemma1.hgno - lemma2.hgno
+  }
+}
+
 axios.interceptors.request.use(function (config) {
     config.headers["x-api-key"] = "ZkYiyRVXxH86ijsvhx3cH4SY5Iik2ijI3BKVJGMm"
     return config;
@@ -132,7 +141,7 @@ function navigate_to_search(self, query) {
 function navigate_to_word(self, word) {
   axios.get(self.api_pref + 'suggest?q=' + word)
   .then(function(response){
-    self.search_results = response.data.filter(result => result.match.length == word.length)
+    self.search_results = response.data.filter(result => result.match.length == word.length).sort(compare_by_hgno(word))
     if (! self.search_results.length) {
       self.error = "Ordet '" + decodeURIComponent(word) + "' finnes ikke i ordbøkene"
     } else {
@@ -185,7 +194,7 @@ export default {
       if(event.articles){
         let source = '/' + this.lang + '/w/' + event.word
         this.$router.push(source)
-        this.search_results = event.articles.map(a => Object.assign(a, {source: source}))
+        this.search_results = event.articles.sort(compare_by_hgno(event.word)).map(a => Object.assign(a, {source: source}))
         this.article = null
         this.error = null
         history.replaceState({article: this.article, search_results: this.search_results, lang: this.lang, error: this.error}, '')
-- 
GitLab