Syntax inspired from KQL (specification)
var collection = new List<Person>();
var queryBuilder = new QueryBuilder<Person>();
queryBuilder.AddHandler<string>("name", (obj, value) => obj.FullName.Contains(value, StringComparison.OrdinalIgnoreCase));
queryBuilder.AddRangeHandler<int>("age", (obj, value) => value.IsInRange((int)(DateTime.UtcNow - obj.DateOfBirth).TotalDays / 365));
var query = queryBuilder.Build("name:sample query");
query.Evaluate(new Person("John Doe", new DateTime(2000, 1, 1)));
record Person(string FullName, DateTime DateOfBirth);
- Logical operators
NOT
,AND
,OR
- Priority using
(
,)
AddHandler
: supported operators::
AddRangeHandler
: supported operators::
,<
,<=
,>
,>=
,..
(range)SetTextFilterHandler
matches all non-bound filters- Special values:
today
,yesterday
,this week
,this month
,last month
,this year
,last year
Examples:
name:john
orname=john
name:"john doe"
name<>john
or-name:john
orNOT name:john
(name:"john doe" OR name:jane) AND age>21
created:"this week"
age:13..19
(lower and upper bound are included)age>=21
is_open:true free form text
is_open:true AND NOT "free form text"