Add graph.Search for substr

This commit is contained in:
Bel LaPointe
2020-07-22 22:42:21 -06:00
parent 660cd64262
commit db1c36fc0f
3 changed files with 46 additions and 7 deletions

View File

@@ -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)
}