-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
[55] Filter on lessons title #78
base: develop
Are you sure you want to change the base?
[55] Filter on lessons title #78
Conversation
a490c4e
to
e667b8d
Compare
@@ -32,6 +32,11 @@ public PaginatedResult<Lesson> PaginatedList(LessonFilter filter) | |||
result = result.Where(l => l.Theme.Id == filter.ThemeId); | |||
} | |||
|
|||
if (!string.IsNullOrEmpty(filter.Term)) | |||
{ | |||
result = result.Where(l => l.Title.Contains(filter.Term) || l.Description.Contains(filter.Term)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider ignoring case and accents (e.g. diacritice): EF.Functions.ILike(l.Title, $"%{filter.Term}%"))
Edit: this only does case-insensitivity. For the accent part you can move to Postgres query or remove accents manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the remarks. I will update the code. For the accent case, I noticed that EF has a function EF.Functions.Unaccent()
but only works with UTF-8 dbs, I'll check that and treat accents also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think it will be better to do this from the query level so we can easily reuse it for all filter terms.
I propose creating a custom string scalar type
public class FilterTermStringGraphType : StringGraphType
{
public override object ParseValue(object value)
{
// Your preprocessing logic
string processedValue = value.ToString().ToLower(); // Example: convert to lowercase
// Add more cleaning/preprocessing steps as needed
return base.ParseValue(processedValue);
}
}
And use this as the argument type.
The benefit of this approach is that we can have a simple way to update cleaning for this terms no matter of the query they are used in.
- code style cleanup
c6c6bf3
to
5496b24
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposed alternative to term filtering
@@ -32,6 +32,11 @@ public PaginatedResult<Lesson> PaginatedList(LessonFilter filter) | |||
result = result.Where(l => l.Theme.Id == filter.ThemeId); | |||
} | |||
|
|||
if (!string.IsNullOrEmpty(filter.Term)) | |||
{ | |||
result = result.Where(l => l.Title.Contains(filter.Term) || l.Description.Contains(filter.Term)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think it will be better to do this from the query level so we can easily reuse it for all filter terms.
I propose creating a custom string scalar type
public class FilterTermStringGraphType : StringGraphType
{
public override object ParseValue(object value)
{
// Your preprocessing logic
string processedValue = value.ToString().ToLower(); // Example: convert to lowercase
// Add more cleaning/preprocessing steps as needed
return base.ParseValue(processedValue);
}
}
And use this as the argument type.
The benefit of this approach is that we can have a simple way to update cleaning for this terms no matter of the query they are used in.
What does it fix?
Issue #55
How has it been tested?
From GraphiQL with seed data: