[55] Filter on lessons title#78
Conversation
a490c4e to
e667b8d
Compare
|
|
||
| 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.
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.
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.
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
alexandru-calinoiu
left a comment
There was a problem hiding this comment.
Proposed alternative to term filtering
|
|
||
| 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.
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:
{ "data": { "lessons": { "items": [ { "title": "Consectetur adipiscing elit" }, { "title": "Nemo enim ipsam voluptatem" } ] } } }