|
1
|
/** |
|
2
|
* Native engine (default): |
|
3
|
* - Built-in `tsvector` / `tsquery` |
|
4
|
* - `pg_trgm` — typo tolerance |
|
5
|
* - `unaccent` — accent folding via `medusa_search_<language>` text search config |
|
6
|
* |
|
7
|
* Lakebase engine — Medusa Cloud only (PG16+): |
|
8
|
* - `lakebase_text` — BM25 via `lakebase_bm25` |
|
9
|
* - `lakebase_vector` — ANN via `lakebase_ann` (CASCADE installs `vector`) |
|
10
|
* |
|
11
|
* The provider migration creates `pg_trgm`, `unaccent`, the default |
|
12
|
* `medusa_search_english` config, and — on engines that ship them — |
|
13
|
* `lakebase_vector` / `lakebase_text` via `CREATE EXTENSION ... CASCADE`. |
|
14
|
* Custom languages need a matching `medusa_search_<language>` configuration. |
|
15
|
*/ |
|
16
|
|
|
17
|
export function textSearchConfigName(language: string): string { |
|
18
|
return `medusa_search_${language}` |
|
19
|
} |
|
20
|
|
|
21
|
/** |
|
22
|
* `word_similarity(query, text)` from pg_trgm. Unlike plain `similarity`, it |
|
23
|
* compares the query against the best-matching word sequence in the document |
|
24
|
* text, so long documents don't dilute the score. |
|
25
|
*/ |
|
26
|
export function wordSimilarityCall(querySql: string, textSql: string): string { |
|
27
|
return `word_similarity(${querySql}, ${textSql})` |
|
28
|
} |