Exemple #1
0
    def get(self, request, identifier, format=None):
        related, result_count = search_controller.related_images(
            uuid=identifier, index='image', request=request, filter_dead=True)

        context = {'request': request}
        serialized_related = ImageSerializer(related,
                                             many=True,
                                             context=context).data
        response_data = {
            RESULT_COUNT: result_count,
            PAGE_COUNT: 0,
            RESULTS: serialized_related
        }
        serialized_response = ImageSearchResultsSerializer(data=response_data)
        return Response(status=200, data=serialized_response.initial_data)
Exemple #2
0
    def get(self, request, format=None):
        # Parse and validate query parameters
        params = ImageSearchQueryStringSerializer(data=request.query_params)
        if not params.is_valid():
            return input_error_response(params.errors)

        hashed_ip = hash(_get_user_ip(request))
        page_param = params.data[PAGE]
        page_size = params.data[PAGESIZE]
        qa = params.data[QA]
        filter_dead = params.data[FILTER_DEAD]

        search_index = 'search-qa' if qa else 'image'
        try:
            results, page_count, result_count = search_controller.search(
                params,
                search_index,
                page_size,
                hashed_ip,
                request,
                filter_dead,
                page=page_param
            )
        except ValueError as value_error:
            return input_error_response(str(value_error))

        context = {'request': request}
        serialized_results = ImageSerializer(
            results, many=True, context=context
        ).data

        if len(results) < page_size and page_count == 0:
            result_count = len(results)
        response_data = {
            RESULT_COUNT: result_count,
            PAGE_COUNT: page_count,
            PAGE_SIZE: len(results),
            RESULTS: serialized_results
        }
        serialized_response = ImageSearchResultsSerializer(data=response_data)
        return Response(status=200, data=serialized_response.initial_data)