moved filter logic into query

This commit is contained in:
ston1th 2017-11-12 14:33:39 +01:00
commit 3b458f6ff1
4 changed files with 94 additions and 70 deletions

View file

@ -51,7 +51,7 @@ For nested structs:
Supported logical matching:
* `AND` - all statements have to match
* `AND` - all statements have to match (if no logic is provided, this is the default)
* `OR` - only one statement has to match
* `NOT` - none of the statements have to match
@ -93,7 +93,7 @@ var data = Filter{
### Explicit match
```
filter.NewQuery("Bool:true", filter.OR).Filter(&data)
filter.NewQuery("OR Bool:true").Filter(&data)
data = [{str1 42 true {s1 {1}}} {str2 42 true {s2 {2}}}]
```
@ -104,7 +104,7 @@ Wildcard operator: `*`
To match the `'*'` character use: `**`
```
filter.NewQuery("String:s*", filter.OR).Filter(&data)
filter.NewQuery("OR String:s*").Filter(&data)
data = [{str1 42 true {s1 {1}}} {str3 42 false {s3 {3}}}]
```
@ -112,7 +112,7 @@ data = [{str1 42 true {s1 {1}}} {str3 42 false {s3 {3}}}]
### Nested struct match
```
filter.NewQuery("Struct.Struct.Int:3", filter.OR).Filter(&data)
filter.NewQuery("OR Struct.Struct.Int:3").Filter(&data)
data = [{str3 42 false {s3 {3}}}]
```
@ -120,7 +120,7 @@ data = [{str3 42 false {s3 {3}}}]
### Multiple matches
```
filter.NewQuery("Struct.String:*2 Bool:true", filter.AND).Filter(&data)
filter.NewQuery("Struct.String:*2 Bool:true").Filter(&data)
data = [{2str 42 true {s2 {2}}}]
```
@ -132,7 +132,7 @@ The `GenericFilter` does not support sorting.
#### Sort
```
filter.NewQuery("sort:Bool:desc", filter.AND).Filter(&data)
filter.NewQuery("sort:Bool:desc").Filter(&data)
data = [{str1 42 false {s1 {1}}} {2str 42 true {s2 {2}}} {str3 42 true {s3 {3}}}]
```
@ -140,7 +140,7 @@ data = [{str1 42 false {s1 {1}}} {2str 42 true {s2 {2}}} {str3 42 true {s3 {3}}}
#### Sort and Filter
```
filter.NewQuery("sort:Bool:desc String:str*", filter.AND).Filter(&data)
filter.NewQuery("sort:Bool:desc String:str*").Filter(&data)
data = [{str1 42 false {s1 {1}}} {str3 42 true {s3 {3}}}]
```