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

refs meta#150 søk og autocomplete mottar rene lister med artikler

parent 833329da
No related branches found
No related tags found
No related merge requests found
...@@ -99,7 +99,7 @@ export default { ...@@ -99,7 +99,7 @@ export default {
return axios.get(self.api_pref + 'suggest?q=' + q).then( return axios.get(self.api_pref + 'suggest?q=' + q).then(
function(response) { function(response) {
let hits = q.length ? [{q: q}] : [] 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) resolve(hits)
}) })
}) })
...@@ -116,19 +116,19 @@ export default { ...@@ -116,19 +116,19 @@ export default {
select_result: function(event) { select_result: function(event) {
this.$refs.search.value = '' this.$refs.search.value = ''
document.activeElement.blur() document.activeElement.blur()
if(event._source){ if(event.body){
this.$router.push('/' + event._index + '/' + event._id) this.$router.push('/' + event._index + '/' + event._id)
this.search_results = [] this.search_results = []
this.article = event._source this.article = event
history.replaceState({article: this.article, search_results: this.search_results, lang: this.lang}, '') history.replaceState({article: this.article, search_results: this.search_results, lang: this.lang}, '')
}else{ }else{
var self = this var self = this
self.waiting = true self.waiting = true
self.article = {lemmas: [], body:{pronunciation: [], definitions: [], etymology: []}} 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){ .then(function(response){
self.$router.push('/' + `/search?q=${event.q}&lang=${self.lang}`) 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 self.waiting = false
history.replaceState({article: self.article, search_results: self.search_results, lang: self.lang}, '') history.replaceState({article: self.article, search_results: self.search_results, lang: self.lang}, '')
}) })
...@@ -160,9 +160,9 @@ export default { ...@@ -160,9 +160,9 @@ export default {
this.lang = this.$route.params.lang || this.$route.query.lang || 'bob,nob' this.lang = this.$route.params.lang || this.$route.query.lang || 'bob,nob'
var self = this; var self = this;
if(this.$route.query.q) { 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){ .then(function(response){
self.search_results = response.data.hits.hits self.search_results = response.data
self.waiting = false self.waiting = false
history.replaceState({article: self.article, search_results: self.search_results, lang: self.lang}, '') history.replaceState({article: self.article, search_results: self.search_results, lang: self.lang}, '')
}) })
......
...@@ -26,13 +26,13 @@ export default { ...@@ -26,13 +26,13 @@ export default {
}, },
computed: { computed: {
previewHeader: function(){ previewHeader: function(){
return this.searchHit.text && this.searchHit.text + " (" + labels[this.searchHit._index] + ")" || return this.searchHit.match && this.searchHit.match + " (" + labels[this.searchHit.dictionary] + ")" ||
(this.searchHit._source && this.searchHit._source.lemmas.map(l => `${l.lemma}`) || []).join(',') || (this.searchHit.lemmas && this.searchHit.lemmas.map(l => `${l.lemma}`) || []).join(',') ||
"Alle søkeresultater..." "Alle søkeresultater..."
}, },
previewText: function(){ previewText: function(){
if (! this.searchHit._source) return '' if (! this.searchHit.body) return ''
let element = this.searchHit._source.body.definitions[0] || '' let element = this.searchHit.body.definitions[0] || ''
while (element.type_ == 'definition') element = element.elements[0] while (element.type_ == 'definition') element = element.elements[0]
if (element.type_ == 'example') { if (element.type_ == 'example') {
element = element.quote element = element.quote
...@@ -40,7 +40,7 @@ export default { ...@@ -40,7 +40,7 @@ export default {
element = {content: '', items: []} element = {content: '', items: []}
} }
let lang = this.searchHit._index let lang = this.searchHit.dictionary
let replacements = element.items.map(item => item.text || let replacements = element.items.map(item => item.text ||
item.string || item.string ||
...@@ -54,7 +54,7 @@ export default { ...@@ -54,7 +54,7 @@ export default {
return element.content.replace(/\$/gi, replacement) return element.content.replace(/\$/gi, replacement)
}, },
group_list: function() { group_list: function() {
return helpers.group_list(this.searchHit._source.lemmas) return helpers.group_list(this.searchHit.lemmas)
} }
}, },
components: { components: {
......
...@@ -33,19 +33,19 @@ export default { ...@@ -33,19 +33,19 @@ export default {
}, },
computed: { computed: {
results_bob: function(){ results_bob: function(){
return this.hits.filter(hit => hit._index == 'bob') return this.hits.filter(hit => hit.dictionary == 'bob')
}, },
results_nob: function(){ results_nob: function(){
return this.hits.filter(hit => hit._index == 'nob') return this.hits.filter(hit => hit.dictionary == 'nob')
}, },
results_norsk: function(){ results_norsk: function(){
return this.hits.filter(hit => hit._index == 'norsk_ordbok') return this.hits.filter(hit => hit.dictionary == 'norsk_ordbok')
} }
}, },
methods: { methods: {
article_link_click: function(result) { article_link_click: function(result) {
this.$router.push('/' + result._index + '/' + result._id) this.$router.push('/' + result.dictionary + '/' + result.article_id)
this.$emit('search-hit-click', result._source) this.$emit('search-hit-click', result)
} }
}, },
components: { components: {
......
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