Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mélanie Chauvel
funkwhale
Commits
89f6e365
Verified
Commit
89f6e365
authored
6 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Show short entries first in search results to improve UX
parent
567884b7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/funkwhale_api/common/utils.py
+9
-1
9 additions, 1 deletion
api/funkwhale_api/common/utils.py
api/funkwhale_api/music/views.py
+9
-8
9 additions, 8 deletions
api/funkwhale_api/music/views.py
changes/changelog.d/searchorder.enhancement
+1
-0
1 addition, 0 deletions
changes/changelog.d/searchorder.enhancement
with
19 additions
and
9 deletions
api/funkwhale_api/common/utils.py
+
9
−
1
View file @
89f6e365
...
...
@@ -9,7 +9,7 @@ from urllib.parse import parse_qs, urlencode, urlsplit, urlunsplit
from
django.conf
import
settings
from
django
import
urls
from
django.db
import
transaction
from
django.db
import
models
,
transaction
def
rename_file
(
instance
,
field_name
,
new_name
,
allow_missing_file
=
False
):
...
...
@@ -139,3 +139,11 @@ def parse_meta(html):
meta
=
[
elem
for
elem
in
tree
.
iter
()
if
elem
.
tag
in
[
"
meta
"
,
"
link
"
]]
return
[
dict
([(
"
tag
"
,
elem
.
tag
)]
+
list
(
elem
.
items
()))
for
elem
in
meta
]
def
order_for_search
(
qs
,
field
):
"""
When searching, it
'
s often more useful to have short results first,
this function will order the given qs based on the length of the given field
"""
return
qs
.
annotate
(
__size
=
models
.
functions
.
Length
(
field
)).
order_by
(
"
__size
"
)
This diff is collapsed.
Click to expand it.
api/funkwhale_api/music/views.py
+
9
−
8
View file @
89f6e365
...
...
@@ -448,28 +448,29 @@ class Search(views.APIView):
"
artist__name__unaccent
"
,
]
query_obj
=
utils
.
get_query
(
query
,
search_fields
)
return
(
qs
=
(
models
.
Track
.
objects
.
all
()
.
filter
(
query_obj
)
.
select_related
(
"
artist
"
,
"
album__artist
"
)
)[:
self
.
max_results
]
)
return
common_utils
.
order_for_search
(
qs
,
"
title
"
)[:
self
.
max_results
]
def
get_albums
(
self
,
query
):
search_fields
=
[
"
mbid
"
,
"
title__unaccent
"
,
"
artist__name__unaccent
"
]
query_obj
=
utils
.
get_query
(
query
,
search_fields
)
return
(
qs
=
(
models
.
Album
.
objects
.
all
()
.
filter
(
query_obj
)
.
select_related
()
.
prefetch_related
(
"
tracks
"
)
)[:
self
.
max_results
]
.
prefetch_related
(
"
tracks__artist
"
)
)
return
common_utils
.
order_for_search
(
qs
,
"
title
"
)[:
self
.
max_results
]
def
get_artists
(
self
,
query
):
search_fields
=
[
"
mbid
"
,
"
name__unaccent
"
]
query_obj
=
utils
.
get_query
(
query
,
search_fields
)
return
(
models
.
Artist
.
objects
.
all
().
filter
(
query_obj
).
with_albums
())[
:
self
.
max_results
]
qs
=
models
.
Artist
.
objects
.
all
().
filter
(
query_obj
).
with_albums
()
return
common_utils
.
order_for_search
(
qs
,
"
name
"
)[:
self
.
max_results
]
def
get_tags
(
self
,
query
):
search_fields
=
[
"
slug
"
,
"
name__unaccent
"
]
...
...
This diff is collapsed.
Click to expand it.
changes/changelog.d/searchorder.enhancement
0 → 100644
+
1
−
0
View file @
89f6e365
Show short entries first in search results to improve UX
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