fix: 修复实体搜索框因输入语句包含and导致识别错误的问题,以及schema字段修改导致的模糊搜索domain和app不能识别的问题

This commit is contained in:
刘洪洪
2023-08-29 10:26:40 +08:00
parent ea3cc7bc67
commit c53cecad93

View File

@@ -1398,7 +1398,7 @@ export function comparedEntityKey (str) {
const regex = /\ = | =|= /g
q = q.replace(regex, '=')
if (q.indexOf('AND') > -1) {
if (q.indexOf('AND') > -1 && checkStrIncludeAnd(q)) {
const arr = q.split(' AND ')
let newQ = ''
let errorQ = ''
@@ -1449,6 +1449,7 @@ export function comparedEntityKey (str) {
}
} else {
const key = q.substring(0, q.indexOf('='))
q = q.replace(/ AND /g, ' and ')
const obj = columnList.find(t => t.label.toLowerCase() === key.toLowerCase())
if (obj) {
return { key: obj.label + q.substring(q.indexOf('='), q.length), isKey: true }
@@ -1511,11 +1512,15 @@ export const handleEntityTypeByStr = (str) => {
const reg = /^(?=^.{3,255}$)(http(s)?:\/\/)?(www\.)?[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:\d+)*(\/\w+\.\w+)*$/
if (regexIPv4.test(str) || regexIPv6.test(str)) {
return `IP='${str}'`
const obj = columnList.find(t => t.label.toLowerCase() === 'ip')
return `${obj.label}='${str}'`
} else if (reg.test(str)) {
return `Domain LIKE '%${str}'`
// 只写作domain即可schema字段更改几次避免后续再更改直接拿columnList的label进行替换
const obj = columnList.find(t => t.label.toLowerCase() === 'domain')
return `${obj.label} LIKE '%${str}'`
} else {
return `App LIKE '%${str}%'`
const obj = columnList.find(t => t.label.toLowerCase() === 'app')
return `${obj.label} LIKE '%${str}%'`
}
}
}
@@ -1609,3 +1614,28 @@ const combineLabel1 = (list) => {
return acc
}, {})
}
/**
* 检测传过来的字符串是否包含and
* 例如 app='Computer and Internet'这种情况,需要单独甄别
* @param str
*/
const checkStrIncludeAnd = (str) => {
const arr = str.split(' AND ')
let label = ''
arr.forEach((item, index) => {
// and前后的语句前面一段不需要甄别因为前一段可能是app='Computer但后一段肯定不属于columnList
// 如果后面一段属于columnList的关键字整段字符串具有and的连接效果
if (index % 2 !== 0) {
if (item.indexOf('=') > -1) {
label = item.substring(0, item.indexOf('='))
} else if (item.toLowerCase().indexOf(' in ') > -1) {
label = item.substring(0, item.toLowerCase().indexOf(' in '))
} else if (item.indexOf('has(') > -1) {
label = item.substring(4, item.indexOf(','))
}
}
})
return columnList.find(t => t.label.toLowerCase() === label.toLowerCase())
}