Filtri
Contit usa un potente sistema di filtri strutturato basato su FilterConditionGroup — un albero ricorsivo e componibile di condizioni AND/OR.
Filtro base
{
"page": 1,
"pageSize": 20,
"filter": {
"type": "condition",
"fieldKey": "status",
"operator": "e",
"value": "active"
}
}
Gruppi AND / OR
{
"filter": {
"type": "and",
"conditions": [
{ "type": "condition", "fieldKey": "category", "operator": "e", "value": "news" },
{ "type": "condition", "fieldKey": "published", "operator": "e", "value": true }
]
}
}
Gruppi nidificati
{
"filter": {
"type": "and",
"conditions": [
{
"type": "or",
"conditions": [
{ "type": "condition", "fieldKey": "brand", "operator": "e", "value": "A" },
{ "type": "condition", "fieldKey": "brand", "operator": "e", "value": "B" }
]
},
{ "type": "condition", "fieldKey": "price", "operator": "gt", "value": 0 }
]
}
}
Operatori filtro
| Valore JSON | Enum C# | Descrizione |
|---|---|---|
e |
Equal |
Uguaglianza esatta |
ne |
NotEqual |
Diverso |
in |
Contains |
L'array contiene il valore |
nin |
NotContains |
L'array non contiene il valore |
like |
StringContains |
La stringa contiene la sottostringa |
nlike |
StringNotContains |
La stringa non contiene |
start |
StartsWith |
Inizia con |
end |
EndsWith |
Finisce con |
lt |
LessThan |
Minore di |
lte |
LessThanOrEqual |
Minore o uguale |
gt |
GreaterThan |
Maggiore di |
gte |
GreaterThanOrEqual |
Maggiore o uguale |
noe |
NullOrEmpty |
Nullo o vuoto |
nnoe |
NotNullOrEmpty |
Non nullo né vuoto |
def |
Defined |
Il campo esiste |
ndef |
NotDefined |
Il campo non esiste |
distance |
Distance |
Prossimità geografica (campi GeoLocation) |
Tipi di condizione
| Valore JSON | Enum C# | Descrizione |
|---|---|---|
and |
And |
Tutte le condizioni devono corrispondere |
or |
Or |
Almeno una condizione deve corrispondere |
condition |
Condition |
Singola regola filtro |
Campi di sistema
Filtra sui metadati built-in usando il prefisso sysfield.:
| Chiave | Tipo | Descrizione |
|---|---|---|
sysfield.id |
string | ID del contenuto |
sysfield.dateInsert |
DateTime | Data di creazione |
sysfield.lastUpdate |
DateTime | Data ultima modifica |
{ "type": "condition", "fieldKey": "sysfield.lastUpdate", "operator": "gt", "value": "2025-01-01T00:00:00Z" }
Dot notation per campi JSON
Per i campi di tipo Json, usa la dot notation per interrogare proprietà nidificate:
| Sintassi | Significato | Esempio |
|---|---|---|
address.city |
Proprietà nidificata | Accede a city dentro l'oggetto address |
tags[0] |
Indice array | Primo elemento dell'array tags |
items[].name |
Tutti gli elementi | Cerca name in qualsiasi elemento (JOIN) |
items[0].name |
Elemento specifico | name del primo elemento |
"api.version" |
Chiave con punto | Usa le virgolette per chiavi che contengono punti |
Esempio
{
"filter": {
"type": "and",
"conditions": [
{ "type": "condition", "fieldKey": "address.city", "operator": "e", "value": "Milano" },
{ "type": "condition", "fieldKey": "items[].qty", "operator": "gt", "value": 0 }
]
}
}
.NET SDK
var response = await client.Content.Get<MyModel>("products", new ContentsRequest
{
Page = 1,
PageSize = 20,
Filter = new FilterConditionGroup
{
Type = FilterConditionType.And,
Conditions =
[
new FilterConditionGroup
{
Type = FilterConditionType.Or,
Conditions =
[
new FilterCondition("brand", FilterOperation.Equal, "A"),
new FilterCondition("brand", FilterOperation.Equal, "B")
]
},
new FilterCondition("price", FilterOperation.GreaterThan, 0),
new FilterCondition("sysfield.lastUpdate",
FilterOperation.GreaterThan, DateTime.Now.AddDays(-7))
]
}
});
Nota: Nell'SDK .NET, usa i nomi enum C# (
FilterOperation.Equal,FilterConditionType.And). L'SDK li serializza automaticamente nei valori JSON ("e","and").