Coder Social home page Coder Social logo

Comments (5)

dchaplinsky avatar dchaplinsky commented on June 1, 2024

@toastdriven @acdha could you please take a look into it?

from django-haystack.

kingbuzzman avatar kingbuzzman commented on June 1, 2024

Having the same issue now, any update?

from django-haystack.

febsn avatar febsn commented on June 1, 2024

Same problem here.

from django-haystack.

bartTC avatar bartTC commented on June 1, 2024
Failed to query Elasticsearch using 'OR title:(pdf) OR keywords:("pdf") OR id:(pdf)) AND NOT (login_required:(True)))': 
...
Can't parse boolean value [True], expected [true] or [false]

You can workaround this, if you don't like to monkeypatch. Just don't pass a boolean. Watch what is passing the boolean, in my case it was login_required.

I changed the corresponding field to hold an integer

login_required = indexes.BooleanField(default=False) # to
login_required = indexes.IntegerField(default=0)

And the related queryset;

    def prepare_login_required(self, obj):
        return obj.page.login_required # to
        return 1 if obj.page.login_required else 0
        
    def get_queryset(self):
        queryset = self.form.search()
        if not self.request.user.is_authenticated:
            queryset = queryset.exclude(login_required=True) # to
            queryset = queryset.exclude(login_required=1)
        return queryset

from django-haystack.

rascalking avatar rascalking commented on June 1, 2024

I'm also seeing an issue going in the other direction, back into bools in query results. Since BooleanField.convert() just returns bool(value), and bool("false") == True, all booleans are always being returned as True.

I had to resort to subclassing BooleanField and overriding convert():

from haystack.fields import BooleanField as _BooleanField

class BooleanField(_BooleanField):
    def convert(self, value):
        if isinstance(value, str):
            return False if value.lower() in ('false', '') else True
        else:
            return super().convert(value)

from django-haystack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.