Skip to main content

Crate fff_search

Crate fff_search 

Source
Expand description

§FFF Search — High-performance file finder core

This crate provides the core search engine for FFF (Fast File Finder). It includes filesystem indexing with real-time watching, fuzzy matching powered by frizbee, frecency scoring backed by LMDB, and multi-mode grep search.

§Architecture

  • file_picker::FilePicker — Main entry point. Indexes a directory tree in a background thread, maintains a sorted file list, watches the filesystem for changes, and performs fuzzy search with frecency-weighted scoring.
  • frecency::FrecencyTracker — LMDB-backed database that tracks file access and modification patterns for intelligent result ranking.
  • query_tracker::QueryTracker — Tracks search query history and provides “combo-boost” scoring for repeatedly matched files.
  • grep — Live grep search supporting regex, plain-text, and fuzzy modes with optional constraint filtering.
  • git — Git status caching and repository detection.

§Shared State

SharedPicker, SharedFrecency, and SharedQueryTracker are newtype wrappers around Arc<RwLock<Option<T>>> for thread-safe shared access. They provide read() / write() methods with built-in error conversion and convenience helpers like wait_for_scan().

§Quick Start

use fff_search::file_picker::FilePicker;
use fff_search::frecency::FrecencyTracker;
use fff_search::query_tracker::QueryTracker;
use fff_search::{
    FFFMode, FilePickerOptions, FuzzySearchOptions, PaginationArgs, QueryParser,
    SharedFrecency, SharedPicker, SharedQueryTracker,
};

let shared_picker = SharedPicker::default();
let shared_frecency = SharedFrecency::default();
let shared_query_tracker = SharedQueryTracker::default();

let tmp = std::env::temp_dir().join("fff-doctest");
std::fs::create_dir_all(&tmp).unwrap();

// 1. Optionally initialize frecency and query tracker databases
let frecency = FrecencyTracker::new(tmp.join("frecency"), false)?;
shared_frecency.init(frecency)?;

let query_tracker = QueryTracker::new(tmp.join("queries"), false)?;
shared_query_tracker.init(query_tracker)?;

// 2. Init the file picker (spawns background scan + watcher)
FilePicker::new_with_shared_state(
    shared_picker.clone(),
    shared_frecency.clone(),
    FilePickerOptions {
        base_path: ".".into(),
        mode: FFFMode::Ai,
        ..Default::default()
    },
)?;

// 3. Wait for scan
shared_picker.wait_for_scan(std::time::Duration::from_secs(10));

// 4. Search: lock the picker and query tracker
let picker_guard = shared_picker.read()?;
let picker = picker_guard.as_ref().unwrap();
let qt_guard = shared_query_tracker.read()?;

// 5. Parse the query and perform fuzzy search
let parser = QueryParser::default();
let query = parser.parse("lib.rs");

let results = picker.fuzzy_search(
    &query,
    qt_guard.as_ref(),
    FuzzySearchOptions {
        max_threads: 0,
        current_file: None,
        pagination: PaginationArgs { offset: 0, limit: 50 },
        ..Default::default()
    },
);

assert!(results.total_matched > 0);
assert!(results.items.first().unwrap().relative_path(picker).ends_with("lib.rs"));

let _ = std::fs::remove_dir_all(&tmp);

Re-exports§

pub use file_picker::*;
pub use frecency::*;
pub use grep::*;
pub use query_tracker::*;
pub use shared::*;
pub use types::*;

Modules§

bigram_query
Regex → bigram decomposition for the inverted bigram index.
case_insensitive_memmem
SIMD-accelerated case-insensitive substring search.
file_picker
Core file picker: filesystem indexing, background watching, and fuzzy search.
frecency
Frecency (frequency + recency) database for file access scoring.
git
Git status caching and repository detection utilities.
glob_detect
Glob wildcard detection — delegates to zlob when available, pure-Rust fallback otherwise.
grep
Live grep search with regex, plain-text, and fuzzy matching modes.
location
Location parsing for file:line:col patterns
log
Tracing/logging initialization and panic hook setup. Shared logging utilities for FFF crates.
path_utils
Path manipulation utilities: cross platform canonicalization, tilde expansion, and directory distance penalties for search scoring.
query_tracker
Search query history tracker for combo-boost scoring.
shared
Thread-safe shared handles for FilePicker, FrecencyTracker, and QueryTracker.
types
Core data types shared across the crate.

Structs§

AiGrepConfig
Configuration for AI-mode grep — extends GrepConfig behavior with automatic file-path constraint detection.
BigramFilter
Inverted bigram index with optional “skip-1” extension Copmressed into bitset for minimal usage, the layout of this struct actually matters
BigramIndexBuilder
Temporary sync dense builder for the bigram index. Builds from the many threads reading file contents in parallel
BigramOverlay
Modified and added files store their own bigram sets. Deleted files are tombstoned in a bitset so they can be excluded from base query results. This overlay is updated by the background watcher on every file event and cleared when the base index is rebuilt.
DbHealth
Health information about a database
DirSearchConfig
Configuration for directory and mixed search modes.
FFFQuery
FileSearchConfig
Default configuration for file picker - all features enabled
GrepConfig
Configuration for full-text search (grep) - file constraints enabled for filtering which files to search, git status disabled since it’s not useful when searching file contents.
MixedSearchConfig
Configuration for mixed (files + directories) search.
QueryParser
Main query parser - zero-cost wrapper around configuration

Enums§

Constraint
Constraint types that can be extracted from a query
Error
FuzzyQuery
GitStatusFilter
Location

Traits§

DbHealthChecker
ParserConfig
Parser configuration trait - allows different picker types to customize parsing

Functions§

extract_bigrams

Type Aliases§

ConstraintVec
Result