Skip to content

Commit 803f2c5

Browse files
author
breezeli
authored
Merge pull request #2842 from breezelxp/v3.2.x
新增主机查询页面支持多字符字段模型查询功能 Former-commit-id: ed21665
2 parents 4ce6368 + d4043e9 commit 803f2c5

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

src/common/definitions.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,10 @@ const (
122122
BKInnerObjIDApache = "bk_apache"
123123
)
124124

125-
// Revision
126125
const (
127-
RevisionEnterprise = "enterprise"
128-
RevisionCommunity = "community"
129-
RevisionOpensource = "opensource"
130-
)
126+
// used only for host search
127+
BKDBMULTIPLELike = "$multilike"
131128

132-
const (
133129
// BKDBIN the db operator
134130
BKDBIN = "$in"
135131

src/common/paraparse/host.go

+17
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ package params
1414

1515
import (
1616
"configcenter/src/common"
17+
"configcenter/src/common/mapstr"
1718
"configcenter/src/common/metadata"
1819
"configcenter/src/common/util"
20+
"fmt"
1921
)
2022

2123
//type Flag string
@@ -69,6 +71,21 @@ func ParseHostParams(input []metadata.ConditionItem, output map[string]interface
6971
regex := make(map[string]interface{})
7072
regex[common.BKDBLIKE] = i.Value
7173
output[i.Field] = regex
74+
case common.BKDBMULTIPLELike:
75+
multi, ok := i.Value.([]interface{})
76+
if !ok {
77+
return fmt.Errorf("operator %s only support for string array", common.BKDBMULTIPLELike)
78+
}
79+
fields := make([]interface{}, 0)
80+
for _, m := range multi {
81+
mstr, ok := m.(string)
82+
if !ok {
83+
return fmt.Errorf("operator %s only support for string array", common.BKDBMULTIPLELike)
84+
}
85+
fields = append(fields, mapstr.MapStr{i.Field: mapstr.MapStr{common.BKDBLIKE: mstr}})
86+
}
87+
output[common.BKDBOR] = fields
88+
7289
default:
7390
queryCondItem, ok := output[i.Field].(map[string]interface{})
7491
if !ok {

src/scene_server/host_server/logics/hostsearch.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,15 @@ func (sh *searchHost) searchByHostConds() error {
681681
}
682682

683683
condition := make(map[string]interface{})
684-
hostParse.ParseHostParams(sh.conds.hostCond.Condition, condition)
685-
hostParse.ParseHostIPParams(sh.hostSearchParam.Ip, condition)
684+
err = hostParse.ParseHostParams(sh.conds.hostCond.Condition, condition)
685+
if err != nil {
686+
return err
687+
}
688+
689+
err = hostParse.ParseHostIPParams(sh.hostSearchParam.Ip, condition)
690+
if err != nil {
691+
return err
692+
}
686693

687694
query := &metadata.QueryInput{
688695
Condition: condition,

0 commit comments

Comments
 (0)