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.all() return empty list when no input. #1021

Open
eromoe opened this issue Jun 30, 2014 · 10 comments · May be fixed by mchaput/whoosh#33 or whoosh-community/whoosh#576
Open

searchqueryset.all() return empty list when no input. #1021

eromoe opened this issue Jun 30, 2014 · 10 comments · May be fixed by mchaput/whoosh#33 or whoosh-community/whoosh#576

Comments

@eromoe
Copy link

eromoe commented Jun 30, 2014

I want to get all results when there is no input.
So I add below code to my search form.It returns a empty list.

    def no_query_found(self):
        return self.searchqueryset.all()

It returns all when I exclude a special char.

    def no_query_found(self):
        return self.searchqueryset.exclude(content='foo')

env: win 7, django 1.4 , haystack 2.1.0, whoosh 2.5.7

@jogwen
Copy link
Contributor

jogwen commented Aug 18, 2014

+1.

With:

  • django-haystack 2.2.0
  • Whoosh 2.6.0
  • Django 1.6.4

haystack/forms.py: SearchForm.no_query_found() docstring suggests:

"Should you want to show all results, override this method in your
own SearchForm subclass and do return self.searchqueryset.all()."

But this doesn't work - self.searchqueryset.all() returns an empty SearchQuerySet.

QuerySet.all() returns all objects, so it's confusing to me that SearchQuerySet.all() returns the empty set.

Is there a 'proper' way of fetching all objects via the SearchQuerySet? If not, I'll try and find a filter()/exclude() that will trigger the effect I'm after without excluding any objects, but I think the SearchForm.no_query_found() docstring should be corrected because it's just wrong at the moment.

@AJLeonardi
Copy link

+2

With:

  • Django-Haystack: 2.2.0
  • Whoosh: 2.6.0
  • Django: 1.5.4

SearchQuerySet().all() returns an empty list.

I know the index is created properly because when I use the basic_search() view, I get results just fine.

@AJLeonardi
Copy link

Hi guys, I think this might be by design. when using .filter(), my results are coming back fine.

still, I'd like to see .all() return all results! I guess I'm not clear on the purpose of the function.

see the comments in the response to my stack overflow question: http://stackoverflow.com/questions/25695904/django-search-setting-haystack-default-operator-or-has-no-effect

@kinuax
Copy link

kinuax commented Jul 17, 2015

I found myself with the same problem: self.searchqueryset.all() returns an empty list.

In my case, this behaviour is related with the field type of text in the SearchIndex:
text = indexes.CharField(document=True, use_template=True) -> self.searchqueryset.all() returns all the objects from the index
text = indexes.EdgeNgramField(document=True, use_template=True) -> self.searchqueryset.all() returns an empty list

@kinuax
Copy link

kinuax commented Jul 17, 2015

With indexes.EdgeNgramField field type, self.searchqueryset.exclude(content='foo'), as proposed, returns the objects from the index.

Thanks for commenting.

@seocam
Copy link

seocam commented Mar 25, 2016

Same here. If the field holding the document=True is a EdgeNgramField or NgramField the SearchQuerySet comes empty if no filter is applied.

Whoosh 2.7.3
Django 1.8.11
Haystack 2.4.1

@lgellert
Copy link

lgellert commented Jun 9, 2016

+5

With:
Django-Haystack: 2.5.dev1
Whoosh: 2.7.4
Django: 1.9.4
SearchQuerySet().all() returns an empty list with an EdgeNgramField.

Thanks all for this thread, and @kinuax for the 'excludes' hackaround which works for now.

@pembo13
Copy link

pembo13 commented Sep 17, 2018

Hi guys, this is still an undocumented, apparent bug.

  • django-haystack==2.8.1
  • Whoosh==2.7.4

@twz915
Copy link

twz915 commented Oct 31, 2018

I am using sqs = SearchQuerySet().models(Project).exclude(no_such_field="x") to get all currently

@maksimstojkovic
Copy link

Hi Everyone,

I've looked into this issue and it seems that there is a tokenization problem for N-gram fields as they are self_parsing, and do not currently support wildcard searches, such as SearchQuerySet() and SearchQuerySet.all().

I've created a pull request(s?) for this issue, which you can browse below if you are interested in seeing the fix:

In the meantime, the simplest solution I've used is sqs = SearchQuerySet().exclude(_text=None)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
10 participants