Skip to content

FacetedSearch does not accept sort configuration #1318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tptlab opened this issue Feb 22, 2020 · 1 comment · Fixed by #1773
Closed

FacetedSearch does not accept sort configuration #1318

tptlab opened this issue Feb 22, 2020 · 1 comment · Fixed by #1773
Labels
Category: Bug Something isn't right

Comments

@tptlab
Copy link

tptlab commented Feb 22, 2020

  • ElasticSearch: 7.5.2 on Ubuntu
  • Python: 3.8.1
  • elasticsearch-dsl: 7.1.0

The document says FaucetedSearch accept configuration option sort as a class attribute.

sort
tuple or list of fields on which the results should be sorted.

So I tried to create the following class.

class BlogSearch(FacetedSearch):
    index = 'blogs'

    doc_types = [Blog, Post]
    fields = ['title', 'content']

    sort = ('-published_at',)

    def search(self):
        s = super().search()
        return s.filter('term', published=True)

Then it raises TypeError.

>>> BlogSearch().execute()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "***/site-packages/elasticsearch_dsl/faceted_search.py", line 271, in __init__
	self._s = self.build_search()
File "***/site-packages/elasticsearch_dsl/faceted_search.py", line 381, in build_search
	s = self.sort(s)
TypeError: 'tuple' object is not callable

I tried sort = '-publisehd_at' but got the same error. What kind of argument should be set?

BlogSearch(sort=('-published_at',)) works fine, but I'd like to set the default sort order.

@miguelgrinberg miguelgrinberg added the Category: Bug Something isn't right label Mar 25, 2024
miguelgrinberg added a commit to miguelgrinberg/elasticsearch-dsl-py that referenced this issue Apr 10, 2024
@miguelgrinberg
Copy link
Collaborator

The documentation is incorrect. sort is passed as an argument in the constructor, it is not a class attribute.

miguelgrinberg added a commit to miguelgrinberg/elasticsearch-dsl-py that referenced this issue Apr 11, 2024
github-actions bot pushed a commit that referenced this issue Apr 29, 2024
miguelgrinberg added a commit that referenced this issue Apr 29, 2024
miguelgrinberg added a commit that referenced this issue Apr 29, 2024
Fixes #1318

(cherry picked from commit 0c0bdb7)

Co-authored-by: Miguel Grinberg <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Bug Something isn't right
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants