(
func: &ast::Function,
table: &crate::resolver::columns::ResolvedTable,
extra_filter: Option<&ast::Expr>,
)
| 146 | } |
| 147 | |
| 148 | fn plan_text_from_where( |
| 149 | func: &ast::Function, |
| 150 | table: &crate::resolver::columns::ResolvedTable, |
| 151 | extra_filter: Option<&ast::Expr>, |
| 152 | ) -> Result<Option<SqlPlan>> { |
| 153 | use crate::fts_types::FtsQuery; |
| 154 | |
| 155 | let args = extract_func_args(func)?; |
| 156 | if args.len() < 2 { |
| 157 | return Ok(None); |
| 158 | } |
| 159 | let query_text = extract_string_literal(&args[1])?; |
| 160 | |
| 161 | // Detect a phrase query: query_text surrounded by double-quotes. |
| 162 | // SQL form: `text_match(body, '"quick brown fox"')`. |
| 163 | // The outer SQL single-quotes are stripped by the SQL parser; the |
| 164 | // inner double-quotes are literal characters in the string value. |
| 165 | let fts_query = |
| 166 | if query_text.starts_with('"') && query_text.ends_with('"') && query_text.len() > 2 { |
| 167 | let inner = &query_text[1..query_text.len() - 1]; |
| 168 | let terms: Vec<String> = inner.split_whitespace().map(|s| s.to_string()).collect(); |
| 169 | if terms.len() > 1 { |
| 170 | FtsQuery::Phrase(terms) |
| 171 | } else { |
| 172 | FtsQuery::Plain { |
| 173 | text: inner.to_string(), |
| 174 | fuzzy: true, |
| 175 | } |
| 176 | } |
| 177 | } else { |
| 178 | FtsQuery::Plain { |
| 179 | text: query_text, |
| 180 | fuzzy: true, |
| 181 | } |
| 182 | }; |
| 183 | |
| 184 | Ok(Some(SqlPlan::TextSearch { |
| 185 | collection: table.name.clone(), |
| 186 | query: fts_query, |
| 187 | top_k: 1000, |
| 188 | filters: extra_filter_to_filters(extra_filter)?, |
| 189 | score_alias: None, |
| 190 | })) |
| 191 | } |
| 192 | |
| 193 | fn plan_vector_from_where( |
| 194 | name: &str, |
no test coverage detected