Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] search CJK characters #276

Open
swifterslb opened this issue Jan 8, 2025 · 1 comment
Open

[Feature request] search CJK characters #276

swifterslb opened this issue Jan 8, 2025 · 1 comment

Comments

@swifterslb
Copy link

Official Telegram doesn't support searching for CJK (Chinese, Japanese and Korean) characters. This is very inconvenient. Swiftgram has realized this function. Is it possible to implement it in Forkgram? Thanks!

@Crystal-RainSlide
Copy link

Crystal-RainSlide commented Jan 16, 2025

I took a look within the changes made to offical iOS version in version 11.5.3 of Swiftgram. It's not a specifc CJK character searching support, but a local message searching fallback, which only happens when there is a "no result found" from Telegram server.

Instead of doesn't support CJK, offical Telegram kind of like only support searching the words of Latin-like languages, it don't work for partial matching for any language that are written without words and spaces.

On the other side, a program language's "local search", like text.contains(query), is mostly just plain text matching, which almost always works to some extent (as long as there isn't any nasty Unicode stuff):

https://github.com/Swiftgram/Telegram-iOS/blob/7d4b4eaf6cf4cffaf328a8edf2e161e0de180795/submodules/TelegramCore/Sources/TelegramEngine/Messages/SearchMessages.swift#L330-L347

                    // MARK: Swiftgram
                    var result: [Message] = []
                    if forceLocal {
                        transaction.withAllMessages(peerId: peerId, reversed: true, { message in
                            if result.count >= limit {
                                return false
                            }
                            if let tags = tags, message.tags != tags {
                                return true
                            }
                            if message.text.contains(query) {
                                result.append(message)
                            }
                            return true
                        })
                    } else {
                        result = transaction.searchMessages(peerId: peerId, query: query, tags: tags)
                    }

This is a good addition even if it only support local messages.

However, since full-text matching still works, when the Telegram server actually returns some message(s) from the full-text matching (when result.0.totalCount > 0 is true), then Swiftgram won't trigger the local searching:

https://github.com/Swiftgram/Telegram-iOS/blob/7d4b4eaf6cf4cffaf328a8edf2e161e0de180795/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift#L79-L85

            // TODO(swiftgram): Try to fallback on error when searching. RX is hard...
            |> mapToSignal { result -> Signal<(SearchMessagesResult, SearchMessagesState), NoError> in
                if (result.0.totalCount > 0) {
                    return .single(result)
                }
                return _internal_searchMessages(account: self.account, location: location, query: query, state: state, centerId: centerId, limit: limit, forceLocal: true)
            }

So, other than the local search feature itself, a "Local Search" toggle (or anything like that) is also needed to make it accessible, to make it a finished feature. Instead of only do local search when Telegram server search returns no result.

(Open Swiftgram/Telegram-iOS@7d4b4ea on PC, then search forceLocal: in the top right commit search box to locate those changes yourself.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants