hezarfen_backend
Clone
https://git.tahinli.com/archive/hezarfen_backend.git
0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits
| 1 | //! Two different folds, for two different jobs — never swap them: |
| 2 | //! |
| 3 | //! * [`search_fold`] / [`search_fold_sql`] are the **search** fold: |
| 4 | //! deliberately *destructive*, collapsing `ı ş ğ ç ö ü â î û` onto their |
| 5 | //! ASCII bases so a teacher on an ASCII keyboard still finds accented data. |
| 6 | //! * [`case_fold_tr`] is the **identity** fold: Turkish-correct case folding |
| 7 | //! only. It answers "are these two entries the same word?" and must never |
| 8 | //! conflate distinct letters (`tur` ≠ `tür`, `kir` ≠ `kır`). |
| 9 | //! |
| 10 | //! The search fold is shared by the needle (Rust side) and the column |
| 11 | //! (PostgreSQL side) so the two can never disagree. |
| 12 | //! |
| 13 | //! Rust's `to_lowercase` and PostgreSQL's `lower()` are both |
| 14 | //! locale-invariant here: Turkish `İ` (U+0130) lowercases to `i` + U+0307 |
| 15 | //! (combining dot above), so plain `lower(text) LIKE '%q%'` never matched |
| 16 | //! `İSTANBUL` for a teacher who typed `istanbul`. Folding strips that |
| 17 | //! leftover dot and maps the Turkish letters onto their ASCII base, which also |
| 18 | //! makes the search work in both directions (`istanbul` ↔ `İSTANBUL`, |
| 19 | //! `ıgdır` ↔ `Iğdır`). |
| 20 | |
| 21 | use crateTEXT_FOLD_REPLACEMENTS; |
| 22 | |
| 23 | /// Fold a search needle (or any Rust-side string) for comparison. **Search |
| 24 | /// only** — this is lossy, `tür` and `tur` both fold to `tur`. For "is this |
| 25 | /// the same word?" use [`case_fold_tr`]. |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | /// The same folding as a PostgreSQL expression over `column`, for use inside |
| 35 | /// a `WHERE`. `column` is always a literal field name we wrote — never user |
| 36 | /// input. |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | /// Case-fold under the **Turkish** casing rule, for identity comparisons |
| 46 | /// (list dedup). Only the two dotted/dotless pairs are folded together — |
| 47 | /// `i` ↔ `İ` and `ı` ↔ `I` — so `TÜR` and `tür` are one word while `tur` and |
| 48 | /// `tür` stay two. Never use this for search: it will not match an ASCII |
| 49 | /// spelling of an accented word (that is [`search_fold`]'s job). |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 |