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

Function parse_tsquery

nodedb-sql/src/functions/fts_ops/tsquery_parser.rs:27–46  ·  view source on GitHub ↗

Parse a PG `tsquery` string into an `FtsQuery` tree. Empty input is rejected with `SqlError::Parse`.

(input: &str)

Source from the content-addressed store, hash-verified

25///
26/// Empty input is rejected with `SqlError::Parse`.
27pub fn parse_tsquery(input: &str) -> Result<FtsQuery> {
28 let input = input.trim();
29 if input.is_empty() {
30 return Err(SqlError::Parse {
31 detail: "tsquery: empty query string".into(),
32 });
33 }
34 let tokens = tokenize(input);
35 let mut pos = 0;
36 let query = parse_or(&tokens, &mut pos)?;
37 if pos < tokens.len() {
38 return Err(SqlError::Parse {
39 detail: format!(
40 "tsquery: unexpected token '{}' at position {pos}",
41 tokens[pos]
42 ),
43 });
44 }
45 Ok(query)
46}
47
48/// Build an `FtsQuery::Phrase` from whitespace-separated terms.
49///

Callers 8

parse_single_termFunction · 0.85
parse_and_two_termsFunction · 0.85
parse_or_two_termsFunction · 0.85
parse_prefixFunction · 0.85
parse_nestedFunction · 0.85
parse_not_termFunction · 0.85
and_is_left_associativeFunction · 0.85
or_is_left_associativeFunction · 0.85

Calls 4

tokenizeFunction · 0.70
parse_orFunction · 0.70
is_emptyMethod · 0.45
lenMethod · 0.45

Tested by 8

parse_single_termFunction · 0.68
parse_and_two_termsFunction · 0.68
parse_or_two_termsFunction · 0.68
parse_prefixFunction · 0.68
parse_nestedFunction · 0.68
parse_not_termFunction · 0.68
and_is_left_associativeFunction · 0.68
or_is_left_associativeFunction · 0.68