Skip to content

Commit

Permalink
Use sqlite instr function for case-exact match
Browse files Browse the repository at this point in the history
  • Loading branch information
sholderbach committed Mar 26, 2024
1 parent 1a4fd0d commit b2682f3
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/history/sqlite_backed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,20 @@ impl SqliteBackedHistory {
};
if let Some(command_line) = &query.filter.command_line {
// TODO: escape %
let command_line_like = match command_line {
CommandLineSearch::Exact(e) => e.to_string(),
CommandLineSearch::Prefix(prefix) => format!("{prefix}*"),
CommandLineSearch::Substring(cont) => format!("*{cont}*"),
match command_line {
CommandLineSearch::Exact(e) => {
wheres.push("command_line == :command_line");
params.push((":command_line", Box::new(e)));
}
CommandLineSearch::Prefix(prefix) => {
wheres.push("instr(command_line, :command_line) == 1");
params.push((":command_line", Box::new(prefix)));
}
CommandLineSearch::Substring(cont) => {
wheres.push("instr(command_line, :command_line) >= 1");
params.push((":command_line", Box::new(cont)));
}
};
wheres.push("command_line glob :command_line");
params.push((":command_line", Box::new(command_line_like)));
}

if let Some(str) = &query.filter.not_command_line {
Expand Down

0 comments on commit b2682f3

Please sign in to comment.