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

refs meta#143 swagger.json + suggest-endpoint i API

parent d1bd1057
No related branches found
No related tags found
No related merge requests found
{
"openapi": "3.0.1",
"info": {
"title": "ordbok-cache",
"version": "2020-02-17T12:44:25Z"
},
"servers": [],
"paths": {
"/article/{dict_id}/{art_id}": {
"get": {
"parameters": [
{
"name": "dict_id",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "art_id",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"security": [
{
"api_key": []
}
]
}
},
"/article/{dict_id}/search": {
"get": {
"parameters": [
{
"name": "dict_id",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "q",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
}
],
"security": [
{
"api_key": []
}
]
}
},
"/article/{dict_id}/suggest": {
"get": {
"parameters": [
{
"name": "dict_id",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "q",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
}
],
"security": [
{
"api_key": []
}
]
}
}
},
"components": {
"schemas": {
"Empty": {
"title": "Empty Schema",
"type": "object"
}
},
"securitySchemes": {
"api_key": {
"type": "apiKey",
"name": "x-api-key",
"in": "header"
}
}
}
}
...@@ -57,7 +57,7 @@ import SearchResults from './components/SearchResults.vue' ...@@ -57,7 +57,7 @@ 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/cache/article' var api_endpoint = 'https://beta.ordbok.uib.no/api/article'
axios.interceptors.request.use(function (config) { axios.interceptors.request.use(function (config) {
config.headers["x-api-key"] = "ZkYiyRVXxH86ijsvhx3cH4SY5Iik2ijI3BKVJGMm" config.headers["x-api-key"] = "ZkYiyRVXxH86ijsvhx3cH4SY5Iik2ijI3BKVJGMm"
...@@ -90,18 +90,8 @@ export default { ...@@ -90,18 +90,8 @@ export default {
let self = this let self = this
return function(q) { return function(q) {
return new Promise(resolve => { return new Promise(resolve => {
return axios.post(api_endpoint + '/' + self.lang + '/_search/', return axios.get(api_endpoint + '/' + self.lang + '/suggest?q=' + q).then(
{ function(response) {
"suggest": {
"suggest" : {
"prefix" : q,
"completion" : {
"field" : "suggest",
"size": 10
}
}
}
}).then(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.suggest.suggest[0].options.sort((o1, o2) => o1.text.length - o2.text.length))
resolve(hits) resolve(hits)
...@@ -129,7 +119,7 @@ export default { ...@@ -129,7 +119,7 @@ export default {
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(api_endpoint + '/' + self.lang + '/_search?q=' + event.q + ' ' + event.q + '*&size=20') axios.get(api_endpoint + '/' + self.lang + '/search?q=' + event.q + ' ' + event.q + '*&size=20')
.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.hits.hits
...@@ -164,7 +154,7 @@ export default { ...@@ -164,7 +154,7 @@ 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(api_endpoint + '/' + self.lang + '/_search?q=' + self.$route.query.q + ' ' + self.$route.query.q + '*&size=20') axios.get(api_endpoint + '/' + self.lang + '/search?q=' + self.$route.query.q + ' ' + self.$route.query.q + '*&size=20')
.then(function(response){ .then(function(response){
self.search_results = response.data.hits.hits self.search_results = response.data.hits.hits
self.waiting = false self.waiting = false
......
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