Return a flat image array when semantic search is activated Don't unload semantic search, when it's activated. Extract class for search logic Add some logging to the whole process Sort by relevancypull/413/head
parent
64a5a860ae
commit
8612a77eee
@ -0,0 +1,47 @@
|
||||
from django.db.models import Q
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.response import Response
|
||||
|
||||
from api.filters import SemanticSearchFilter
|
||||
from api.models import Photo
|
||||
from api.views.pagination import HugeResultsSetPagination
|
||||
from api.views.PhotosGroupedByDate import get_photos_ordered_by_date
|
||||
from api.views.serializers_serpy import GroupedPhotosSerializer, PigPhotoSerilizer
|
||||
|
||||
|
||||
class SearchListViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = GroupedPhotosSerializer
|
||||
pagination_class = HugeResultsSetPagination
|
||||
filter_backends = (SemanticSearchFilter,)
|
||||
search_fields = [
|
||||
"search_captions",
|
||||
"search_location",
|
||||
"faces__person__name",
|
||||
"exif_timestamp",
|
||||
"image_paths",
|
||||
]
|
||||
|
||||
def get_queryset(self):
|
||||
return Photo.visible.filter(Q(owner=self.request.user)).order_by(
|
||||
"-exif_timestamp"
|
||||
)
|
||||
|
||||
def retrieve(self, *args, **kwargs):
|
||||
return super(SearchListViewSet, self).retrieve(*args, **kwargs)
|
||||
|
||||
def list(self, request):
|
||||
if request.user.semantic_search_topk == 0:
|
||||
queryset = self.filter_queryset(
|
||||
Photo.visible.filter(Q(owner=self.request.user)).order_by(
|
||||
"-exif_timestamp"
|
||||
)
|
||||
)
|
||||
grouped_photos = get_photos_ordered_by_date(queryset)
|
||||
serializer = GroupedPhotosSerializer(grouped_photos, many=True)
|
||||
return Response({"results": serializer.data})
|
||||
else:
|
||||
queryset = self.filter_queryset(
|
||||
Photo.visible.filter(Q(owner=self.request.user))
|
||||
)
|
||||
serializer = PigPhotoSerilizer(queryset, many=True)
|
||||
return Response({"results": serializer.data})
|
Loading…
Reference in new issue