mirror of
https://github.com/Hopiu/xapian-haystack.git
synced 2026-03-16 22:20:31 +00:00
Removed leftover run and run_mlt methods. Replaced with overriden build_params. This should fix gh-85 and gh-82.
This commit is contained in:
parent
d32dde1b7b
commit
a8453772e5
1 changed files with 8 additions and 57 deletions
|
|
@ -921,6 +921,14 @@ class SearchQuery(BaseSearchQuery):
|
|||
super(SearchQuery, self).__init__(backend=backend)
|
||||
self.backend = backend or SearchBackend(site=site)
|
||||
|
||||
def build_params(self, *args, **kwargs):
|
||||
kwargs = super(SearchQuery, self).build_params(*args, **kwargs)
|
||||
|
||||
if self.end_offset is not None:
|
||||
kwargs['end_offset'] = self.end_offset - self.start_offset
|
||||
|
||||
return kwargs
|
||||
|
||||
def build_query(self):
|
||||
if not self.query_filter:
|
||||
query = xapian.Query('')
|
||||
|
|
@ -1253,60 +1261,3 @@ def _marshal_datetime(dt):
|
|||
dt.year, dt.month, dt.day, dt.hour,
|
||||
dt.minute, dt.second
|
||||
)
|
||||
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
Builds and executes the query. Returns a list of search results.
|
||||
"""
|
||||
final_query = self.build_query()
|
||||
kwargs = {
|
||||
'start_offset': self.start_offset,
|
||||
}
|
||||
|
||||
if self.order_by:
|
||||
kwargs['sort_by'] = self.order_by
|
||||
|
||||
if self.end_offset is not None:
|
||||
kwargs['end_offset'] = self.end_offset - self.start_offset
|
||||
|
||||
if self.highlight:
|
||||
kwargs['highlight'] = self.highlight
|
||||
|
||||
if self.facets:
|
||||
kwargs['facets'] = list(self.facets)
|
||||
|
||||
if self.date_facets:
|
||||
kwargs['date_facets'] = self.date_facets
|
||||
|
||||
if self.query_facets:
|
||||
kwargs['query_facets'] = self.query_facets
|
||||
|
||||
if self.narrow_queries:
|
||||
kwargs['narrow_queries'] = self.narrow_queries
|
||||
|
||||
results = self.backend.search(final_query, **kwargs)
|
||||
self._results = results.get('results', [])
|
||||
self._hit_count = results.get('hits', 0)
|
||||
self._facet_counts = results.get('facets', {})
|
||||
self._spelling_suggestion = results.get('spelling_suggestion', None)
|
||||
|
||||
|
||||
def run_mlt(self):
|
||||
"""
|
||||
Builds and executes the query. Returns a list of search results.
|
||||
"""
|
||||
if self._more_like_this is False or self._mlt_instance is None:
|
||||
raise MoreLikeThisError("No instance was provided to determine 'More Like This' results.")
|
||||
|
||||
additional_query_string = self.build_query()
|
||||
kwargs = {
|
||||
'start_offset': self.start_offset,
|
||||
}
|
||||
|
||||
if self.end_offset is not None:
|
||||
kwargs['end_offset'] = self.end_offset - self.start_offset
|
||||
|
||||
results = self.backend.more_like_this(self._mlt_instance, additional_query_string, **kwargs)
|
||||
self._results = results.get('results', [])
|
||||
self._hit_count = results.get('hits', 0)
|
||||
|
|
|
|||
Loading…
Reference in a new issue