pub fn parse_fuzzy_query(query: &str) -> Vec<FuzzyMatch<'_>>
Expand description
Parses a fuzzy search query string into a vector of FuzzyMatch
items.
The query is split by spaces. Terms are implicitly ANDed.
A |
token acts as an OR operator, grouping the term before it with the terms after it until the next non-OR term
or end of query.
ยงExamples
assert_eq!(
parse_fuzzy_query("foo bar"),
vec![
FuzzyMatch::Term(FuzzyTerm { kind: FuzzyTermKind::Fuzzy, term: "foo" }),
FuzzyMatch::Term(FuzzyTerm { kind: FuzzyTermKind::Fuzzy, term: "bar" }),
]
);
assert_eq!(
parse_fuzzy_query("foo | bar"),
vec![FuzzyMatch::Or(vec![
FuzzyTerm { kind: FuzzyTermKind::Fuzzy, term: "foo" },
FuzzyTerm { kind: FuzzyTermKind::Fuzzy, term: "bar" },
])],
);
assert_eq!(
parse_fuzzy_query("^core go$ | rb$ | py$"),
vec![
FuzzyMatch::Term(FuzzyTerm { kind: FuzzyTermKind::PrefixExact, term: "core" }),
FuzzyMatch::Or(vec![
FuzzyTerm { kind: FuzzyTermKind::SuffixExact, term: "go" },
FuzzyTerm { kind: FuzzyTermKind::SuffixExact, term: "rb" },
FuzzyTerm { kind: FuzzyTermKind::SuffixExact, term: "py" },
]),
]
);