Skip to content

Loading…

Errors on searches with leading "-" #728

Open
lenz opened this Issue · 2 comments

2 participants

@lenz

Lately I observed two problems. Both occurred with woosh as backend.

  1. When a very short query is performed (exactly one char + "-") like "-x" I get the following error:
    Exception Value: 'NoneType' object has no attribute 'normalize'
    Exception Location: /Users/lenz/Projekte/innotech-legacy/lib/whoosh/query/wrappers.py in normalize, line 128

  2. When a longer query is performed (like "-xx") there is no error but the pagination is shown although there are no results. Wen using the pagination there is the following error on Page 3 ("?q=-xxxx&page=3"):
    Exception Value: index_queryset() got an unexpected keyword argument 'using'
    Exception Location: /Users/lenz/Projekte/innotech-legacy/lib/haystack/indexes.py in read_queryset, line 120

I am using the latest release of woosh and the latest commit if haystack 2.0 beta.

@acdha

Are you using auto_query? "-" is used to exclude terms, which would explain the no results aspect of your second point.

index_queryset() got an unexpected keyword argument 'using'
/Users/lenz/Projekte/innotech-legacy/lib/haystack/indexes.py in read_queryset, line 120

Looks like you are using the latest django-haystack but need to update your index class' read_queryset() method to support the using parameter which was added in #534.

@lenz

Thanks for your quick reply!
I am using haystack on a basic level like described in your "getting started" document. So I never used "read_queryset" or "auto_query".

Now I added the "using" argument to "index_queryset(self, using=None)" like described in your latest getting started docs. Additionally I did a rebuild_index, which was not running without the "using" kwarg. These steps solved problem nr. 2 (?q=-xx). I do get results now and can navigate to page 3 (last page) without getting an error.

Problem nr. 1 (?q=-x) is still there.

This is how I use haystack

urls.py:

url(r'^suche/', SearchView(), name='search'),

search_indexes.py:

from haystack import indexes
from feincms.module.page.models import Page
from django.test.client import RequestFactory
from django.contrib.auth.models import AnonymousUser
from django.utils.html import strip_tags


class PageIndex(indexes.SearchIndex, indexes.Indexable):
    """
    Index for FeinCMS Page objects
    """
    url = indexes.CharField(model_attr="_cached_url")
    text = indexes.CharField(document=True, default="")
    title = indexes.CharField(model_attr="title")
    modified = indexes.DateTimeField(model_attr="modified")

    def get_model(self):
        return Page

    def should_update(self, instance, **kwargs):
        return instance.active

    def index_queryset(self, using=None):
        return self.get_model().objects.filter(groups=None)

    def get_updated_field(self):
        return "modified"

    def prepare(self, obj):
        self.prepared_data = super(PageIndex, self).prepare(obj)
        rf = RequestFactory()
        request = rf.get(self.prepared_data['url'])
        request.user = AnonymousUser()
        for c in obj.content.content_main:
            self.prepared_data['text'] += strip_tags(c.render(request=request))
        return self.prepared_data
@acdha acdha added the unconfirmed label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.