From ebe5ae7f2cc6f44abc13cdaf09de78b4f72dee14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Volds=C3=A6ter?= <ole.voldsater@uib.no> Date: Wed, 30 Sep 2020 14:19:38 +0200 Subject: [PATCH] =?UTF-8?q?refs=20meta#150=20s=C3=B8k=20og=20autocomplete?= =?UTF-8?q?=20mottar=20rene=20lister=20med=20artikler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 14 +++++++------- src/components/Preview.vue | 12 ++++++------ src/components/SearchResults.vue | 10 +++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/App.vue b/src/App.vue index 6dfc470..95b1848 100644 --- a/src/App.vue +++ b/src/App.vue @@ -99,7 +99,7 @@ export default { return axios.get(self.api_pref + 'suggest?q=' + q).then( function(response) { let hits = q.length ? [{q: q}] : [] - hits = hits.concat(response.data.suggest.suggest[0].options.sort((o1, o2) => o1.text.length - o2.text.length)) + hits = hits.concat(response.data) resolve(hits) }) }) @@ -116,19 +116,19 @@ export default { select_result: function(event) { this.$refs.search.value = '' document.activeElement.blur() - if(event._source){ + if(event.body){ this.$router.push('/' + event._index + '/' + event._id) this.search_results = [] - this.article = event._source + this.article = event history.replaceState({article: this.article, search_results: this.search_results, lang: this.lang}, '') }else{ var self = this self.waiting = true self.article = {lemmas: [], body:{pronunciation: [], definitions: [], etymology: []}} - axios.get(self.api_pref + 'search?q=' + event.q + ' ' + event.q + '*&size=20') + axios.get(self.api_pref + 'search?q=' + event.q) .then(function(response){ self.$router.push('/' + `/search?q=${event.q}&lang=${self.lang}`) - self.search_results = response.data.hits.hits + self.search_results = response.data self.waiting = false history.replaceState({article: self.article, search_results: self.search_results, lang: self.lang}, '') }) @@ -160,9 +160,9 @@ export default { this.lang = this.$route.params.lang || this.$route.query.lang || 'bob,nob' var self = this; if(this.$route.query.q) { - axios.get(self.api_pref + 'search?q=' + self.$route.query.q + ' ' + self.$route.query.q + '*&size=20') + axios.get(self.api_pref + 'search?q=' + self.$route.query.q) .then(function(response){ - self.search_results = response.data.hits.hits + self.search_results = response.data self.waiting = false history.replaceState({article: self.article, search_results: self.search_results, lang: self.lang}, '') }) diff --git a/src/components/Preview.vue b/src/components/Preview.vue index 5c7df1c..1870a1d 100644 --- a/src/components/Preview.vue +++ b/src/components/Preview.vue @@ -26,13 +26,13 @@ export default { }, computed: { previewHeader: function(){ - return this.searchHit.text && this.searchHit.text + " (" + labels[this.searchHit._index] + ")" || - (this.searchHit._source && this.searchHit._source.lemmas.map(l => `${l.lemma}`) || []).join(',') || + return this.searchHit.match && this.searchHit.match + " (" + labels[this.searchHit.dictionary] + ")" || + (this.searchHit.lemmas && this.searchHit.lemmas.map(l => `${l.lemma}`) || []).join(',') || "Alle søkeresultater..." }, previewText: function(){ - if (! this.searchHit._source) return '' - let element = this.searchHit._source.body.definitions[0] || '' + if (! this.searchHit.body) return '' + let element = this.searchHit.body.definitions[0] || '' while (element.type_ == 'definition') element = element.elements[0] if (element.type_ == 'example') { element = element.quote @@ -40,7 +40,7 @@ export default { element = {content: '', items: []} } - let lang = this.searchHit._index + let lang = this.searchHit.dictionary let replacements = element.items.map(item => item.text || item.string || @@ -54,7 +54,7 @@ export default { return element.content.replace(/\$/gi, replacement) }, group_list: function() { - return helpers.group_list(this.searchHit._source.lemmas) + return helpers.group_list(this.searchHit.lemmas) } }, components: { diff --git a/src/components/SearchResults.vue b/src/components/SearchResults.vue index 40db8b1..6daf7aa 100644 --- a/src/components/SearchResults.vue +++ b/src/components/SearchResults.vue @@ -33,19 +33,19 @@ export default { }, computed: { results_bob: function(){ - return this.hits.filter(hit => hit._index == 'bob') + return this.hits.filter(hit => hit.dictionary == 'bob') }, results_nob: function(){ - return this.hits.filter(hit => hit._index == 'nob') + return this.hits.filter(hit => hit.dictionary == 'nob') }, results_norsk: function(){ - return this.hits.filter(hit => hit._index == 'norsk_ordbok') + return this.hits.filter(hit => hit.dictionary == 'norsk_ordbok') } }, methods: { article_link_click: function(result) { - this.$router.push('/' + result._index + '/' + result._id) - this.$emit('search-hit-click', result._source) + this.$router.push('/' + result.dictionary + '/' + result.article_id) + this.$emit('search-hit-click', result) } }, components: { -- GitLab