Skip to content

fix: precise 規則的讀取順序被 rule_str 排序打亂了 - #40

Open
chiakich wants to merge 1 commit into
moskytw:devfrom
chiakich:fix/precise-rule-order
Open

fix: precise 規則的讀取順序被 rule_str 排序打亂了#40
chiakich wants to merge 1 commit into
moskytw:devfrom
chiakich:fix/precise-rule-order

Conversation

@chiakich

@chiakich chiakich commented Aug 12, 2026

Copy link
Copy Markdown

@moskytw 感謝您製作的套件,多年以來一直使用,受益良多,非常感謝!但最近發現一個 bug:

問題

get_rule_str_zipcode_pairs() 查詢沒有 order by,SQLite 因此透過 (addr_str, rule_str) 主鍵索引取列,等於照 rule_str 字碼排序。但 find() 是 first-match-wins,規則順序即比對優先序,跟字碼順序無關。

這種整條路的 catch-all 字碼排序會排在 // 之前,於是蓋掉本來要墊底的窄範圍規則:

臺北市中正區三樹路291號 -> 應為 237641(單245號至291號),實得 237012(全)

這應該跟 #17 當年回報的是同一個 bug(興大路145號 答成整區碼),只是被誤診為個案。

修法

select ... order by rowidprecise 是一般 rowid table 靠 insert or ignore 灌入,rowid 即 CSV 列序,也就是中華郵政資料本身「特例在前、全在後」的順序。

測試

TestDirectory 的 CSV fixture 加了一段可重現此問題的測試街道,並新增 test_find_prefers_narrower_rule_over_catch_all。還原修正可讓新測試失敗,套用後通過,已手動驗證。

@chiakich
chiakich force-pushed the fix/precise-rule-order branch from 53f40d2 to 81a14a2 Compare August 12, 2026 02:23
@chiakich chiakich changed the title fix: precise 規則要照 CSV 原始順序讀,不要照 rule_str 排序 fix: precise 規則的讀取順序被 rule_str 排序打亂了 Aug 12, 2026
@chiakich
chiakich force-pushed the fix/precise-rule-order branch 2 times, most recently from c522f0f to 3346834 Compare August 12, 2026 02:29
@chiakich
chiakich force-pushed the fix/precise-rule-order branch from 3346834 to 810a2b3 Compare August 12, 2026 02:32
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

Successfully merging this pull request may close these issues.

1 participant