mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-26 07:43:44 +00:00
Replace backend _search methods with search_x_class attributes
This commit is contained in:
parent
e3154fa06f
commit
3449139e76
3 changed files with 11 additions and 10 deletions
|
|
@ -173,6 +173,9 @@ class BaseSearchResults(object):
|
|||
|
||||
|
||||
class BaseSearch(object):
|
||||
search_query_class = None
|
||||
search_results_class = None
|
||||
|
||||
def __init__(self, params):
|
||||
pass
|
||||
|
||||
|
|
@ -197,9 +200,6 @@ class BaseSearch(object):
|
|||
def delete(self, obj):
|
||||
raise NotImplementedError
|
||||
|
||||
def _search(self, queryset, query_string, fields=None):
|
||||
raise NotImplementedError
|
||||
|
||||
def search(self, query_string, model_or_queryset, fields=None, filters=None, prefetch_related=None):
|
||||
# Find model/queryset
|
||||
if isinstance(model_or_queryset, QuerySet):
|
||||
|
|
@ -227,4 +227,5 @@ class BaseSearch(object):
|
|||
queryset = queryset.prefetch_related(prefetch)
|
||||
|
||||
# Search
|
||||
return self._search(queryset, query_string, fields=fields)
|
||||
search_query = self.search_query_class(queryset, query_string, fields=fields)
|
||||
return self.search_results_class(self, search_query)
|
||||
|
|
|
|||
|
|
@ -72,6 +72,9 @@ class DBSearchResults(BaseSearchResults):
|
|||
|
||||
|
||||
class DBSearch(BaseSearch):
|
||||
search_query_class = DBSearchQuery
|
||||
search_results_class = DBSearchResults
|
||||
|
||||
def __init__(self, params):
|
||||
super(DBSearch, self).__init__(params)
|
||||
|
||||
|
|
@ -93,8 +96,5 @@ class DBSearch(BaseSearch):
|
|||
def delete(self, obj):
|
||||
pass # Not needed
|
||||
|
||||
def _search(self, queryset, query_string, fields=None):
|
||||
return DBSearchResults(self, DBSearchQuery(queryset, query_string, fields=fields))
|
||||
|
||||
|
||||
SearchBackend = DBSearch
|
||||
|
|
|
|||
|
|
@ -467,6 +467,9 @@ class ElasticSearchAtomicIndexRebuilder(ElasticSearchIndexRebuilder):
|
|||
|
||||
|
||||
class ElasticSearch(BaseSearch):
|
||||
search_query_class = ElasticSearchQuery
|
||||
search_results_class = ElasticSearchResults
|
||||
|
||||
def __init__(self, params):
|
||||
super(ElasticSearch, self).__init__(params)
|
||||
|
||||
|
|
@ -579,8 +582,5 @@ class ElasticSearch(BaseSearch):
|
|||
except NotFoundError:
|
||||
pass # Document doesn't exist, ignore this exception
|
||||
|
||||
def _search(self, queryset, query_string, fields=None):
|
||||
return ElasticSearchResults(self, ElasticSearchQuery(queryset, query_string, fields=fields))
|
||||
|
||||
|
||||
SearchBackend = ElasticSearch
|
||||
|
|
|
|||
Loading…
Reference in a new issue