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 perform a case insensitive search? #42

Open
boop5 opened this issue Jun 18, 2020 · 4 comments
Open

How to perform a case insensitive search? #42

boop5 opened this issue Jun 18, 2020 · 4 comments

Comments

@boop5
Copy link

boop5 commented Jun 18, 2020

I want to ignore the case when using Containg or ContainigAll. But SetCulture is not available. Is the documentation outdated or am I doing something wrong?

Simplified example of what I'm doing

var searchTerms = new string[] { "mockingbird", "kill" }
var found = await books.Search(book => book.Title)
                       .ContainingAll(searchTerms)
                       .ToListAsync(stoppingToken);

I'm searching on an EfCore DbSet which inherits from IQueryable

@ninjanye
Copy link
Owner

Hi @boop5

Apologies for the delay in responding to this... What is it you are currently trying, using your example above you should be able to do the following... The important thing is to use SetCulture before the containing command

var searchTerms = new string[] { "mockingbird", "kill" }
var found = await books.Search(book => book.Title)
                       .SetCulture(StringComparison.OrdinalIgnoreCase)
                       .ContainingAll(searchTerms)
                       .ToListAsync(stoppingToken);

@ninjanye
Copy link
Owner

Hi @boop5,

Was just looking back on this and I think I now understand the issue. For IEnumerable<T> the .SetCulture method is available, however, when used with SQLServer the default is to perform a case insensitive string match, so SetCulture is not needed. This does raise the point, that just because someone is using IQueryable does not mean they have SqlServer as their backend store, so this is something I will look to add for IQueryable in the future

I will give this a couple of days, but otherwise assuming this addresses your point, I will close this down

@wouter-b
Copy link

wouter-b commented Jan 31, 2022

Hi @ninjanye ,

that just because someone is using IQueryable does not mean they have SqlServer as their backend store, so this is something I will look to add for IQueryable in the future

I'm using CosmosDB as a backend, whcih is Case Sensitive by default. Adding .SetCulture to IQueryable would solve the case insensitive search for me.

RIght now my workaround is

var queryTerms = query.Trim().ToLower().Split(' '); return projects.Search( p => p.ProjectName.ToLower(), p => p.ClientName.ToLower(), p => p.Area.ToLower() ).ContainingAll(queryTerms);

Which is not optimal because it requires a scan instead of using an index.

@jrodriguez-masao
Copy link

Hello @ninjanye, I'm using SQLite (case-sensitive by default) as a backend an it would also be really useful to have .SetCulture for IQueryable. Have you got any timeline on this implementation, or any way we can help make it happen?

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

4 participants