feat(command-palette): implement frecency ranking for command palette

This commit adds a "frecency" (frequency + recency) based ranking algorithm to the command palette. By tracking the usage of commands, applications, and quicklinks, we can provide more useful results when paired with the search score. It prioritizes recently used items, which are likely more relevant for the user. A new `FrecencyManager` was added to the Rust backend to handle usage tracking in a dedicated SQLite database. The `CommandPalette.svelte` component now fetches this data and computes a dynamic score for each item to determine its rank in the list.
This commit is contained in:
ByteAtATime 2025-06-24 09:25:16 -07:00
parent fe4ce3c5be
commit 06f823873c
No known key found for this signature in database
5 changed files with 226 additions and 48 deletions

View file

@ -7,12 +7,14 @@ mod desktop;
mod error;
mod extensions;
mod filesystem;
mod frecency;
mod oauth;
mod quicklinks;
mod system;
use crate::{app::App, cache::AppCache};
use browser_extension::WsState;
use frecency::FrecencyManager;
use quicklinks::QuicklinkManager;
use selection::get_text;
use std::process::Command;
@ -94,6 +96,20 @@ async fn show_hud(app: tauri::AppHandle, title: String) -> Result<(), String> {
Ok(())
}
#[tauri::command]
fn record_usage(app: tauri::AppHandle, item_id: String) -> Result<(), String> {
app.state::<FrecencyManager>()
.record_usage(item_id)
.map_err(|e| e.to_string())
}
#[tauri::command]
fn get_frecency_data(app: tauri::AppHandle) -> Result<Vec<frecency::FrecencyData>, String> {
app.state::<FrecencyManager>()
.get_frecency_data()
.map_err(|e| e.to_string())
}
fn setup_background_refresh() {
thread::spawn(|| {
thread::sleep(Duration::from_secs(60));
@ -197,7 +213,9 @@ pub fn run() {
system::get_default_application,
system::get_frontmost_application,
system::show_in_finder,
system::trash
system::trash,
record_usage,
get_frecency_data
])
.setup(|app| {
let app_handle = app.handle().clone();
@ -210,6 +228,9 @@ pub fn run() {
quicklink_manager.init_db()?;
app.manage(quicklink_manager);
let frecency_manager = FrecencyManager::new(app.handle().clone())?;
app.manage(frecency_manager);
setup_background_refresh();
setup_global_shortcut(app)?;