From a77ad2fe7ecc00d43b76326df7dec9d580429879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Volds=C3=A6ter?= <ole.voldsater@uib.no> Date: Thu, 20 Feb 2020 12:23:25 +0100 Subject: [PATCH] =?UTF-8?q?fungerer=20mot=20cache,=20men=20igjen=20bare=20?= =?UTF-8?q?for=20bokm=C3=A5l?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 35 +++++++++++++------------------- src/components/Header.vue | 2 +- src/components/SearchResults.vue | 8 ++++---- src/utils/helpers.js | 4 +++- 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/App.vue b/src/App.vue index 60545a2..d8197cc 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,14 +2,7 @@ <main id="app"> <img alt="Vue logo" src="./assets/logo.png"> <header> - <form class="" action="search" method="get"> - <input placeholder="Søk..." name="q" /> - <select class="" name="lang"> - <option value="nob">Bokmål</option> - <option value="nno">Nynorsk</option> - </select> - <input type="submit" name="" value="Yay!"> - </form> + <autocomplete :debounceTime="50" :auto-select="true" :search="search" :get-result-value="result_view" @submit="select_result" placeholder="søk..."></autocomplete> </header> <img id="spinner" :class="waiting ? 'show' : 'hide'" src="./assets/spinner.gif" alt="Venter på innhold" /> <SearchResults :hits="search_results" :lang="query_lang" /> @@ -21,10 +14,10 @@ import axios from "axios" import Article from './components/Article.vue' import SearchResults from './components/SearchResults.vue' -//import Autocomplete from '@trevoreyre/autocomplete-vue' -//import '@trevoreyre/autocomplete-vue/dist/style.css' +import Autocomplete from '@trevoreyre/autocomplete-vue' +import '@trevoreyre/autocomplete-vue/dist/style.css' -var api_endpoint = 'https://ordbok-dev.aws.uib.no/api/dict/' +var api_endpoint = 'https://ordbok-dev.aws.uib.no/cache/article/nob' export default { name: 'app', @@ -39,9 +32,9 @@ export default { search_results: [], waiting: true, article: {lemmas: [], body:{pronunciation: [], definitions: [], etymology: []}}, - /*search: function(q) { + search: function(q) { return new Promise(resolve => { - return axios.post(api_endpoint + '_search/', + return axios.post(api_endpoint + '/_search/', { "suggest": { "suggest" : { @@ -57,10 +50,10 @@ export default { resolve(hits) }) }) - },*/ + }, result_view: function(result) { if (result._source) - return result._source.lemmas.map(x => x.word).join(', ') + return result._source.lemmas.map(x => x.lemma).join(', ') else return 'Alle søkeresultater...' } @@ -68,7 +61,7 @@ export default { }, components: { Article, - //Autocomplete, + Autocomplete, SearchResults }, methods: { @@ -77,24 +70,24 @@ export default { this.search_results = [] this.article = event._source }else{ - window.location.href="search?q=" + event.q + window.location.href="/search?q=" + event.q } } }, mounted: function(){ var self = this; if(this.search_query) { - axios.get(api_endpoint + self.query_lang + '/article' + '?expand_lemmas=true&lemma_text=' + self.search_query) + axios.get(api_endpoint + '/_search?q=' + self.search_query) .then(function(response){ - self.search_results = response.data + self.search_results = response.data.hits.hits self.waiting = false }) } else if(this.article_id) { - axios.get(api_endpoint + self.path_lang + '/article' + '/' + self.article_id + '?expand_lemmas=true&expand_refs=true') + axios.get(api_endpoint + '/' + self.article_id) .then(function(response){ - self.article = response.data + self.article = response.data._source self.waiting = false }) } diff --git a/src/components/Header.vue b/src/components/Header.vue index 655bad1..edc0ba8 100644 --- a/src/components/Header.vue +++ b/src/components/Header.vue @@ -6,7 +6,7 @@ <h4>{{lemma.lemma}}</h4> <table v-for="(std, index) in lemma.standardisations" :key="index"> <tr> - <th rowspan="2">{{std.tags.join(', ')}}</th> + <th rowspan="2">{{std.tags ? std.tags.join(', ') : ''}}</th> <th v-for="(inflection, index) in std.inflection" :key="index">{{inflection.tags.join(', ')}}</th> </tr> <tr> diff --git a/src/components/SearchResults.vue b/src/components/SearchResults.vue index 72cf9a3..17ff7d1 100644 --- a/src/components/SearchResults.vue +++ b/src/components/SearchResults.vue @@ -3,7 +3,7 @@ <h2 v-if="hits.length">Søkeresultater</h2> <ul> <li v-for="(result, index) in extended_results" :key="index"> - <a :href="'/' + lang + '/' + result.id">{{result.label}}</a> ({{result.classification}}) + <a :href="'/' + result.id">{{result.label}}</a> ({{result.classification}}) </li> </ul> </section> @@ -22,9 +22,9 @@ export default { return this.hits.map( function(hit){ return { - id: hit.article_id, - label: hit.lemmas.map(x => x.lemma).join(', '), - classification: helpers.group_list(hit.lemmas) + id: hit._id, + label: hit._source.lemmas.map(x => x.lemma).join(', '), + classification: helpers.group_list(hit._source.lemmas) } }) } diff --git a/src/utils/helpers.js b/src/utils/helpers.js index f40ede5..c1c6a88 100644 --- a/src/utils/helpers.js +++ b/src/utils/helpers.js @@ -2,7 +2,9 @@ var group_list = function(grps) { var grp_collection = new Set() grps.forEach(function(lemma){ lemma.standardisations.forEach(function(grp){ - grp_collection.add(grp.tags[0] == 'subst' ? grp.tags[0] + ',' + grp.tags[1] : grp.tags[0]) + if (grp.tags){ + grp_collection.add(grp.tags[0] == 'subst' ? grp.tags[0] + ',' + grp.tags[1] : grp.tags[0]) + } }) }) return Array.from(grp_collection).join('; ') -- GitLab