diff --git a/StickerSlack/SwiftUI/SearchView.swift b/StickerSlack/SwiftUI/SearchView.swift index 214398d..74afd8b 100644 --- a/StickerSlack/SwiftUI/SearchView.swift +++ b/StickerSlack/SwiftUI/SearchView.swift @@ -34,15 +34,15 @@ struct SearchView: View { if currentSearch != nil { withAnimation { currentSearch?.cancel() } } - currentSearch = Task { - let result = await hoarder.trie.search(for: searchTerm) +// currentSearch = Task { + let result = hoarder.trie.search(for: searchTerm) guard !Task.isCancelled else { return } - await MainActor.run { +// await MainActor.run { withAnimation(.snappy) { searchResult = result } - } - } +// } +// } } } } diff --git a/StickerSlack/Trie/Trie.swift b/StickerSlack/Trie/Trie.swift index b1c9649..f41fb10 100644 --- a/StickerSlack/Trie/Trie.swift +++ b/StickerSlack/Trie/Trie.swift @@ -18,11 +18,12 @@ class Trie: ObservableObject { var root: TrieNode = TrieNode() var dict: [String:Emoji] = [:] - var wordlist: [String] = [] + var wordlist: Set = [] +// var previousSearchTerm func insert(word: String) { let word = word.lowercased() - wordlist.append(word) + wordlist.insert(word) var currentNode = root let indices = word.indices let last = indices.last @@ -42,7 +43,7 @@ class Trie: ObservableObject { } func search(for query: String) -> [String] { - var result: Set = Set(wordlist) + var result: Set = wordlist for word in query.split(separator: " ") { result = result.filter { $0.localizedCaseInsensitiveContains(word) } }