PR #146 opened: Fix word-boundary search (RAG no longer matches "storage")
The bug
search, compare and neighborhood matched terms with title ILIKE '%term%' — pure substring. So searching RAG matched storage, average, coverage, leveraging — short/acronym queries were unusable (this is why "RAG" returned noise and errored).
The fix
New App\Support\SearchPattern::wordBoundary() builds a Postgres case-insensitive (~*) regex anchored with \m/\M (start/end of word) and escapes regex metacharacters. Applied to Search, Compare and Neighborhood (all four matching blocks each).
- Whole-word + phrase matches still work, including URL path segments (
/rag/still matches,/storage/doesn't). - Anchors are only added on the side that begins/ends with a word char, so
.NETandC++still match.
Tests
The SQL is Postgres-only and the suite runs on sqlite, so the matching logic is extracted and unit-tested in pure PHP (translating \m/\M → PCRE \b): confirms RAG no longer matches storage/average coverage/leveraging dragons, still matches real RAG mentions, handles phrases and metacharacters. 5 passing, lint clean.