Add graph.Search for substr
This commit is contained in:
@@ -6,6 +6,15 @@ import (
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
type Regex struct {
|
||||
Key string
|
||||
Value string
|
||||
}
|
||||
|
||||
func (re Regex) MarshalBSON() ([]byte, error) {
|
||||
return filterMarshal("$regex", re.Key, re.Value)
|
||||
}
|
||||
|
||||
type FilterIn struct {
|
||||
Key string
|
||||
Values []interface{}
|
||||
@@ -46,12 +55,17 @@ func NewFilterIn(key string, values interface{}) FilterIn {
|
||||
}
|
||||
|
||||
func (fi FilterIn) MarshalBSON() ([]byte, error) {
|
||||
if len(fi.Key) == 0 {
|
||||
return filterMarshal("$in", fi.Key, fi.Values)
|
||||
}
|
||||
|
||||
func filterMarshal(op, key string, value interface{}) ([]byte, error) {
|
||||
if len(key) == 0 {
|
||||
return bson.Marshal(map[string]interface{}{})
|
||||
}
|
||||
return bson.Marshal(map[string]map[string][]interface{}{
|
||||
fi.Key: map[string][]interface{}{
|
||||
"$in": fi.Values,
|
||||
m := map[string]map[string]interface{}{
|
||||
key: map[string]interface{}{
|
||||
op: value,
|
||||
},
|
||||
})
|
||||
}
|
||||
return bson.Marshal(m)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user