Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beta.ordbok.uib.no
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Språksamlingane
beta.ordbok.uib.no
Commits
f3fc0138
Commit
f3fc0138
authored
3 years ago
by
Henrik Askjer
Browse files
Options
Downloads
Patches
Plain Diff
Add new suggest API and new solution to autocomplete problem
parent
53dd68b1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/Autocomplete.vue
+22
-39
22 additions, 39 deletions
src/components/Autocomplete.vue
src/components/DictionaryView.vue
+5
-1
5 additions, 1 deletion
src/components/DictionaryView.vue
with
27 additions
and
40 deletions
src/components/Autocomplete.vue
+
22
−
39
View file @
f3fc0138
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
:dense="$vuetify.breakpoint.smAndDown"
:dense="$vuetify.breakpoint.smAndDown"
>
>
<template
v-slot:item=
"data"
>
<template
v-slot:item=
"data"
>
<span
class=
"search-hit"
>
{{
data
.
item
.
label
}}
</span>
(
{{
data
.
item
.
lang
_set
?
Array
.
from
(
data
.
item
.
lang_set
).
sort
().
join
(
'
,
'
)
:
'
fritekstsøk
'
}}
)
<span
class=
"search-hit"
>
{{
data
.
item
.
label
}}
</span>
(
{{
data
.
item
.
lang
?
data
.
item
.
lang
:
'
fritekstsøk
'
}}
)
</
template
>
</
template
>
</v-combobox>
</v-combobox>
</div>
</div>
...
@@ -49,42 +49,26 @@
...
@@ -49,42 +49,26 @@
suggesting
:
null
,
suggesting
:
null
,
debounced
:
debounce
(
function
(
q
,
self
)
{
debounced
:
debounce
(
function
(
q
,
self
)
{
self
.
loading
=
true
self
.
loading
=
true
return
axios
.
get
(
self
.
endpoint
+
'
suggest?q=
'
+
encodeURIComponent
(
q
))
return
axios
.
get
(
self
.
endpoint
+
'
suggest?
'
,
{
params
:
{
q
:
encodeURIComponent
(
q
),
dict
:
this
.
$parent
.
lang
,
n
:
9
}}
)
.
then
(
.
then
(
function
(
response
)
{
function
(
response
)
{
if
(
self
.
suggesting
)
{
if
(
self
.
suggesting
)
{
let
hits
=
[]
let
hits
=
[]
if
(
q
==
self
.
$refs
.
autocomplete
.
searchInput
)
{
response
.
data
.
forEach
((
item
,
i
)
=>
{
response
.
data
.
forEach
((
item
,
i
)
=>
{
let
hit
=
{
q
:
q
,
word
:
encodeURIComponent
(
item
[
0
]),
label
:
item
[
0
]}
let
match
=
encodeURIComponent
(
item
.
match
)
hit
.
lang
=
item
[
1
][
1
]
?
"
bm, nn
"
:
{
"
bob
"
:
"
bm
"
,
"
nob
"
:
"
nn
"
}[
item
[
1
][
0
]]
hits
.
push
(
hit
)
if
(
!
hits
[
0
]
||
hits
[
0
].
word
!=
match
)
{
});
hits
.
splice
(
0
,
0
,
{
q
:
encodeURIComponent
(
q
),
lang_set
:
new
Set
(),
word
:
match
,
articles
:
[]})
}
hits
[
0
].
lang_set
.
add
(
item
.
dictionary
==
'
bob
'
?
'
bm
'
:
'
nn
'
)
hits
[
0
].
articles
.
push
(
item
)
});
hits
.
forEach
(
function
(
hit
)
{
if
(
hit
.
lang_set
)
{
hit
.
label
=
decodeURIComponent
(
hit
.
word
)
}
});
hits
.
reverse
()
hits
=
hits
.
slice
(
0
,
9
)
hits
.
sort
(
(
h1
,
h2
)
=>
{
self
.
items
=
hits
let
val1
=
h1
.
label
.
length
*
10
+
(
h1
.
label
[
0
].
toLowerCase
()
===
h1
.
label
[
0
]
?
0
:
1
)
let
val2
=
h2
.
label
.
length
*
10
+
(
h2
.
label
[
0
].
toLowerCase
()
===
h2
.
label
[
0
]
?
0
:
1
)
let
currentSearch
=
self
.
$refs
.
autocomplete
.
searchInput
return
val1
-
val2
self
.
items
.
push
({
currentSearch
:
encodeURIComponent
(
currentSearch
),
label
:
currentSearch
+
'
'
})
})
let
currentSearch
=
self
.
$refs
.
autocomplete
.
searchInput
if
(
q
==
currentSearch
)
{
self
.
items
=
hits
}
self
.
items
.
push
({
currentSearch
:
encodeURIComponent
(
currentSearch
),
label
:
currentSearch
+
'
'
})
}
}
}
self
.
loading
=
false
self
.
loading
=
false
})
})
...
@@ -101,21 +85,20 @@
...
@@ -101,21 +85,20 @@
},
},
select
(
item
)
{
select
(
item
)
{
if
(
item
)
{
if
(
item
)
{
if
(
typeof
item
===
'
string
'
)
{
if
(
item
.
q
===
self
.
$refs
.
autocomplete
.
searchInput
)
{
item
=
{
"
q
"
:
encodeURIComponent
(
item
)}
this
.
items
=
[]
}
this
.
suggesting
=
false
this
.
items
=
[]
this
.
suggesting
=
false
this
.
$emit
(
'
submit
'
,
item
)
this
.
$emit
(
'
submit
'
,
item
)
let
self
=
this
let
self
=
this
setTimeout
(()
=>
self
.
$refs
.
autocomplete
.
$refs
.
input
.
select
(),
1
)
setTimeout
(()
=>
self
.
$refs
.
autocomplete
.
$refs
.
input
.
select
(),
1
)
}
}
}
}
}
},
},
methods
:
{
methods
:
{
run_query
(
q
)
{
run_query
(
q
)
{
this
.
items
=
[]
this
.
suggesting
=
true
this
.
suggesting
=
true
this
.
debounced
(
q
,
this
)
this
.
debounced
(
q
,
this
)
}
}
...
...
This diff is collapsed.
Click to expand it.
src/components/DictionaryView.vue
+
5
−
1
View file @
f3fc0138
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
</v-radio>
</v-radio>
</v-radio-group>
</v-radio-group>
</div>
</div>
<Autocomplete
@
submit=
"select_result"
:endpoint=
"
api_pref
"
>
<Autocomplete
@
submit=
"select_result"
:endpoint=
"
oda_endpoint
"
>
</Autocomplete>
</Autocomplete>
</div>
</div>
<div
id=
"spinner"
v-if=
"waiting"
>
<div
id=
"spinner"
v-if=
"waiting"
>
...
@@ -74,6 +74,7 @@ import SearchResults from './SearchResults.vue'
...
@@ -74,6 +74,7 @@ import SearchResults from './SearchResults.vue'
import
Autocomplete
from
'
./Autocomplete.vue
'
import
Autocomplete
from
'
./Autocomplete.vue
'
var
api_endpoint
=
process
.
env
.
VUE_APP_API_PREFIX
+
'
/api/dict
'
var
api_endpoint
=
process
.
env
.
VUE_APP_API_PREFIX
+
'
/api/dict
'
const
oda_endpoint
=
'
https://oda.uib.no/opal-api/
'
function
compare_by_hgno
(
lemma_text
)
{
function
compare_by_hgno
(
lemma_text
)
{
return
function
(
art1
,
art2
)
{
return
function
(
art1
,
art2
)
{
...
@@ -188,6 +189,9 @@ export default {
...
@@ -188,6 +189,9 @@ export default {
},
},
api_pref
:
function
()
{
api_pref
:
function
()
{
return
api_endpoint
+
'
/
'
+
this
.
lang
+
'
/article/
'
return
api_endpoint
+
'
/
'
+
this
.
lang
+
'
/article/
'
},
oda_endpoint
:
function
()
{
return
oda_endpoint
}
}
},
},
components
:
{
components
:
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment