-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
Filter OR operator and complex predicates #183
Comments
This would also make 'or' filtering possible. A feature I would like to have is to filter on multiple values, so that for example this:
returns resources where |
@dnperfors I agree that your format makes sense (to me at least) for
but doesn't solve for the more general:
I could see something like this to solve that case:
This would allow you to construct more complex conditional clauses across multiple attributes. I'm not particularly fond of that syntax, so I'm open to suggestions. If we go with this, I would still like to preserve the original value (unsplit |
@jaredcnance I need to check but I think that multiple filters should be This also interops with common patterns and request readers in frameworks like Laravel/Express/Rails. |
Is there anything in the spec around arrays of values? |
From the jsonapi.org spec:
|
@jaredcnance, For a previous project where I had to implement the jsonapi spec, I didn’t really find a good solution for OR-ing multiple attributes as you describe, but how about something like: @rtablada, there is nothing specific mentioned about arrays, the best you could do is indeed using the comma separator and for testing for specific values in an array you could use a contains operator (not sure if it is already supported) |
@jaredcnance I need the OR operator asap, so I've quickly implemented the following prototype:
Startup:
My methods implemeting the OR logic:
What do you think of this approach? |
@nikalfa thanks for sharing! This seems like a valid approach. I'm not sure if the semantics of the (A&B or C&D) But, it does look like it's perfectly fine for: (AorB & CorD) Regarding the use of |
@jaredcnance Yes, this construct can't handle the the ORing of ANDs, but this would make the parsing of the FilterQuery much more complex. As for combinations with ANDs - my implementation can handle any number of them. In Fact it can also handle any amount of ORs as long they are "not interrupted". This filter sequence works:
The only Issue I have with my current solution is that the This would mean custom implementation for every Entity, or maybe a more general implementation which would Serialize the Entity to JSON and then compare the strings. |
filter[name][]=name1,name2 |
Wouldn't the basic implementation of @nikalfa serve as a good stepping stone? Or do you wish for a fully implemented version for v4? |
If @nikalfa or someone else has time to implement a solution, I'll happily back this approach moving forward. I think more complex filtering operations may be supported through json:api v1.1 operations. |
@wisepotato @jaredcnance it's pretty ironic that the trigger for the OR filter reappeared right now. Although I did implement this feature in March, it was never included in our product. For the upcoming sprint (two weeks) I got the task to dust off/finalize the implementation and get it into production. I'll happily share my solution. |
Currently, filter values are split by comma into separate
FiterQuery
s. This makes things like this possible:But, this doesn't make much sense and the proper query should be:
It also prevents custom queries from being picked up using
IQueryAccessor.GetRequired<>()
This issue has been re-purposed for the discussion of complex filter predicates (anything other than simple serial AND)
The text was updated successfully, but these errors were encountered: