Skip to content
Snippets Groups Projects
Commit 3355e890 authored by Henrik Askjer's avatar Henrik Askjer
Browse files

Fetch inflections and similar when submitting search

parent 5e031509
No related branches found
No related tags found
No related merge requests found
......@@ -94,8 +94,6 @@
return {
loading: false,
items: [],
inflection_suggestions: null,
similar: null,
search: null,
select: this.$route.query? this.$route.query.q : null,
suggesting: null,
......@@ -116,8 +114,6 @@
if (typeof item != 'string') {
this.items = []
this.suggesting = false
item.inflection_suggestions = this.inflection_suggestions
item.similar = this.similar
this.submit(item)
......@@ -159,16 +155,16 @@
this.suggesting = true
if (!/[_*%|]/.test(q)) {
let self = this
let params = {q, dict: self.get_lang(), n: 6, dform: 'int', meta: 'n', include: "eis", wc: self.$parent.pos_selected}
let params = {q, dict: self.get_lang(), n: 6, dform: 'int', meta: 'n', include: "e", wc: self.$parent.pos_selected}
self.api.get('suggest?', {params})
.then(async (response) => {
if (self.$refs.autocomplete.searchInput == q & self.suggesting) {
console.log(response)
let suggestions = []
if (response.data.a.exact) {
suggestions = response.data.a.exact.map(item => ({q: q, match: item[0], time: time, lang: [item[1]], w: true}))
}
self.inflection_suggestions = response.data.a.inflect
self.similar = response.data.a.similar
if (suggestions.length) {
if (suggestions[0].q != suggestions[0].match) {
suggestions.unshift({q, match: q, time})
......@@ -185,8 +181,6 @@
}
else {
this.similar = []
this.inflection_suggestions = []
this.items = [{q, match: q, time}]
}
......
......@@ -130,7 +130,6 @@ function navigate_to_article(self, origin) {
self.error = null
})
.catch(function(error){
console.log(error)
self.handle_error(error, true)
})
.then(function(response){
......@@ -172,7 +171,6 @@ function load_articles(self, query, offset, n, dict) {
self.search_results[dict] = results
})
.catch(error => {
self.waiting_for_articles = false
self.handle_error(error)
})
}
......@@ -184,6 +182,7 @@ function load_articles(self, query, offset, n, dict) {
}
function navigate_to_query(self, word) {
self.error = null
self.waiting_for_articles = true
......@@ -191,8 +190,20 @@ function navigate_to_query(self, word) {
self.event = {match: word}
}
let query = self.event
self.inflection_suggestions = (self.event && query.inflection_suggestions) || []
let q = query.match
// Get inflections
if (!/[_*%|]/.test(q)) {
console.log("ARTICLE INFO", self.article_info)
let params = {q, dict: self.lang, include: "i", meta: 'n', wc: self.pos_selected}
api.get('suggest?', {params})
.then((response) => {
self.inflection_suggestions = response.data.a.inflect
}).catch(error =>{
self.handle_error(error)
self.replace_history()
})
}
// Get article IDs
let params = {w: query.match, dict: self.lang, scope: self.scope, meta: 'y'}
......@@ -218,7 +229,21 @@ function navigate_to_query(self, word) {
else {
self.similar = []
}
// Similar
if (bm_length == 0 || nn_length == 0) {
if (!/[_*%|]/.test(q)) {
console.log("ARTICLE INFO", self.article_info)
let dict = self.lang
if (dict == 'bm,nn') {
dict = bm_length == 0? 'bm' : 'nn'
}
let params = {q, dict, include: "s", wc: self.pos_selected}
api.get('suggest?', {params})
.then((response) => { self.similar = response.data.a.similar})
}
}
if (bm_length + nn_length == 0) {
self.similar = (self.event && query.similar) || []
......@@ -235,29 +260,6 @@ function navigate_to_query(self, word) {
load_articles(self, query, offset, self.perPage, "nn")
])
.then(() => {
// Show inflection suggestions if they are not among the first results
/*
if (self.event && self.event.inflection_suggestions) {
self.inflection_suggestions = self.event.inflection_suggestions.filter((item) => {
if ((item[1] == 1 || item[1] == 3) && self.search_results.bm) {
if (!self.search_results.bm[0]) {
console.log("SUGGEST ERROR: no bm results")
}
else return !self.search_results.bm[0].suggest.includes(item[0])
}
if ((item[1] == 2 || item[1] == 3) && self.search_results.nn) {
if (!self.search_results.nn[0]) {
console.log("SUGGEST ERROR: no nn results")
}
else return !self.search_results.nn[0].suggest.includes(item[0])
}
})
} else {
self.inflection_suggestions = []
}
*/
self.waiting_for_articles = false
self.$store.commit('setSearchRoute', self.$route.fullPath)
......@@ -265,8 +267,6 @@ function navigate_to_query(self, word) {
})
}
}).catch(error =>{
self.waiting_for_articles = false
console.log(error)
self.handle_error(error)
self.replace_history()
})
......@@ -287,7 +287,7 @@ export default {
monthly_bm: null,
monthly_nn: null,
event: null,
scope: "wb",
scope: "ei",
pos_selected: "ALL",
article_info: null,
page: 1,
......@@ -355,6 +355,7 @@ export default {
})
},
handle_error: function(error, article) {
this.waiting_for_articles = false
this.search_results = {}
console.log(error)
if (error.message == "Network Error") {
......
......@@ -116,17 +116,13 @@ export default {
return ["NOUN", "PRON","DET","ADJ","CCONJ","SCONJ", "ADV", "VERB", "INTJ"].map(text =>{
return {text: this.$t("pos." + text ), value: text}
})
},
scope_items: function() {
return ["w", "wb", "b", "wxb"].map(text => {
return {text: this.$t("scope." + text), value: text}
})
}
},
methods: {
reset (pos) {
this.$emit('updatePos', "ALL")
this.$emit('updateScope', "wb")
this.$emit('updateScope', "ei")
},
updatePos (pos) {
this.$emit('updatePos', pos)
......
......@@ -69,12 +69,6 @@
"VERB": "verb",
"INTJ": "interjeksjoner"
},
"scope": {
"w": "oppslagsord",
"wb": "oppslagsord og bøygde former",
"b": "bøygde former",
"wxb": "fulltekst"
},
"error": {
"404": {
"title": "404: Ikke funnet",
......
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