Skip to content
Snippets Groups Projects
Commit 3ce89846 authored by Ole Voldsæter's avatar Ole Voldsæter
Browse files

fikser meta#318

parent 7fff4bf7
No related branches found
Tags release_2021-11-24
No related merge requests found
...@@ -74,6 +74,15 @@ import Autocomplete from './Autocomplete.vue' ...@@ -74,6 +74,15 @@ import Autocomplete from './Autocomplete.vue'
var api_endpoint = 'https://beta.ordbok.uib.no/api/dict' 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) { axios.interceptors.request.use(function (config) {
config.headers["x-api-key"] = "ZkYiyRVXxH86ijsvhx3cH4SY5Iik2ijI3BKVJGMm" config.headers["x-api-key"] = "ZkYiyRVXxH86ijsvhx3cH4SY5Iik2ijI3BKVJGMm"
return config; return config;
...@@ -132,7 +141,7 @@ function navigate_to_search(self, query) { ...@@ -132,7 +141,7 @@ function navigate_to_search(self, query) {
function navigate_to_word(self, word) { function navigate_to_word(self, word) {
axios.get(self.api_pref + 'suggest?q=' + word) axios.get(self.api_pref + 'suggest?q=' + word)
.then(function(response){ .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) { if (! self.search_results.length) {
self.error = "Ordet '" + decodeURIComponent(word) + "' finnes ikke i ordbøkene" self.error = "Ordet '" + decodeURIComponent(word) + "' finnes ikke i ordbøkene"
} else { } else {
...@@ -185,7 +194,7 @@ export default { ...@@ -185,7 +194,7 @@ export default {
if(event.articles){ if(event.articles){
let source = '/' + this.lang + '/w/' + event.word let source = '/' + this.lang + '/w/' + event.word
this.$router.push(source) 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.article = null
this.error = null this.error = null
history.replaceState({article: this.article, search_results: this.search_results, lang: this.lang, error: this.error}, '') history.replaceState({article: this.article, search_results: this.search_results, lang: this.lang, error: this.error}, '')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment