kopia lustrzana https://github.com/wagtail/wagtail
				
				
				
			Ensured BaseSearchBackend.search method always return BaseSearchResults subclasses
							rodzic
							
								
									2b09cdaef2
								
							
						
					
					
						commit
						0cb16f2a01
					
				| 
						 | 
				
			
			@ -3,12 +3,9 @@ from __future__ import absolute_import, unicode_literals
 | 
			
		|||
from collections import OrderedDict
 | 
			
		||||
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from django.db.models.query import QuerySet
 | 
			
		||||
from rest_framework.pagination import BasePagination
 | 
			
		||||
from rest_framework.response import Response
 | 
			
		||||
 | 
			
		||||
from wagtail.wagtailsearch.backends.base import BaseSearchResults
 | 
			
		||||
 | 
			
		||||
from .utils import BadRequestError
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -36,7 +33,7 @@ class WagtailPagination(BasePagination):
 | 
			
		|||
        stop = offset + limit
 | 
			
		||||
 | 
			
		||||
        self.view = view
 | 
			
		||||
        self.total_count = queryset.count() if isinstance(queryset, (BaseSearchResults, QuerySet)) else len(queryset)
 | 
			
		||||
        self.total_count = queryset.count()
 | 
			
		||||
        return queryset[start:stop]
 | 
			
		||||
 | 
			
		||||
    def get_paginated_response(self, data):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,12 +3,9 @@ from __future__ import absolute_import, unicode_literals
 | 
			
		|||
from collections import OrderedDict
 | 
			
		||||
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from django.db.models.query import QuerySet
 | 
			
		||||
from rest_framework.pagination import BasePagination
 | 
			
		||||
from rest_framework.response import Response
 | 
			
		||||
 | 
			
		||||
from wagtail.wagtailsearch.backends.base import BaseSearchResults
 | 
			
		||||
 | 
			
		||||
from .utils import BadRequestError
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -36,7 +33,7 @@ class WagtailPagination(BasePagination):
 | 
			
		|||
        stop = offset + limit
 | 
			
		||||
 | 
			
		||||
        self.view = view
 | 
			
		||||
        self.total_count = queryset.count() if isinstance(queryset, (BaseSearchResults, QuerySet)) else len(queryset)
 | 
			
		||||
        self.total_count = queryset.count()
 | 
			
		||||
        return queryset[start:stop]
 | 
			
		||||
 | 
			
		||||
    def get_paginated_response(self, data):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -186,6 +186,20 @@ class BaseSearchResults(object):
 | 
			
		|||
        return clone
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class EmptySearchResults(BaseSearchResults):
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
        return super(EmptySearchResults, self).__init__(None, None)
 | 
			
		||||
 | 
			
		||||
    def _clone(self):
 | 
			
		||||
        return self.__class__()
 | 
			
		||||
 | 
			
		||||
    def _do_search(self):
 | 
			
		||||
        return []
 | 
			
		||||
 | 
			
		||||
    def _do_count(self):
 | 
			
		||||
        return 0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class BaseSearchBackend(object):
 | 
			
		||||
    query_class = None
 | 
			
		||||
    results_class = None
 | 
			
		||||
| 
						 | 
				
			
			@ -230,11 +244,11 @@ class BaseSearchBackend(object):
 | 
			
		|||
 | 
			
		||||
        # Model must be a class that is in the index
 | 
			
		||||
        if not class_is_indexed(model):
 | 
			
		||||
            return []
 | 
			
		||||
            return EmptySearchResults()
 | 
			
		||||
 | 
			
		||||
        # Check that theres still a query string after the clean up
 | 
			
		||||
        if query_string == "":
 | 
			
		||||
            return []
 | 
			
		||||
            return EmptySearchResults()
 | 
			
		||||
 | 
			
		||||
        # Only fields that are indexed as a SearchField can be passed in fields
 | 
			
		||||
        if fields:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue