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
Better approach (in my opinion) to AND/OR junctions #198
Conversation
. Added support for ilike filter operator; . Implemented or_ in filters (by using lists);
…filter operator, Fixed issue fix jfinkels#94 regression;
…filter operator, Fixed issue fix jfinkels#94 regression;
Conflicts: flask_restless/search.py flask_restless/views.py
WARNING: total_rows becomes num_results;
Conflicts: flask_restless/search.py
. Removed cumbersome "junction";
Thanks for the suggestions! I am not totally on board with this for the following reasons.
However, I am open to persuasive arguments. |
Fine. :-)
Obviously if you approve this I will write code, documentation and tests needed to support it - and documentation can include a note regarding the "search feature being complete for the scope of the module". Whatever you decide thank you for your reply! |
I understand the value of a response that includes only the data that the client requires (fewer bits need to be transported), but I'm still not convinced that this belongs in Flask-Restless. I'm going to leave this pull request open for a while, and if many other people have the same issue, then I'll pull in the changes. |
Allright. |
I actually have a related issue: I need to filter based on two columns in a related object, which for as far as I can see is not possible using the current options. So either this solution or allowing something like below would work for me. (I can also open up a PR for the solution below if appreciated).
|
I think nested and/or will help very much. Not sure about frankix' approach, though. |
I'm facing this very same problem so having a way to specify an OR operator for just a few filters and use AND for the rest would be great. The alternation between AND/OR for each level feels weird to me but as long as it's well documented it's fine for me... I will apply the patch on my code until this is PR is merged. I agree that this PR also completes the search functionality giving advance features for people who's building a pretty complex set of filters. |
@franklx, @jfinkels, @synergetic: I've been thinking and maybe a syntax like the following would be easier:
The code above would generate a query like this:
Things can get more standardised, flexible (and also complicated) like this:
What do you guys think? |
I'd prefer the first solution by @christophervalles being concise and retains the original flask-restless concept that the and operator is implicit (you always use "and" in queries). To be fully expressive the second example should be written as:
that in my opinion is awfully cumbersome. |
@franklx Yes, the fully expressive option might be too much so, if we stick with the idea of the AND operator being implicit the problem goes down to implement the new OR operator and we end up with a pretty "clean" way of dealing with this issue. |
Can someone check out how other similar projects solve this problem? Here's just a few: https://flask-restless.readthedocs.org/en/latest/similarprojects.html |
is this resolved? This feature would help me a lot |
Before, filters in search queries were joined using only conjunction or only disjunction, as controlled by the `disjunction` parameter. Now we allow arbitrary Boolean expressions of filter objects. By default, if no ANDs or ORs are specified, the filters are assumed to be a conjunction. This supercedes pull request #198 and fixes it in a different way.
I just committed a change to the code that will allow search queries to have arbitrary Boolean formulas consisting of filter objects. For example:
This supercedes this pull request by implementing the requested change in a slightly different way. This feature will appear in the next tagged release, which I will publish soon. |
Sounds good, thanks! |
The junction mechanism doesn't solve the nested and/or problem.
Consider the query:
The junction mechanism doesn't provide syntax to write it like a json filter.
My method looks like an hack (because it's not intuitive) but works very well.
It uses lists to group and apply the correct conjunction/disjunction.
My implementation allow the WHERE part of the query to be written as:
As you can see the or / and junction is toggled on every new level.
If you are interested in this approach I will write documentation and tests and submit and more clean pull request.