Skip to content
Snippets Groups Projects
Commit a77ad2fe authored by Ole Voldsæter's avatar Ole Voldsæter
Browse files

fungerer mot cache, men igjen bare for bokmål

parent cc209c42
No related branches found
No related tags found
No related merge requests found
...@@ -2,14 +2,7 @@ ...@@ -2,14 +2,7 @@
<main id="app"> <main id="app">
<img alt="Vue logo" src="./assets/logo.png"> <img alt="Vue logo" src="./assets/logo.png">
<header> <header>
<form class="" action="search" method="get"> <autocomplete :debounceTime="50" :auto-select="true" :search="search" :get-result-value="result_view" @submit="select_result" placeholder="søk..."></autocomplete>
<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>
</header> </header>
<img id="spinner" :class="waiting ? 'show' : 'hide'" src="./assets/spinner.gif" alt="Venter på innhold" /> <img id="spinner" :class="waiting ? 'show' : 'hide'" src="./assets/spinner.gif" alt="Venter på innhold" />
<SearchResults :hits="search_results" :lang="query_lang" /> <SearchResults :hits="search_results" :lang="query_lang" />
...@@ -21,10 +14,10 @@ ...@@ -21,10 +14,10 @@
import axios from "axios" import axios from "axios"
import Article from './components/Article.vue' import Article from './components/Article.vue'
import SearchResults from './components/SearchResults.vue' import SearchResults from './components/SearchResults.vue'
//import Autocomplete from '@trevoreyre/autocomplete-vue' import Autocomplete from '@trevoreyre/autocomplete-vue'
//import '@trevoreyre/autocomplete-vue/dist/style.css' 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 { export default {
name: 'app', name: 'app',
...@@ -39,9 +32,9 @@ export default { ...@@ -39,9 +32,9 @@ export default {
search_results: [], search_results: [],
waiting: true, waiting: true,
article: {lemmas: [], body:{pronunciation: [], definitions: [], etymology: []}}, article: {lemmas: [], body:{pronunciation: [], definitions: [], etymology: []}},
/*search: function(q) { search: function(q) {
return new Promise(resolve => { return new Promise(resolve => {
return axios.post(api_endpoint + '_search/', return axios.post(api_endpoint + '/_search/',
{ {
"suggest": { "suggest": {
"suggest" : { "suggest" : {
...@@ -57,10 +50,10 @@ export default { ...@@ -57,10 +50,10 @@ export default {
resolve(hits) resolve(hits)
}) })
}) })
},*/ },
result_view: function(result) { result_view: function(result) {
if (result._source) if (result._source)
return result._source.lemmas.map(x => x.word).join(', ') return result._source.lemmas.map(x => x.lemma).join(', ')
else else
return 'Alle søkeresultater...' return 'Alle søkeresultater...'
} }
...@@ -68,7 +61,7 @@ export default { ...@@ -68,7 +61,7 @@ export default {
}, },
components: { components: {
Article, Article,
//Autocomplete, Autocomplete,
SearchResults SearchResults
}, },
methods: { methods: {
...@@ -77,24 +70,24 @@ export default { ...@@ -77,24 +70,24 @@ export default {
this.search_results = [] this.search_results = []
this.article = event._source this.article = event._source
}else{ }else{
window.location.href="search?q=" + event.q window.location.href="/search?q=" + event.q
} }
} }
}, },
mounted: function(){ mounted: function(){
var self = this; var self = this;
if(this.search_query) { 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){ .then(function(response){
self.search_results = response.data self.search_results = response.data.hits.hits
self.waiting = false self.waiting = false
}) })
} }
else if(this.article_id) 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){ .then(function(response){
self.article = response.data self.article = response.data._source
self.waiting = false self.waiting = false
}) })
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<h4>{{lemma.lemma}}</h4> <h4>{{lemma.lemma}}</h4>
<table v-for="(std, index) in lemma.standardisations" :key="index"> <table v-for="(std, index) in lemma.standardisations" :key="index">
<tr> <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> <th v-for="(inflection, index) in std.inflection" :key="index">{{inflection.tags.join(', ')}}</th>
</tr> </tr>
<tr> <tr>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<h2 v-if="hits.length">Søkeresultater</h2> <h2 v-if="hits.length">Søkeresultater</h2>
<ul> <ul>
<li v-for="(result, index) in extended_results" :key="index"> <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> </li>
</ul> </ul>
</section> </section>
...@@ -22,9 +22,9 @@ export default { ...@@ -22,9 +22,9 @@ export default {
return this.hits.map( return this.hits.map(
function(hit){ function(hit){
return { return {
id: hit.article_id, id: hit._id,
label: hit.lemmas.map(x => x.lemma).join(', '), label: hit._source.lemmas.map(x => x.lemma).join(', '),
classification: helpers.group_list(hit.lemmas) classification: helpers.group_list(hit._source.lemmas)
} }
}) })
} }
......
...@@ -2,7 +2,9 @@ var group_list = function(grps) { ...@@ -2,7 +2,9 @@ var group_list = function(grps) {
var grp_collection = new Set() var grp_collection = new Set()
grps.forEach(function(lemma){ grps.forEach(function(lemma){
lemma.standardisations.forEach(function(grp){ 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('; ') return Array.from(grp_collection).join('; ')
......
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