Skip to main content

nodedb_sql/functions/fts_ops/
pg_fts_funcs.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Lowering helpers for PG full-text search surface operators.
4//!
5//! These functions are called from `resolver/expr.rs` to lower PG FTS
6//! operators/casts to internal `SqlExpr::Function` nodes before the generic
7//! expression lowering path runs.
8
9use crate::types_expr::SqlExpr;
10
11/// Lower `col @@ query_expr` to `pg_fts_match(col, query_expr)`.
12pub fn lower_pg_fts_match(col: SqlExpr, query_expr: SqlExpr) -> SqlExpr {
13    SqlExpr::Function {
14        name: "pg_fts_match".into(),
15        args: vec![col, query_expr],
16        distinct: false,
17    }
18}
19
20/// Lower `to_tsquery('...')` / `to_tsquery(lang, '...')` args.
21///
22/// The caller (resolver) has already converted the function args; this just
23/// wraps them in a `pg_to_tsquery` function call.
24pub fn lower_pg_to_tsquery(args: Vec<SqlExpr>) -> SqlExpr {
25    SqlExpr::Function {
26        name: "pg_to_tsquery".into(),
27        args,
28        distinct: false,
29    }
30}
31
32/// Lower `plainto_tsquery('...')` / `plainto_tsquery(lang, '...')` args.
33pub fn lower_pg_plainto_tsquery(args: Vec<SqlExpr>) -> SqlExpr {
34    SqlExpr::Function {
35        name: "pg_plainto_tsquery".into(),
36        args,
37        distinct: false,
38    }
39}
40
41/// Lower `phraseto_tsquery('...')` args.
42///
43/// The resulting `pg_phraseto_tsquery` call is evaluated by the executor
44/// to `FtsQuery::Phrase`, which is then rejected with `Unsupported`.
45pub fn lower_phraseto_tsquery(args: Vec<SqlExpr>) -> SqlExpr {
46    SqlExpr::Function {
47        name: "pg_phraseto_tsquery".into(),
48        args,
49        distinct: false,
50    }
51}
52
53/// Lower `websearch_to_tsquery('...')` / `websearch_to_tsquery(lang, '...')` args.
54pub fn lower_pg_websearch_to_tsquery(args: Vec<SqlExpr>) -> SqlExpr {
55    SqlExpr::Function {
56        name: "pg_websearch_to_tsquery".into(),
57        args,
58        distinct: false,
59    }
60}