new seach algorithm in search, might remove trie :br:

remove searcterm from hoarder
move emojipackmanager
This commit is contained in:
neon443 committed 2026-03-15 02:24:04 +00:00
1 parent 9e2bb928ee
commit 06e15db8db
8 files changed
+52 -41

No files matched your search

+1 -1
View File
@@ -251,6 +251,7 @@
isa = PBXGroup;
children = (
A9D15B892EB1142C00404792 /* EmojiPack.swift */,
A9CD6C372EDDE37500B7F421 /* EmojiPackManager.swift */,
A935437A2EB2A3C800BB80A4 /* FilterCategory.swift */,
);
path = Categorisation;
@@ -293,7 +294,6 @@
A949B1D62EA04C0B00215164 = {
isa = PBXGroup;
children = (
A9CD6C372EDDE37500B7F421 /* EmojiPackManager.swift */,
A9E2ECD72EB74CE00038B2D6 /* Config.xcconfig */,
A949B1F22EA04E8200215164 /* StickerSlack */,
A9104C742EB3AE4700D160EA /* Resources */,
-2
View File
@@ -24,7 +24,6 @@ class EmojiHoarder: Hoarder, ObservableObject {
@Published var trie: Trie = Trie()
@Published var downloadedEmojis: Set<String> = []
@Published var downloadedEmojisArr: [String] = []
@Published var searchTerm: String = ""
@Published var letterStats: [EmojiHoarder.LetterStat] = []
@Published var letterStatsSorting: EmojiHoarder.LetterStatSorting = .init(by: .letter, ascending: true)
@@ -117,7 +116,6 @@ class EmojiHoarder: Hoarder, ObservableObject {
downloadedEmojisArr = []
UserDefaults.standard.removeObject(forKey: "downloadedEmojis")
UserDefaults.standard.removeObject(forKey: "downloadedEmojisArr")
searchTerm = ""
letterStats = []
}
-1
View File
@@ -15,7 +15,6 @@ protocol Hoarder {
var endpoint: URL { get }
var encoder: JSONEncoder { get }
var decoder: JSONDecoder { get }
var searchTerm: String { get set }
func download(emoji: Emoji, skipStoreIndex: Bool) async
func delete(emoji: Emoji, skipStoreIndex: Bool)
+8 -4
View File
@@ -11,6 +11,10 @@ import Haptics
struct EmojiRow: View {
@ObservedObject var hoarder: EmojiHoarder
@State var emoji: Emoji
var isLocal: Bool {
return hoarder.downloadedEmojis.contains(emoji.name)
}
var body: some View {
HStack {
@@ -24,12 +28,12 @@ struct EmojiRow: View {
.foregroundStyle(.gray.opacity(0.1))
Text(emoji.name)
.font(.caption)
.bold(hoarder.downloadedEmojis.contains(emoji.name))
.foregroundColor(hoarder.downloadedEmojis.contains(emoji.name) ? .green : .primary)
.bold(isLocal)
.foregroundColor(isLocal ? .green : .primary)
.padding(3)
}
.fixedSize()
if hoarder.downloadedEmojis.contains(emoji.name) {
if isLocal {
Image(systemName: "arrow.down.circle.fill")
.resizable().scaledToFit()
.frame(width: 20, height: 20)
@@ -41,7 +45,7 @@ struct EmojiRow: View {
Spacer()
if hoarder.downloadedEmojis.contains(emoji.name) {
if isLocal {
Button("", systemImage: "trash") {
hoarder.delete(emoji: emoji)
}
+13 -5
View File
@@ -10,18 +10,26 @@ import SwiftUI
struct SearchView: View {
@ObservedObject var hoarder: EmojiHoarder
@State var filterResult: [String] = []
@State var searchTerm: String = ""
@State var searchResult: [String] = []
var body: some View {
NavigationStack {
List(filterResult, id: \.self) { name in
List(searchResult, id: \.self) { name in
EmojiRow(hoarder: hoarder, emoji: hoarder.trie.dict[name]!)
}
.onChange(of: hoarder.searchTerm) { _ in
withAnimation(.snappy) { filterResult = hoarder.trie.search(prefix: hoarder.searchTerm) }
.onChange(of: searchTerm) { _ in
Task.detached(name: "emojiSearch", priority: .userInitiated) {
let result = await hoarder.trie.search(for: searchTerm)
await MainActor.run {
withAnimation(.snappy) {
searchResult = result
}
}
}
}
}
.searchable(text: $hoarder.searchTerm)
.searchable(text: $searchTerm)
}
}
+8
View File
@@ -41,6 +41,14 @@ class Trie: ObservableObject {
}
}
func search(for query: String) -> [String] {
var result: [String] = wordlist
for word in query.split(separator: " ") {
result = result.filter { $0.localizedCaseInsensitiveContains(word) }
}
return result
}
func search(exactly query: String) -> Bool {
var currentNode = root
+22 -28
View File
@@ -10,10 +10,9 @@ import SwiftUI
struct TrieTestingView: View {
@ObservedObject var hoarder: EmojiHoarder
@State var searchStatus: Bool? = nil
@State var filterTerm: String = ""
@State var filterResult: [String] = []
@State var searchTerm: String = ""
@State var searchResults: [String] = []
@State var exactSearchResult: Bool? = nil
@State var uikit: Bool = false
@@ -25,31 +24,26 @@ struct TrieTestingView: View {
}
private func runSearch() {
filterResult = []
searchStatus = nil
guard !filterTerm.isEmpty else { return }
searchResults = []
exactSearchResult = nil
guard !searchTerm.isEmpty else { return }
switch searchType {
case .trie:
withAnimation(.snappy) {
filterResult = hoarder.trie.search(prefix: filterTerm)
searchResults = hoarder.trie.search(prefix: searchTerm)
}
print("testing: trie search complete")
case .contains:
Task.detached {
var result: [String] = await hoarder.trie.wordlist
for word in await filterTerm.split(separator: " ") {
result = result.filter { $0.localizedCaseInsensitiveContains(word) }
}
let result = await hoarder.trie.search(for: searchTerm)
await MainActor.run {
withAnimation(.snappy) {
filterResult = result
}
withAnimation(.snappy) { searchResults = result }
print("testing: contains search complete")
}
}
case .exact:
withAnimation(.snappy) {
searchStatus = hoarder.trie.search(exactly: filterTerm)
exactSearchResult = hoarder.trie.search(exactly: searchTerm)
}
print("testing: exact search complete")
}
@@ -77,19 +71,19 @@ struct TrieTestingView: View {
}
}
.pickerStyle(.segmented)
.onChange(of: searchType.rawValue+filterTerm) { _ in
.onChange(of: searchType.rawValue+searchTerm) { _ in
runSearch()
}
if searchType == .exact {
HStack {
TextField("", text: $filterTerm)
TextField("", text: $searchTerm)
.textFieldStyle(.roundedBorder)
.border(.orange)
if let searchStatus {
if let exactSearchResult {
Circle()
.frame(width: 20, height: 20)
.foregroundStyle(searchStatus ? .green : .red)
.foregroundStyle(exactSearchResult ? .green : .red)
} else {
Text("?")
.frame(width: 20, height: 20)
@@ -99,32 +93,32 @@ struct TrieTestingView: View {
if searchType == .trie {
HStack {
TextField("", text: $filterTerm)
TextField("", text: $searchTerm)
.textFieldStyle(.roundedBorder)
.border(.orange)
Text("\(filterResult.count)")
Text("\(searchResults.count)")
.modifier(numericTextCompat())
}
}
if searchType == .contains {
HStack {
TextField("", text: $filterTerm)
TextField("", text: $searchTerm)
.textFieldStyle(.roundedBorder)
.border(.orange)
Text("\(filterResult.count)")
Text("\(searchResults.count)")
.modifier(numericTextCompat())
}
}
if uikit {
EmojiCollectionView(hoarder: hoarder, items: filterResult)
.animation(.snappy, value: filterResult)
EmojiCollectionView(hoarder: hoarder, items: searchResults)
.animation(.snappy, value: searchResults)
} else {
List(filterResult, id: \.self) { item in
List(searchResults, id: \.self) { item in
EmojiRow(hoarder: hoarder, emoji: hoarder.trie.dict[item]!)
}
.animation(.snappy, value: filterResult)
.animation(.snappy, value: searchResults)
}
Text("\(hoarder.trie.root.children.count)")
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.