aboutsummaryrefslogtreecommitdiffstats
path: root/crates/daemon/src/search
diff options
context:
space:
mode:
Diffstat (limited to 'crates/daemon/src/search')
-rw-r--r--crates/daemon/src/search/mod.rs54
1 files changed, 27 insertions, 27 deletions
diff --git a/crates/daemon/src/search/mod.rs b/crates/daemon/src/search/mod.rs
index 02c79c9c..b4d03bcd 100644
--- a/crates/daemon/src/search/mod.rs
+++ b/crates/daemon/src/search/mod.rs
@@ -37,16 +37,16 @@ fn format_uuid_bytes(bytes: &[u8; 16]) -> String {
/// Pre-computed frecency data for O(1) lookup.
#[derive(Debug, Clone, Default)]
-pub(crate) struct FrecencyData {
+pub struct FrecencyData {
/// Total number of times this command was used.
- pub(crate) count: u32,
+ pub count: u32,
/// Most recent usage timestamp (unix seconds).
- pub(crate) last_used: i64,
+ pub last_used: i64,
}
impl FrecencyData {
/// Record a new usage of this command.
- pub(crate) fn record_use(&mut self, timestamp: i64) {
+ pub fn record_use(&mut self, timestamp: i64) {
self.count += 1;
if timestamp > self.last_used {
self.last_used = timestamp;
@@ -65,7 +65,7 @@ impl FrecencyData {
/// A multiplier of 0.0 disables that component, 1.0 is unchanged, 2.0 doubles weight.
/// Values like 0.5 reduce weight by half, 1.5 increases by 50%, etc.
#[instrument(level = Level::TRACE, name = "index_frecency_compute")]
- pub(crate) fn compute(&self, now: i64, recency_mul: f64, frequency_mul: f64) -> u32 {
+ pub fn compute(&self, now: i64, recency_mul: f64, frequency_mul: f64) -> u32 {
if self.count == 0 {
return 0;
}
@@ -100,13 +100,13 @@ impl FrecencyData {
}
/// Data for a unique command.
-pub(crate) struct CommandData {
+pub struct CommandData {
/// History ID of the most recent invocation (16-byte UUID).
most_recent_id: [u8; 16],
/// Timestamp of the most recent invocation.
most_recent_timestamp: i64,
/// Pre-computed global frecency.
- pub(crate) global_frecency: FrecencyData,
+ pub global_frecency: FrecencyData,
// Pre-computed indexes for O(1) filter lookups
// Using HashSet instead of DashSet since CommandData lives inside DashMap (already synchronized)
@@ -121,7 +121,7 @@ pub(crate) struct CommandData {
impl CommandData {
/// Create a new [`CommandData`] from a history entry.
/// Returns None if the history entry has invalid UUIDs.
- pub(crate) fn new(history: &History, interner: &ThreadedRodeo) -> Option<Self> {
+ pub fn new(history: &History, interner: &ThreadedRodeo) -> Option<Self> {
let history_id = parse_uuid_bytes(&history.id.0)?;
let session = parse_uuid_bytes(&history.session)?;
let timestamp = history.timestamp.unix_timestamp();
@@ -153,7 +153,7 @@ impl CommandData {
/// Add an invocation from a history entry.
/// Returns false if the history entry has invalid UUIDs.
- pub(crate) fn add_invocation(&mut self, history: &History, interner: &ThreadedRodeo) -> bool {
+ pub fn add_invocation(&mut self, history: &History, interner: &ThreadedRodeo) -> bool {
let Some(history_id) = parse_uuid_bytes(&history.id.0) else {
return false;
};
@@ -182,13 +182,13 @@ impl CommandData {
}
/// Get the most recent history ID for this command.
- pub(crate) fn most_recent_id(&self) -> String {
+ pub fn most_recent_id(&self) -> String {
format_uuid_bytes(&self.most_recent_id)
}
/// Check if any invocation matches a directory filter (exact match).
/// O(1) lookup using pre-computed index.
- pub(crate) fn has_invocation_in_dir(&self, dir: &str, interner: &ThreadedRodeo) -> bool {
+ pub fn has_invocation_in_dir(&self, dir: &str, interner: &ThreadedRodeo) -> bool {
interner
.get(dir)
.is_some_and(|spur| self.directories.contains(&spur))
@@ -196,7 +196,7 @@ impl CommandData {
/// Check if any invocation matches a directory prefix (workspace/git root).
/// O(n) where n = number of unique directories for this command.
- pub(crate) fn has_invocation_in_workspace(
+ pub fn has_invocation_in_workspace(
&self,
prefix: &str,
interner: &ThreadedRodeo,
@@ -208,7 +208,7 @@ impl CommandData {
/// Check if any invocation matches a hostname.
/// O(1) lookup using pre-computed index.
- pub(crate) fn has_invocation_on_host(&self, hostname: &str, interner: &ThreadedRodeo) -> bool {
+ pub fn has_invocation_on_host(&self, hostname: &str, interner: &ThreadedRodeo) -> bool {
interner
.get(hostname)
.is_some_and(|spur| self.hosts.contains(&spur))
@@ -216,14 +216,14 @@ impl CommandData {
/// Check if any invocation matches a session.
/// O(1) lookup using pre-computed index.
- pub(crate) fn has_invocation_in_session(&self, session: &str) -> bool {
+ pub fn has_invocation_in_session(&self, session: &str) -> bool {
parse_uuid_bytes(session).is_some_and(|bytes| self.sessions.contains(&bytes))
}
}
/// Filter mode for search queries.
#[derive(Debug, Clone, PartialEq, Eq)]
-pub(crate) enum IndexFilterMode {
+pub enum IndexFilterMode {
/// No filtering - search all commands.
Global,
/// Filter to commands run in a specific directory.
@@ -238,15 +238,15 @@ pub(crate) enum IndexFilterMode {
/// Context for search queries.
#[derive(Debug, Clone, Default)]
-pub(crate) struct QueryContext {
+pub struct QueryContext {
#[expect(dead_code)]
- pub(crate) cwd: Option<String>,
+ pub cwd: Option<String>,
#[expect(dead_code)]
- pub(crate) git_root: Option<String>,
+ pub git_root: Option<String>,
#[expect(dead_code)]
- pub(crate) hostname: Option<String>,
+ pub hostname: Option<String>,
#[expect(dead_code)]
- pub(crate) session_id: Option<String>,
+ pub session_id: Option<String>,
}
/// Shareable frecency map: command -> frecency score.
@@ -261,7 +261,7 @@ type FrecencyMap = Arc<HashMap<Arc<str>, u32>>;
/// Global frecency is precomputed by a background task and used for scoring.
/// If frecency data is not available, search still works but without frecency ranking;
/// although this should never happen due to precomputing the frecency map.
-pub(crate) struct SearchIndex {
+pub struct SearchIndex {
/// Map from command text to command data.
/// Using `DashMap` for concurrent read/write access, wrapped in Arc for sharing with scorer.
/// Keys are Arc<str> to enable zero-copy sharing with `frecency_map`.
@@ -278,7 +278,7 @@ pub(crate) struct SearchIndex {
impl SearchIndex {
/// Create a new empty search index.
- pub(crate) fn new() -> Self {
+ pub fn new() -> Self {
let nucleo_config = atuin_nucleo::Config::DEFAULT;
// Single column for command text
let nucleo = Nucleo::<String>::new(nucleo_config, Arc::new(|| {}), None, 1);
@@ -297,7 +297,7 @@ impl SearchIndex {
///
/// If the command already exists, updates its invocation data.
/// If it's a new command, adds it to both the map and Nucleo.
- pub(crate) fn add_history(&self, history: &History) {
+ pub fn add_history(&self, history: &History) {
let command = history.command.as_str();
// DashMap with Arc<str> keys can be looked up with &str via Borrow trait
@@ -320,14 +320,14 @@ impl SearchIndex {
}
/// Add multiple history entries to the index.
- pub(crate) fn add_histories(&self, histories: &[History]) {
+ pub fn add_histories(&self, histories: &[History]) {
for history in histories {
self.add_history(history);
}
}
/// Get the number of unique commands in the index.
- pub(crate) fn command_count(&self) -> usize {
+ pub fn command_count(&self) -> usize {
self.commands.len()
}
@@ -340,7 +340,7 @@ impl SearchIndex {
clippy::significant_drop_tightening,
reason = "The nucleo early drop is a false-positive"
)]
- pub(crate) async fn search(
+ pub async fn search(
&self,
query: &str,
filter_mode: IndexFilterMode,
@@ -403,7 +403,7 @@ impl SearchIndex {
/// - `frequency_score_multiplier`: Weight for frequency component
/// - `frecency_score_multiplier`: Overall multiplier for final score
#[instrument(skip_all, level = Level::DEBUG, name = "rebuild_frecency")]
- pub(crate) async fn rebuild_frecency(&self, search_settings: &Search) {
+ pub async fn rebuild_frecency(&self, search_settings: &Search) {
let now = OffsetDateTime::now_utc().unix_timestamp();
let mut frecency_map: HashMap<Arc<str>, u32> = HashMap::new();