Search returns no results for non-Latin (Cyrillic/CJK/Greek) queries #3042
Replies: 1 comment
|
Diagnosis is right and On SQLite the two lines really are the whole fix. scope :matching, ->(query, account_id) {
joins("INNER JOIN search_records_fts ON search_records_fts.rowid = #{table_name}.id")
.where("search_records_fts MATCH ?", query)
}The migration builds the table with Trilogy is a different story, because the stemmer runs at write time there. before_save :set_account_key, :stem_contentdef stem_content
self.title = Search::Stemmer.stem(title) if title_changed?
self.content = Search::Stemmer.stem(content) if content_changed?
endSo the same ASCII The other thing I'd separate out is CJK, because the regex doesn't fix it on MySQL at all. The fulltext indexes are plain: t.index [:content, :title], type: :fulltextwith no None of that argues against #2928, it's still the right first move. It would just land better as "fixes space-delimited non-Latin scripts on SQLite, plus a reindex for Trilogy, CJK on MySQL tracked separately" than as a general non-Latin fix, since the current framing promises more than the patch can deliver on the MySQL path. |
Uh oh!
There was an error while loading. Please reload this page.
Search and filter return zero results for any query containing non-Latin characters — Cyrillic (Ukrainian, Russian), CJK, Greek, Arabic and so on — even when matching cards clearly exist. Latin queries work fine, so the failure is easy to mistake for "nothing matched".
Root cause
Search::Query#remove_invalid_search_characterssanitises input withterms.gsub(/[^\w"]/, " "). In Ruby (Onigmo)\wmatches ASCII[a-zA-Z0-9_]only — it does not match Unicode letters. A non-Latin query is therefore reduced to whitespace,termsbecomes blank,Search::Queryfails itspresencevalidation, andSearch::Record.for_queryfalls through toelse none— no results.The FTS index itself is fine: non-Latin content is indexed and a raw
MATCHfinds it. The bug is purely in query sanitisation, which is why it affects both the SQLite and Trilogy adapters.Suggested fix
Use the POSIX
[[:word:]]class, which is Unicode-aware in Ruby:The same ASCII-only
\wappears inSearch::Stemmer.stem, used on the Trilogy/MySQL path for both indexing and querying.Status
I opened #2928 back in June with this change plus a Cyrillic test case mirroring the existing hyphenated-string test — it fails on
mainand passes with the change. I've since read CONTRIBUTING and understand a discussion is the right entry point, so I'm raising it here properly.Happy to close the PR if you'd rather approach this differently, or to adjust it — the patch is two lines plus a test, and it currently merges cleanly.
For context on why this matters beyond my own use: any team writing card titles in a non-Latin script currently has search silently return nothing, with no error to explain why.
All reactions