Skip to content
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

How to work with the array #2

Open
rdvitka opened this issue Feb 7, 2018 · 12 comments
Open

How to work with the array #2

rdvitka opened this issue Feb 7, 2018 · 12 comments

Comments

@rdvitka
Copy link

rdvitka commented Feb 7, 2018

Hello,
How you can work with a array type filters.

&filters=LikeCount>10,Author==[Brad Pitt,Mel Gibson]

I am asking for a hint.

@Biarity
Copy link
Owner

Biarity commented Feb 7, 2018

You'll have to write a custom filter for that. Here's an example for v>=1.3.7:

public class SieveCustomFilterMethods : ISieveCustomFilterMethods
{
    public IQueryable<Post> AuthorIsAnyOf(IQueryable<Post> source, string op, string value)
    {
        var result = source.Where(p => value.Split('|').Contains(p.Author));
        return result;
    }
}

Then inject the class: services.AddScoped<ISieveCustomFilterMethods, SieveCustomFilterMethods>();.

Now you can send requests in the form:

& AuthorIsAnyOf == Bad Pitt|Mel Gibson

Note I'm using the pipe character (|) instead of a comma because Sieve uses commas to separate filter terms.

@Biarity
Copy link
Owner

Biarity commented Feb 14, 2018

I will be closing this issue. If you think this does not fit your use case please let me know - I could put in the time for creating native enumerable search if required.

@Biarity Biarity closed this as completed Feb 14, 2018
@elmankross
Copy link

Sorry for comment in closed issue but what about this feature - native enumerable search?
Custom filters are not really good idea for this case, because it's not a clear use case for clients.
I want to share my OpenAPI schema and describe how to work with filters and that's all.

@Biarity
Copy link
Owner

Biarity commented Oct 1, 2018

Yeah I've ran into this issue. Will look more into this once I get some free time.

@Biarity Biarity reopened this Oct 1, 2018
@Rakiah
Copy link

Rakiah commented May 23, 2019

This sound like a very important feature to me, did you had any time to work over this by chance ?

@maxstralin
Copy link

A bit inclined to look at this, any issues with me submitting a PR if I manage?
Thinking the most flexible of scenarios would be to allow each array entry to have it's own filter, to allow for stuff like &filters=LikeCount>10,Author==[_=Brad P|@=Mel|Angelina Jolie]. Possibly leaving the nested operators optional, like the "Angelina Jolie" entry, and in that case using the operator specified by Author, i.e. ==.

Any opinions?

@maxstralin
Copy link

Ping @Biarity

@Biarity
Copy link
Owner

Biarity commented Sep 24, 2019

@maxstralin Sounds good, feel free to submit a PR. Unfortunately I'll be very busy in the coming days so unlikely to implement this myself in the near future.

@hasanmanzak
Copy link
Collaborator

@maxstralin Any progress on this?

@maxstralin
Copy link

@hasanmanzak Gave up on it back in the days of 2019 but got an urge now to get back to it when you pinged me. I have a dirty proof of concept in https://github.com/maxstralin/Sieve/tree/array-filtering, which would only allow for basic "contains" (case-sensitive) in an IEnumerable<string> property. It needs refactoring and improvement but thought I'd post the update at least.

See CanFilterArray test in General.cs tests for the unit test.
ConvertFilterValueToExpression in SieveProcessor.cs for the method containing the logic.

@hasanmanzak
Copy link
Collaborator

I think we should discuss an API structure then start to work on it :) I just didn't want to dictate any structure I please.

@maxstralin
Copy link

Feel free, if you want to take it then you can take it too haha ;)
Depending on the scope you want, it needs more or less refactoring. E.g. having operators per value, like I suggested in 2019 (Author==[_=Brad P|@=Mel|Angelina Jolie]) doesn't work with the current code as it picks up the Brad P operator instead of ==. However, individual operators per value is probably secondary as the use case is probably not the most common one.

Anyhow, either you do it do a larger refactoring immediately, or you get a working variant up and running, then improve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants