add FTS5 full-text product search

Adds SQLite FTS5 search index with BM25 ranking across product title,
category, variant attributes, and description. Search modal now has
live results with thumbnails, prices, and click-to-navigate. Index
rebuilds automatically after each provider sync.

Also fixes Access syntax on Product/ProductImage structs (Map.get
instead of bracket notation) which was causing crashes when real
products were loaded from the database.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-13 07:29:19 +00:00
parent 35e0386abb
commit 037cd168cd
19 changed files with 603 additions and 34 deletions

View File

@@ -0,0 +1,29 @@
defmodule SimpleshopTheme.Repo.Migrations.CreateProductsSearch do
use Ecto.Migration
def up do
# Rowid mapping (FTS5 needs integer rowids, products use UUIDs)
execute """
CREATE TABLE products_search_map (
rowid INTEGER PRIMARY KEY AUTOINCREMENT,
product_id TEXT NOT NULL UNIQUE
)
"""
# FTS5 virtual table — stores its own content for simple delete/reindex
execute """
CREATE VIRTUAL TABLE products_search USING fts5(
title,
category,
variant_info,
description,
tokenize='unicode61 remove_diacritics 2'
)
"""
end
def down do
execute "DROP TABLE IF EXISTS products_search"
execute "DROP TABLE IF EXISTS products_search_map"
end
end