diff --git a/src/App.vue b/src/App.vue index 60545a227bfde517be9b8ddc107c4b76fe3a468c..d8197cc824170e93d7fd54aa9e96a6adc035a3cf 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 655bad1b2a4e20d1c39abb9cceffb5324a3087f7..edc0ba82b9bd6018ce5f0dcce3b530283b806626 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 72cf9a31b42bb70a246d32918adcca78a51d9019..17ff7d1cb2f316161d6931a7bb9362bb661fb3dc 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 f40ede559b9deb6aac5068043080e087f248d108..c1c6a88fe3ca0d6f55271c38020999d58fb762fa 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('; ')