Skip to content

Commit

Permalink
feat: 适配单英文、字母或英文+字母场景下搜索匹配规则为 LIKE
Browse files Browse the repository at this point in the history
Signed-off-by: Dylan <[email protected]>
  • Loading branch information
nmgwddj committed Aug 4, 2021
1 parent 8c83bde commit 2bd1ddb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
22 changes: 10 additions & 12 deletions example/domAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ window.onload = (function () {
const text = $keyword.value || undefined
const number = $number.value
if (!number) {
alert('请输入写入的条数')
console.log('请输入写入的条数')
return
}
if (window.test) {
Expand All @@ -49,7 +49,7 @@ window.onload = (function () {
let start = $('#q-start').value
let end = $('#q-end').value
// if (!text && !sessionIds && !froms) {
// alert('请输入查询的 关键字 或 sessionId 或 froms')
// console.log('请输入查询的 关键字 或 sessionId 或 froms')
// return
// }
start = start
Expand Down Expand Up @@ -79,32 +79,30 @@ window.onload = (function () {
.then((res) => {
const _end = performance.now()
console.log(TAG_NAME, `查询成功,耗时: ${_end - _start} ms`, res)
alert(`查询成功,耗时: ${_end - _start} ms`)
})
.catch((err) => {
console.error(TAG_NAME, '查询失败:', err)
alert('查询失败')
})
}
}
// 根据idClient查询
else if (hasClass(target, 'j-query-indexdb')) {
const value = $('#q-idClient').value
if (!value) {
alert('请输入要查询的idClient')
console.log('请输入要查询的idClient')
return
}
if (window.test) {
window.test.readByPrimary(value)
// alert('查询成功')
// console.log('查询成功')
}
}
// 发送
else if (hasClass(target, 'j-send')) {
const $keyword = $('#s-keyword')
const value = $keyword.value
if (!value) {
alert('请输入要发送的消息内容')
console.log('请输入要发送的消息内容')
return
}
window.nim &&
Expand All @@ -116,7 +114,7 @@ window.onload = (function () {
if (err) return
// 发送失败的时候可能无 idClient
if (!obj.idClient) return
alert('发送成功')
console.log('发送成功')
},
})
}
Expand All @@ -126,18 +124,18 @@ window.onload = (function () {
window.nim
.clearAllFts()
.then(() => {
alert('清空成功')
console.log('清空成功')
})
.catch(() => {
alert('清空失败!')
console.log('清空失败!')
})
} else if (hasClass(target, 'j-drop')) {
window.nim && window.nim.dropAllFts()
.then(() => {
alert('删除所有表并重建成功')
console.log('删除所有表并重建成功')
})
.catch(() => {
alert('操作失败!')
console.log('操作失败!')
})
}
// 同步消息
Expand Down
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h3>根据关键字全文搜索 queryFts</h3>
<span>关键字</span>
<input id="q-keyword" type="text" placeholder="关键字" />
<span>分词逻辑</span>
<input id="q-option" type="number" placeholder="分词逻辑" />
<input id="q-option" type="number" min="0" max="5" placeholder="分词逻辑" value="0" />
</div>
<div>
<span>sessionIds</span>
Expand Down
2 changes: 1 addition & 1 deletion example/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ NIM.getInstance({
// }
},
onerror() {
// alert(JSON.stringify(event))
// console.log(JSON.stringify(event))
// debugger
console.error(TAG_NAME, 'error')
// location.href = config.loginUrl
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@
"just-scripts": "^1.5.4",
"sqlite3": "^5.0.2"
}
}
}
13 changes: 10 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,17 @@ const fullText = (NimSdk: any) => {
}: IQueryParams): string {
const where: string[] = []
if (text) {
const matchRegex = new RegExp(/^[0-9a-zA-Z]+$/)
const queryText = this.formatSQLText(text)
where.push(
`\`text\` MATCH query('${queryText}', ${queryOption}, ${this.enablePinyin})`
)
if (matchRegex.test(text)) {
where.push(
`\`text\` LIKE '%${text}%'`
)
} else {
where.push(
`\`text\` MATCH query('${queryText}', ${queryOption}, ${this.enablePinyin})`
)
}
}
if (sessionIds && sessionIds.length > 0) {
const temp = sessionIds.map((id: string) => `'${id}'`).join(',')
Expand Down

0 comments on commit 2bd1ddb

Please sign in to comment.