SearchQuery concatenation (`&` and `|`) is either broken or documentation incomplete

223 views
Skip to first unread message

Nicola

unread,
Aug 25, 2016, 7:30:06 AM8/25/16
to Django developers (Contributions to Django itself)
Dear Django-Developers,

We just started using the new search ability that landed in Django 1.10 (using postgres).

Reading the documentation[1], I thought I can use `&` and `|` to join search queries as I like[2]. This is not the case, which can easily be seen by creating a the test-case with two ampersands or pipes[3]. 

I would not expect that the test-cases pass, but they error out: `NotImplementedError: Use .bitand() and .bitor() for bitwise logical operations.`.

To me this is not the expected behaviour, but maybe I deducted the wrong conclusions from reading the documentation.

My unanswered questions:
  • Is it a bug?
  • Is this the intended behaviour?
    • If so: what needs to be done to get a note into the documentation, that only one ampersand/pipe is allowed?
Thank you for your time and effort for this excellent framework!

Kind Regards,

Nicola


Josh Smeaton

unread,
Aug 25, 2016, 8:54:32 AM8/25/16
to Django developers (Contributions to Django itself)
Hi Nicola,

Without a lot of familiarity of SearchQuery, in particular, it looks like a bug to me. SearchQuery defines its own operators to work around the limitation in Combinable, but fails to take into account that when two SearchQuery instances are combined, you're returned a CombinedExpression (containing SearchQueries). SearchVector *does* take this into consideration though, and provides it's own Combinable Mixin, so I wonder if the limitations for SearchQuery aren't on purpose.

Marc Tamlyn would probably have a good idea if this was an oversight or deliberate.

The fix would be to define a SearchQueryCombinable Mixin that looks very similar to SearchVectorCombinable, and override the various __or__ and __and__ methods, as the SearchQuery type does itself. Hope that helps?

Regards,

Marc Tamlyn

unread,
Aug 25, 2016, 9:22:14 AM8/25/16
to django-d...@googlegroups.com
Yup, that sounds like an oversight on my part. The fix would be exactly as Josh described.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/31548201-3d01-4318-8165-47cad2afa1fc%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Nicola

unread,
Aug 29, 2016, 8:47:31 AM8/29/16
to Django developers (Contributions to Django itself)
Hi Josh and Marc,

Thank you very much for your time, pointers and help.

Kind regards,
Nicola
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages