search is not searchin
This commit is contained in:
parent
beeac40a10
commit
3e72510d53
@ -241,13 +241,12 @@ func (m *MongoDB) Search(search string, filter []string, collection_name string)
|
|||||||
opts.SetLimit(100)
|
opts.SetLimit(100)
|
||||||
if strings.TrimSpace(search) == "*" {
|
if strings.TrimSpace(search) == "*" {
|
||||||
search = ""
|
search = ""
|
||||||
} else {
|
|
||||||
search = `(?i).*` + strings.TrimSpace(search) + `.*`
|
|
||||||
}
|
}
|
||||||
|
search = ".*" + strings.TrimSpace(search) + ".*"
|
||||||
targetDBCollection := CollectionMap[collection_name]
|
targetDBCollection := CollectionMap[collection_name]
|
||||||
list := []bson.M{}
|
list := []bson.M{}
|
||||||
for _, k := range filter {
|
for _, k := range filter {
|
||||||
list = append(list, bson.M{k: bson.M{"$regex": search}})
|
list = append(list, bson.M{k: bson.M{"$regex": search, "$options": 'i'}})
|
||||||
}
|
}
|
||||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@ -255,8 +254,8 @@ func (m *MongoDB) Search(search string, filter []string, collection_name string)
|
|||||||
if cursor, err := targetDBCollection.Find(
|
if cursor, err := targetDBCollection.Find(
|
||||||
MngoCtx,
|
MngoCtx,
|
||||||
bson.M{"$or": []bson.M{
|
bson.M{"$or": []bson.M{
|
||||||
{"name": bson.M{"$regex": search}},
|
{"name": bson.M{"$regex": search, "$options": 'i'}},
|
||||||
{"description": bson.M{"$regex": search}},
|
{"description": bson.M{"$regex": search, "$options": 'i'}},
|
||||||
}},
|
}},
|
||||||
opts,
|
opts,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user