Intercept PG FTS surface functions and lower them to `pg_*` internal function-call `SqlExpr` nodes. Returns `Ok(None)` for non-FTS names. `ts_rank_cd` is rejected with `SqlError::Unsupported` as per the approved design.
(
name: &str,
func: &ast::Function,
depth: &mut usize,
)
| 96 | /// `ts_rank_cd` is rejected with `SqlError::Unsupported` as per the |
| 97 | /// approved design. |
| 98 | fn intercept_fts_function( |
| 99 | name: &str, |
| 100 | func: &ast::Function, |
| 101 | depth: &mut usize, |
| 102 | ) -> Result<Option<SqlExpr>> { |
| 103 | use crate::functions::fts_ops::pg_fts_funcs; |
| 104 | |
| 105 | let args = collect_function_args(func, depth)?; |
| 106 | match name { |
| 107 | "to_tsvector" => Ok(Some(SqlExpr::Function { |
| 108 | name: "pg_to_tsvector".into(), |
| 109 | args, |
| 110 | distinct: false, |
| 111 | })), |
| 112 | "to_tsquery" => Ok(Some(pg_fts_funcs::lower_pg_to_tsquery(args))), |
| 113 | "plainto_tsquery" => Ok(Some(pg_fts_funcs::lower_pg_plainto_tsquery(args))), |
| 114 | "phraseto_tsquery" => Ok(Some(pg_fts_funcs::lower_phraseto_tsquery(args))), |
| 115 | "websearch_to_tsquery" => Ok(Some(pg_fts_funcs::lower_pg_websearch_to_tsquery(args))), |
| 116 | "ts_rank" => Ok(Some(SqlExpr::Function { |
| 117 | name: "pg_ts_rank".into(), |
| 118 | args, |
| 119 | distinct: false, |
| 120 | })), |
| 121 | "ts_rank_cd" => Err(SqlError::Unsupported { |
| 122 | detail: "ts_rank_cd is not supported; use ts_rank or bm25_score instead".into(), |
| 123 | }), |
| 124 | "ts_headline" => Ok(Some(SqlExpr::Function { |
| 125 | name: "pg_ts_headline".into(), |
| 126 | args, |
| 127 | distinct: false, |
| 128 | })), |
| 129 | _ => Ok(None), |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | /// Collect function call arguments, converting each `Expr` to `SqlExpr`. |
| 134 | fn collect_function_args(func: &ast::Function, depth: &mut usize) -> Result<Vec<SqlExpr>> { |
no test coverage detected