# fix(search): match hymns when searching with smart apostrophes or punctuation

**URL:** <https://forum.rodydavis.dev/t/fix-search-match-hymns-when-searching-with-smart-apostrophes-or-punctuation/301>\
**Category:** Issues & Bugs\
**Tags:** bug, migrated\
**Created:** [November 21, 2026, 5:37pm UTC](https://forum.rodydavis.dev/t/fix-search-match-hymns-when-searching-with-smart-apostrophes-or-punctuation/301 "2026-11-21T17:37:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://forum.rodydavis.dev/images/discourse-logo-sketch-small.png) [@system](https://forum.rodydavis.dev/u/system)\
**Post date:** [November 21, 2026, 5:37pm UTC](https://forum.rodydavis.dev/t/fix-search-match-hymns-when-searching-with-smart-apostrophes-or-punctuation/301/1 "2026-11-21T17:37:06Z")

</div>

### User Report

> I ran into an issue with the Hymns for Worship app - I was trying to find _I’m Not Ashamed to Own My Lord_. When searching “I’m not ashamed,” it doesn’t come up, but when searching “own my Lord,” it does.

### Root Cause

1. In `packages/hfw_core/lib/src/services/powersync/queries.dart`, `formatSearchQuery` strips all non-word punctuation (`replaceAll(RegExp(r"[^\w\s]"), "")`), turning `"I’m not ashamed"` (or even `"I'm not ashamed"`) into `%im%not%ashamed%`, which fails SQLite `LIKE` against `"I'm Not Ashamed to Own My Lord"` because the stored title still contains the apostrophe between `I` and `m`.
2. In lyrics search (`watchHymns` / `getHymnLyricsSnippets`), raw `cleanQ` and `tokens` keep iOS smart/curly apostrophes (`’`, `U+2019`), so `hp.lyrics LIKE '%i’m not ashamed%'` and `hp.lyrics LIKE '%i’m%'` only match lyrics stored with curly `’` (like #22231) and miss hymns stored with straight ASCII `'` (like #273).
3. `SearchRanker` in `packages/hfw_flutter/lib/services/search/search_ranker.dart` compares `lowerRaw` directly against `title` / `lyricSnippet` without normalizing smart apostrophes/quotes or punctuation.

### Expected Behavior

Searching `"I’m not ashamed"`, `"I'm not ashamed"`, or `"im not ashamed"` should consistently find and rank `#273 I'm Not Ashamed to Own My Lord` as well as hymns stored with either straight or curly apostrophes.

---

<div class="post-metadata">

**Author:** ![rodydavis](https://forum.rodydavis.dev/user_avatar/forum.rodydavis.dev/rodydavis/32/8_2.png) [@rodydavis](https://forum.rodydavis.dev/u/rodydavis)\
**Post date:** [November 21, 2026, 5:48pm UTC](https://forum.rodydavis.dev/t/fix-search-match-hymns-when-searching-with-smart-apostrophes-or-punctuation/301/2 "2026-11-21T17:48:42Z")

</div>

Implemented apostrophe- and punctuation-insensitive search normalization across SQLite queries, snippet extraction, and ranking:

- Added `packages/hfw_core/lib/src/utils/search_text_utils.dart` (`normalizeSmartQuotes`, `normalizeSearchText`, `tokenizeSearchQuery`, `formatSearchQuery`, `sqlStripApostrophes`, `findNormalizedMatchSpan`) and exported it from `hfw_core`.
- Updated `packages/hfw_core/lib/src/services/powersync/queries.dart` (`watchHymns`, `getHymnLyricsSnippets`, `_extractSnippet`, and catalog/list/index search queries) to strip straight and curly apostrophes (`'`, `’`, `‘`) in SQLite `LIKE` comparisons and normalize queries/tokens.
- Updated `SearchRanker` (`packages/hfw_flutter/lib/services/search/search_ranker.dart`) and list search filtering (`packages/hfw_flutter/lib/src/native_bridge/hfw_headless_coordinator.dart`) to use `normalizeSearchText` and `tokenizeSearchQuery`.
- Added unit & SQLite integration tests in `packages/hfw_core/test/utils/search_text_utils_test.dart` and `packages/hfw_flutter/test/services/search/search_ranker_test.dart` covering `i’m not ashamed`, `i'm not ashamed`, `im not ashamed`, `I’m not ashamed,`, and comma-separated titles.

---

<div class="post-metadata">

**Author:** ![rodydavis](https://forum.rodydavis.dev/user_avatar/forum.rodydavis.dev/rodydavis/32/8_2.png) [@rodydavis](https://forum.rodydavis.dev/u/rodydavis)\
**Post date:** [November 21, 2026, 6:34pm UTC](https://forum.rodydavis.dev/t/fix-search-match-hymns-when-searching-with-smart-apostrophes-or-punctuation/301/3 "2026-11-21T18:34:31Z")

</div>

### Test Verification

Verified the uncommitted local search normalization changes via read-only test runs:

- `packages/hfw_core`: `dart test test/utils/search_text_utils_test.dart` — **10/10 passed** (covers `normalizeSmartQuotes`, `normalizeSearchText`, `tokenizeSearchQuery`, `formatSearchQuery`, `findNormalizedMatchSpan`, and SQLite `PowerSyncQueryX` integration for `i’m not ashamed`, `i'm not ashamed`, `im not ashamed`, `I’m not ashamed,`, and comma-separated titles).
- `packages/hfw_flutter`: `flutter test test/services/search/search_ranker_test.dart` — **12/12 passed** (including smart, straight, and omitted apostrophe ranking parity).

Ready to commit/push to `main` and close.

---

<div class="post-metadata">

**Author:** ![system](https://forum.rodydavis.dev/images/discourse-logo-sketch-small.png) [@system](https://forum.rodydavis.dev/u/system)\
**Post date:** [November 28, 2026, 12:59am UTC](https://forum.rodydavis.dev/t/fix-search-match-hymns-when-searching-with-smart-apostrophes-or-punctuation/301/4 "2026-11-28T00:59:06Z")

</div>

Closed on November 28, 2026, 12:59am UTC


