add LIKE substring fallback to search and update plan statuses

FTS5 prefix matching misses mid-word substrings (e.g. "ebook" in
"notebook"). When FTS5 returns zero results, fall back to LIKE
query on title and category with proper wildcard escaping. 4 new
tests, 757 total.

Also marks completed plan files (search, admin-redesign,
setup-wizard, products-context) with correct status.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-13 09:09:10 +00:00
parent 57c3ba0e28
commit edcbc596e3
7 changed files with 78 additions and 15 deletions

View File

@@ -27,7 +27,11 @@ defmodule SimpleshopTheme.Search do
[]
else
fts_query = build_fts_query(query)
search_fts(fts_query)
case search_fts(fts_query) do
[] -> search_like(query)
results -> results
end
end
end
@@ -135,6 +139,26 @@ defmodule SimpleshopTheme.Search do
end
end
# Substring fallback when FTS5 prefix matching returns nothing
defp search_like(query) do
pattern = "%#{sanitize_like(query)}%"
Product
|> where([p], p.visible == true and p.status == "active")
|> where([p], like(p.title, ^pattern) or like(p.category, ^pattern))
|> order_by([p], p.title)
|> limit(20)
|> preload(^@listing_preloads)
|> Repo.all()
end
defp sanitize_like(input) do
input
|> String.replace("\\", "\\\\")
|> String.replace("%", "\\%")
|> String.replace("_", "\\_")
end
defp insert_into_index(%Product{} = product) do
Repo.query!(
"INSERT INTO products_search_map (product_id) VALUES (?1)",