From cbefa870439b7ebbb5ea9fa77ebafd38136eb06b Mon Sep 17 00:00:00 2001 From: qwertyyb Date: Wed, 5 Apr 2023 16:11:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8glob=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?like=E4=BC=98=E5=8C=96=E6=9F=A5=E8=AF=A2=E6=80=A7=E8=83=BD:=20g?= =?UTF-8?q?lob=E8=83=BD=E5=88=A9=E7=94=A8=E7=B4=A2=E5=BC=95=E4=BD=86?= =?UTF-8?q?=E6=98=AFlike=E4=B8=8D=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Fire/CandidatesView.swift | 2 +- Fire/DictManager.swift | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Fire/CandidatesView.swift b/Fire/CandidatesView.swift index ba0aad0..537604b 100644 --- a/Fire/CandidatesView.swift +++ b/Fire/CandidatesView.swift @@ -77,7 +77,7 @@ struct CandidatesView: View { @Environment(\.colorScheme) var colorScheme var _candidatesView: some View { - ForEach(Array(candidates.enumerated()), id: \.element) { (index, candidate) -> CandidateView in + ForEach(Array(candidates.enumerated()), id: \.offset) { (index, candidate) -> CandidateView in CandidateView( candidate: candidate, index: index, diff --git a/Fire/DictManager.swift b/Fire/DictManager.swift index 4fbab36..4daf5f4 100644 --- a/Fire/DictManager.swift +++ b/Fire/DictManager.swift @@ -50,7 +50,7 @@ class DictManager { text, type, min(query) as query from wb_py_dict - where query like :queryLike \( + where query glob :queryLike \( codeMode == .wubi ? "and type = 'wb'" : codeMode == .pinyin ? "and type = 'py'" : "") group by text @@ -120,20 +120,21 @@ class DictManager { } if !Defaults[.zKeyQuery] { - return origin + "%" + return origin + "*" } // z键查询,z不能放在首位 let first = origin.first! return String(first) + (String(origin.suffix(origin.count - 1)) - .replacingOccurrences(of: "z", with: "_")) + "%" + .replacingOccurrences(of: "z", with: "?")) + "*" } func getCandidates(query: String = String(), page: Int = 1) -> (candidates: [Candidate], hasNext: Bool) { if query.count <= 0 { return ([], false) } - NSLog("get local candidate, origin: \(query), query: ", query) + NSLog("[DictManager] getCandidates origin: \(query)") + let startTime = CFAbsoluteTimeGetCurrent() let queryLike = getQueryLike(query) var candidates: [Candidate] = [] sqlite3_reset(queryStatement) @@ -169,6 +170,8 @@ class DictManager { if candidates.isEmpty { candidates.append(Candidate(code: query, text: query, type: CandidateType.placeholder)) } + let duration = CFAbsoluteTimeGetCurrent() - startTime + NSLog("[DictManager] getCandidates query: \(query) , duration: \(duration)") return (candidates, hasNext: allCount > count) }