MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / plan_text_from_where

Function plan_text_from_where

nodedb-sql/src/planner/select/where_search.rs:148–191  ·  view source on GitHub ↗
(
    func: &ast::Function,
    table: &crate::resolver::columns::ResolvedTable,
    extra_filter: Option<&ast::Expr>,
)

Source from the content-addressed store, hash-verified

146}
147
148fn 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
193fn plan_vector_from_where(
194 name: &str,

Callers 1

dispatch_triggerFunction · 0.85

Calls 7

extract_func_argsFunction · 0.85
extra_filter_to_filtersFunction · 0.85
collectMethod · 0.80
to_stringMethod · 0.80
extract_string_literalFunction · 0.70
lenMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected