-
Notifications
You must be signed in to change notification settings - Fork 133
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 on multiple properties (OR condition) #8
Comments
You can do that with a custom filters so for example: The equivalent of your public class SieveCustomFilterMethods : ISieveCustomFilterMethods
{
public IQueryable<Post> PostSearch(IQueryable<Post> source, string op, string value)
{
if (op == "@=")
{
var result = source.Where(p => p.Title.Contains(value)
|| p.Body.Contains(value)
|| p.Author.Contains(value));
return result;
}
else
{
return source;
}
}
} This would save you having to send requests with the same property names repeated every time, as well as allow for any additional logic you might need. That being said, I understand the need for OR logic, especially when you need to query unknown arbitrary parameters each time. I was working on an version where a Really glad you like Sieve :D. |
Thanks for your quick response. Yes, a complete OR logic using One difference I can think of is that with a generic OR solution, operator precedence between AND and OR has to be considered when combining operators. Should it be like in C# (AND before OR) or just an evaluation from left to right? Are brackets needed to group expressions? |
After using Sieve a bit more, I found that I didn't need this feature often (usually custom filters worked fine). But given how easy it is to implement OR logic similar to what you described (c861ada), I'll be including it as part of v2. The feature is ready on the master branch but still not published to nuget yet. I find the current parsing code to be a bit hacky - so I'll be trying to rewrite this using a parsing framework next to maybe support better AND/OR logic with precedence and bracket grouping but that's not a priority for now. EDIT: v2 on nuget now (but review this before upgrading) |
Loving Sieve - it's great! Upvoting this... I'd love this to work: {{url}}collector?sorts=Name&filters=(Name|Description)@=A |
I just tried it - it didn't work :( The Name contained 'A', but the Description didn't. Bug? |
Could you please open a new issue with error details? |
Hi @Biarity , sorry for commenting on an closed issue but I found the OR condition is not fully working I understand What I expect is Am I using the OR condition wrong or is it this a bug?
If so how can I do the OR condition with difference name value? |
Yeah, OR conditions work exclusively for names or values, not whole filters. I guess the closest to what you want would be |
I think it is also better if the README.md include actual examples for the OR operations, as it is now pointed to #8 (comment) which is not what the final implementation. Also, when implementing the custom filter, I found #47 where it will conflict with the FluentAPI |
filters=name=sam |
Hi,
I want to be filtered firstname, lastname, and place by default all what is set up by sieve in data ano... |
I have been playing with Sieve over the last few days and it is really cool.
However, one feature that I think is missing, is the ability to express filters like this:
"If property1 or property2 contain ABC"
I imagine that the
{Name}
part of the filter expressions could be extended like this:(property1,property2)@=ABC
What do you think about this?
The text was updated successfully, but these errors were encountered: