Skip to content
Snippets Groups Projects
Commit c8921237 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Merge branch '81-search-unaccent' into 'develop'

Fixed #81: Search now unaccent letters for queries

Closes #81

See merge request funkwhale/funkwhale!66
parents 9b0d5541 62d0381f
No related branches found
No related tags found
No related merge requests found
......@@ -37,6 +37,7 @@ DJANGO_APPS = (
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.postgres',
# Useful template tags:
# 'django.contrib.humanize',
......
# Generated by Django 2.0.2 on 2018-02-27 18:43
from django.db import migrations
from django.contrib.postgres.operations import UnaccentExtension
class Migration(migrations.Migration):
dependencies = []
operations = [
UnaccentExtension()
]
......@@ -63,7 +63,7 @@ class ArtistViewSet(SearchMixin, viewsets.ReadOnlyModelViewSet):
'albums__tracks__tags'))
serializer_class = serializers.ArtistSerializerNested
permission_classes = [ConditionalAuthentication]
search_fields = ['name']
search_fields = ['name__unaccent']
filter_class = filters.ArtistFilter
ordering_fields = ('id', 'name', 'creation_date')
......@@ -76,7 +76,7 @@ class AlbumViewSet(SearchMixin, viewsets.ReadOnlyModelViewSet):
'tracks__files'))
serializer_class = serializers.AlbumSerializerNested
permission_classes = [ConditionalAuthentication]
search_fields = ['title']
search_fields = ['title__unaccent']
ordering_fields = ('creation_date',)
......@@ -133,9 +133,9 @@ class TrackViewSet(TagViewSetMixin, SearchMixin, viewsets.ReadOnlyModelViewSet):
search_fields = ['title', 'artist__name']
ordering_fields = (
'creation_date',
'title',
'album__title',
'artist__name',
'title__unaccent',
'album__title__unaccent',
'artist__name__unaccent',
)
def get_queryset(self):
......@@ -249,7 +249,11 @@ class Search(views.APIView):
return Response(results, status=200)
def get_tracks(self, query):
search_fields = ['mbid', 'title', 'album__title', 'artist__name']
search_fields = [
'mbid',
'title__unaccent',
'album__title__unaccent',
'artist__name__unaccent']
query_obj = utils.get_query(query, search_fields)
return (
models.Track.objects.all()
......@@ -263,7 +267,10 @@ class Search(views.APIView):
def get_albums(self, query):
search_fields = ['mbid', 'title', 'artist__name']
search_fields = [
'mbid',
'title__unaccent',
'artist__name__unaccent']
query_obj = utils.get_query(query, search_fields)
return (
models.Album.objects.all()
......@@ -277,7 +284,7 @@ class Search(views.APIView):
def get_artists(self, query):
search_fields = ['mbid', 'name']
search_fields = ['mbid', 'name__unaccent']
query_obj = utils.get_query(query, search_fields)
return (
models.Artist.objects.all()
......@@ -292,7 +299,7 @@ class Search(views.APIView):
def get_tags(self, query):
search_fields = ['slug', 'name']
search_fields = ['slug', 'name__unaccent']
query_obj = utils.get_query(query, search_fields)
# We want the shortest tag first
......
Search now unaccent letters for queries like "The Dø" or "Björk", yielding more results (#81)
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