Skip to content

Commit

Permalink
drop _old_xapian_sort
Browse files Browse the repository at this point in the history
  • Loading branch information
asedeno authored and claudep committed Sep 26, 2021
1 parent 4a952bb commit ef1dc87
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions xapian_backend.py
Expand Up @@ -27,13 +27,6 @@
"Please refer to the documentation.")


class NotSupportedError(Exception):
"""
When the installed version of Xapian doesn't support something and we have
the old implementation.
"""
pass

# this maps the different reserved fields to prefixes used to
# create the database:
# id str: unique document id.
Expand Down Expand Up @@ -644,10 +637,7 @@ def search(self, query, sort_by=None, start_offset=0, end_offset=None,
enquire.set_query(query)

if sort_by:
try:
_xapian_sort(enquire, sort_by, self.column)
except NotSupportedError:
_old_xapian_sort(enquire, sort_by, self.column)
_xapian_sort(enquire, sort_by, self.column)

results = []
facets_dict = {
Expand Down Expand Up @@ -1647,25 +1637,8 @@ def _from_xapian_value(value, field_type):
return value


def _old_xapian_sort(enquire, sort_by, column):
sorter = xapian.MultiValueSorter()

for sort_field in sort_by:
if sort_field.startswith('-'):
reverse = True
sort_field = sort_field[1:] # Strip the '-'
else:
reverse = False # Reverse is inverted in Xapian -- http://trac.xapian.org/ticket/311
sorter.add(column[sort_field], reverse)

enquire.set_sort_by_key_then_relevance(sorter, True)


def _xapian_sort(enquire, sort_by, column):
try:
sorter = xapian.MultiValueKeyMaker()
except AttributeError:
raise NotSupportedError
sorter = xapian.MultiValueKeyMaker()

for sort_field in sort_by:
if sort_field.startswith('-'):
Expand Down

0 comments on commit ef1dc87

Please sign in to comment.