Newer
Older
<div class="autocomplete-container" :class="$vuetify.breakpoint.name">
<v-combobox accesskey="s" aria-label="søkefelt"
v-model="select"
:loading="loading"
:items="items"
:search-input.sync="search"
item-text="label"
:menu-props="{maxHeight: $vuetify.breakpoint.name === 'xs' ? 190 : 500, transition: 'fade-transition', allowOverflow: true}"
:append-icon="null"
full-width
({{data.item.lang? data.item.lang[1] ? "bm, nn" : {"bob": "bm", "nob": "nn"}[data.item.lang[0]] : ["fulltekst","fritekst","avansert søk"][data.item.mode]}})
<template slot="no-data">
<div></div>
</template>
},
data: function() {
return {
loading: false,
items: [],
search: null,
}
},
watch: {
search (val) {
const time = Date.now()
if (! val) {
this.items = []
} else {
this.run_query(val, time)
this.items = []
this.submit(item)
run_query(q, time) {
// Keep full text search in the list while requesting suggestions
if (this.items[0].time < time) {
if (/_|\*|\|/.test(q)) {
this.items.splice(0,1, {q: q, label: q, time: time, mode: 2})
} else {
this.items.splice(0,1, {q: q+"*", label: q, time: time, mode: 1})
}
this.items.splice(0,1, {q: q+"*", label: q, time: time, mode: 1})
self.api.get('suggest?', {params: {q: q, dict: self.$parent.lang, n: 80, scope: 'nf'}})
if (self.$refs.autocomplete.searchInput == q & self.suggesting) {
let word_matches = response.data.a.n.map(item => ({q: q, match: item[0], label: item[0], time: time, lang: item[1]}))
let text_matches = response.data.a.f.map(item => ({q: q, match: item[0], label: item[0], time: time, mode: 0}))
let suggestions = []
if( q.charAt(q.length-1) === '!') suggestions = text_matches.concat(word_matches)
else suggestions = word_matches.concat(text_matches)
suggestions.unshift({q: q, label: q, time: time, mode: 2})
} else {
suggestions.push({q: q+"*", label: q + ' ', time: time, mode: 1})
// whitespace necessary because duplicates aren't allowed in the dropdown
self.items = suggestions
submit(item) {
this.$emit('submit', item)
let self = this
setTimeout(() => {
self.$refs.autocomplete.$refs.input.select()
this.items = []
this.suggesting = false
}, 1)
}
<style scoped>
.search-hit {
font-weight: bold;
margin-right: 5px;
color: var(--v-primary-base);
padding-left: 10px;
padding-right: 10px;