Skip to content
Snippets Groups Projects
Commit 6aa71596 authored by Henrik Askjer's avatar Henrik Askjer
Browse files

Use timestamp to evaluate the need for verbatim suggestion

parent 138b0433
No related branches found
No related tags found
No related merge requests found
...@@ -52,10 +52,11 @@ ...@@ -52,10 +52,11 @@
}, },
watch: { watch: {
search (val) { search (val) {
const time = Date.now()
if (! val) { if (! val) {
this.items = [] this.items = []
} else { } else {
this.run_query(val) this.run_query(val, time)
} }
}, },
select(item) { select(item) {
...@@ -81,17 +82,17 @@ ...@@ -81,17 +82,17 @@
} }
}, },
methods: { methods: {
run_query(q) { run_query(q, time) {
this.suggesting = true this.suggesting = true
// Keep full text search in the list while requesting suggestions // Keep full text search in the list while requesting suggestions
if (this.items[0]) { if (this.items[0]) {
if (this.items[0].lang) { if (this.items[0].time < time) {
this.items.unshift({q: q, label: q}) this.items.splice(0,1, {q: q, label: q, time: time})
}
else {
this.items[0] = {q: q, label: q}
} }
} }
else {
this.items.push({q: q, label: q, time: time})
}
let self = this let self = this
self.api.get('suggest?', {params: {q: q, dict: self.$parent.lang, n: 9}}) self.api.get('suggest?', {params: {q: q, dict: self.$parent.lang, n: 9}})
.then(async (response) => { .then(async (response) => {
...@@ -100,7 +101,7 @@ ...@@ -100,7 +101,7 @@
let hits = [] let hits = []
response.data.forEach((item, i) => { response.data.forEach((item, i) => {
let match = item[0] let match = item[0]
let hit = {q: q, match: match, label: match} let hit = {q: q, match: match, label: match, time: time}
hit.article_promise = self.api.get('articles?', {params: {lord: match, dict: self.$parent.lang}}) hit.article_promise = self.api.get('articles?', {params: {lord: match, dict: self.$parent.lang}})
...@@ -109,7 +110,7 @@ ...@@ -109,7 +110,7 @@
}); });
// whitespace necessary because duplicates aren't allowed in the dropdown // whitespace necessary because duplicates aren't allowed in the dropdown
hits.push({q: q, label: q + ' '}) hits.push({q: q, label: q + ' ', time: time})
self.items = hits self.items = hits
} }
self.loading = false self.loading = false
......
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