From 8845fd9ea21756984dd3d72fed21e3d06a786873 Mon Sep 17 00:00:00 2001 From: Henrik Askjer <henrik.askjer@uib.no> Date: Mon, 20 Dec 2021 10:54:44 +0100 Subject: [PATCH] add inflection suggestions --- src/components/Autocomplete.vue | 7 ++-- src/components/DictionaryView.vue | 58 ++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/src/components/Autocomplete.vue b/src/components/Autocomplete.vue index 743eed3c..7f83bb43 100644 --- a/src/components/Autocomplete.vue +++ b/src/components/Autocomplete.vue @@ -85,6 +85,7 @@ import Menu from './Menu.vue' return { loading: false, items: [], + inflected_suggestions: [], search: null, select: this.$route.query? this.$route.query.q : null, suggesting: null, @@ -104,8 +105,9 @@ import Menu from './Menu.vue' if (item) { this.items = [] this.suggesting = false - console.log("ITEM", item) - console.log("INFLECTED", this.inflected_suggestions) + if (this.inflected_suggestions.length) { + item.inflected_suggestions = this.inflected_suggestions + } this.submit(item) @@ -141,6 +143,7 @@ import Menu from './Menu.vue' if (self.$refs.autocomplete.searchInput == q & self.suggesting) { let suggestions = [] suggestions = response.data.a.w.map(item => ({q: q, match: item[0], time: time, lang: [item[1]], w: true})) + self.inflected_suggestions = response.data.a.b if (suggestions.length) { if (suggestions[0].q != suggestions[0].match) { suggestions.unshift({q, match: q, time}) diff --git a/src/components/DictionaryView.vue b/src/components/DictionaryView.vue index 998db118..5f4c9619 100644 --- a/src/components/DictionaryView.vue +++ b/src/components/DictionaryView.vue @@ -6,6 +6,21 @@ <SearchToolbar v-if="$store.state.showSearchToolbar" @updatePos="update_pos" @updateScope="update_scope"/> </div> + <div id="above_results"> + <div id="suggestions" v-if="inflected_suggestions && ! article">Se også <em>{{$route.query.q}}</em> som bøyd form av + <span v-for="(item,index) in inflected_suggestions" :key="index"><router-link :to="generate_path(item[0])" @click.native="navigate_test">{{item[0]}}</router-link>{{index == inflected_suggestions.length? '.' : ', '}}</span> + </div> + + <div class="return_to_results" v-if="total_results && article"> + <router-link v-if="article.source" :to="article.source" @click.native="return_to_results()"> + <v-icon left class="nav_arrow">chevron_left</v-icon>{{$t("back_to_results")}} + </router-link> + <a v-if="!article.source" href="/"> + <v-icon left class="nav_arrow">chevron_left</v-icon>Søk etter andre ord + </a> + </div> + + </div> <SearchResults :results_bm="search_results.bm || []" :results_nn="search_results.nn || []" @@ -18,14 +33,7 @@ <v-progress-circular indeterminate color="secondary" size="120"></v-progress-circular> </div> <div id="single_article_container" v-if="article"> - <div class="return_to_results" v-if="total_results"> - <router-link v-if="article.source" :to="article.source" @click.native="return_to_results()"> - <v-icon left class="nav_arrow">chevron_left</v-icon>{{$t("back_to_results")}} - </router-link> - <a v-if="!article.source" href="/"> - <v-icon left class="nav_arrow">chevron_left</v-icon>Søk etter andre ord - </a> - </div> + <Article :key="article_key" :article="article" @article-click="article_link_click" /> @@ -244,6 +252,26 @@ export default { }, get_search_endpoint: function() { return api + }, + inflected_suggestions: function() { + let suggestions = [] + if (this.event && this.event.inflected_suggestions) { + suggestions = this.event.inflected_suggestions.filter((item) => { + if ((item[1] == 1 || item[1] == 3) && this.search_results.bm) { + return !this.search_results.bm[0].suggest.includes(item[0]) + } + if ((item[1] == 2 || item[1] == 3) && this.search_results.nn) { + return !this.search_results.nn[0].suggest.includes(item[0]) + } + return true + + }) + + + + console.log("MODIFIED",suggestions) + return suggestions + } } }, components: { @@ -346,6 +374,20 @@ export default { + }, + + generate_path: function(q) { + if (q) { + let path = `/${this.lang}/search?q=${q}` + let pos = this.pos_param() + if (pos != 'all') path += "&pos=" + pos + if (this.scope) path += "&scope=" + this.scope + return path + } + }, + navigate_test: function() { + let q = (this.$route.query || this.$route.params).q + navigate_to_query(this, q) }, reload_params: function() { -- GitLab