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

Filter operator for case-insensitive for string #21

Closed
dcube9 opened this issue Sep 19, 2021 · 4 comments
Closed

Filter operator for case-insensitive for string #21

dcube9 opened this issue Sep 19, 2021 · 4 comments
Assignees
Labels
close fixed feature-request Request for a new feature

Comments

@dcube9
Copy link

dcube9 commented Sep 19, 2021

It's usual to filter string data in case-insensitive mode.

A way to do that is add # operator.

var gQuery = new GridifyQuery() { Filter = "FirstName=#John, Address=*#st", OrderBy = "PhoneNumber" };

Regards

@alirezanet
Copy link
Owner

alirezanet commented Sep 20, 2021

Hi, thank you for your feedback
For now, Gridify doesn't have a case-insensitive operator yet but you can achieve case-insensitive search using the value convertors.

e.g

 var gq = new GridifyQuery { Filter = "FirstName=John" };
 var gm = new GridifyMapper<TestClass>()
            .AddMap("name", q => q.Name.ToLower() , c => c.ToLower());

         var query = Ds.ApplyFiltering(gq, gm);

Although I agree having an operator is simpler, The problem with having # operator in values is the character escaping, for example, the user can not easily search #John and must use something like \#John. but I'll look into this more.
I think having an /i operator at the end of each value could be a better option. (also regex is using the same operator)

e.g

var gQuery = new GridifyQuery() { Filter = "FirstName=John/i, Address=*st/i", OrderBy = "PhoneNumber" };

it's really rare if someone wants to have the John/i phrase to search. what do you think?

@alirezanet alirezanet added the feature-request Request for a new feature label Sep 20, 2021
@alirezanet alirezanet self-assigned this Sep 20, 2021
@dcube9
Copy link
Author

dcube9 commented Sep 20, 2021

Hi, thank you for reply.

About symbol, I choice that without a specific reason.
The main problem (IMHO), is the string delimiter, every solution (# or /i or ...) have potentially a syntax problem.
But If we use a delimiter like ' (Apostrophe) for string in string you can write :
var gQuery = new GridifyQuery() { Filter = "FirstName='John'/i, Address=*st/i", OrderBy = "PhoneNumber" };
or
var gQuery = new GridifyQuery() { Filter = "FirstName=#'John', Address=*#'st'", OrderBy = "PhoneNumber" };

and when you need an apostrophe us ' .

what do you think?

@alirezanet
Copy link
Owner

alirezanet commented Sep 21, 2021

The main problem (IMHO), is the string delimiter, every solution (# or /i or ...) have potentially a syntax problem.

You are completely right, but I think supporting the Apostrophe characters has the same problem. also because Gridify is being used in a lot of projects I should avoid any major breaking changes.
I remember I had this idea to support (Apostrophe) in version 1 but after few tests, I realized it's not helping too much.
this problem already exists for ( ) , | characters but it is easy enogth to solve. Regex.Replace(value, "([(),|])", "\\$1" ).
probably I'll only add an operator for case-insensitive support like # or /i ...
thank you for the contribution

@alirezanet alirezanet mentioned this issue Sep 21, 2021
alirezanet added a commit that referenced this issue Sep 21, 2021
Add support Case-Insensitive search using `/i` operator. #21
@alirezanet
Copy link
Owner

alirezanet commented Sep 21, 2021

This feature is available in v2.1.0 . (readme)

var gq = new GridifyQuery() { Filter = "FirstName=John/i" };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
close fixed feature-request Request for a new feature
Projects
None yet
Development

No branches or pull requests

2 participants