Skip to content
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

SearchQuerySet.models() filter not working on ES5 #1622

Open
2 tasks done
JClubb3 opened this issue Jun 28, 2018 · 0 comments
Open
2 tasks done

SearchQuerySet.models() filter not working on ES5 #1622

JClubb3 opened this issue Jun 28, 2018 · 0 comments

Comments

@JClubb3
Copy link

JClubb3 commented Jun 28, 2018

  • Tested with the latest Haystack release
  • Tested with the current Haystack master branch

Expected behaviour

Calling .models() on an SQS will limit results to the specified models.

Actual behaviour

The provided models are ignored. The SQS will always return all matching models.

Steps to reproduce the behaviour

  1. Submit an SQS against a dataset for which instances of multiple models should match.
  2. Submit this SQS once without calling .models() and check the length.
  3. Submit it again while calling .models() and check the length; the two lens will be the same.
>>> a = SearchQuerySet().filter(content="test")
>>> len(a)
7
>>> for s in a.all():
...     print(s)
...
<SearchResult: certapp.comment (pk='7')>
<SearchResult: certapp.comment (pk='1')>
<SearchResult: certapp.comment (pk='2')>
<SearchResult: certapp.comment (pk='6')>
<SearchResult: certapp.comment (pk='9')>
<SearchResult: certapp.featuredocument (pk='4')>
<SearchResult: certapp.featuredocument (pk='6')>
>>> b = a.models(Comment)
>>> len(b)
7
>>> for s in b.all():
...     print(s)
...
<SearchResult: certapp.comment (pk='7')>
<SearchResult: certapp.comment (pk='1')>
<SearchResult: certapp.comment (pk='2')>
<SearchResult: certapp.comment (pk='6')>
<SearchResult: certapp.comment (pk='9')>
<SearchResult: certapp.featuredocument (pk='4')>
<SearchResult: certapp.featuredocument (pk='6')>

Resolution

I did some looking around, and found some code present in ElasticSearchBackend.build_search_kwargs() that had to do with models that is missing in ElasticSearch5Backend.build_search_kwargs(). When I added the code from the former into the latter, my searches work as expected again:

>>> a = SearchQuerySet().filter(content="test")
>>> len(a)
7
>>> b = a.models(Comment)
>>> len(b)
5
>>> for s in b.all():
...     print(s)
...
<SearchResult: certapp.comment (pk='7')>
<SearchResult: certapp.comment (pk='1')>
<SearchResult: certapp.comment (pk='2')>
<SearchResult: certapp.comment (pk='6')>
<SearchResult: certapp.comment (pk='9')>

I will submit a pull request with the code change, though my fix was just a copy and paste.

Configuration

  • Operating system version: Ubuntu 18.04
  • Search engine version: ElasticSearch 5
  • Python version: 3.6.5
  • Django version: 2.0.6
  • Haystack version: 2.8.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant