nucleoc

Nucleoc - Fuzzy Matcher for Crystal

CI GitHub license GitHub release Crystal Shards

Nucleoc is a Crystal port of the nucleo fuzzy matcher from Rust. It provides high-performance fuzzy matching algorithms for text search and filtering.

Status

Production Ready - This is a complete port of the Rust nucleo library with full fuzzy matching functionality implemented and tested.

Features

  • Exact string matching
  • Case-sensitive and case-insensitive matching
  • Configurable scoring parameters
  • Fuzzy matching (greedy and optimal algorithms)
  • Substring matching
  • Prefix/Postfix matching
  • Pattern parsing
  • Unicode normalization
  • High-performance optimizations

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      nucleoc:
        github: dsisnero/nucleoc
    
  2. Run shards install

Usage

require "nucleoc"

# Create a matcher with default configuration
matcher = Nucleoc::Matcher.new

# Fuzzy matching with scores
if score = matcher.fuzzy_match("hello world", "hlo")
  puts "Fuzzy match found with score: #{score}"
end

# Fuzzy matching with indices (positions of matched characters)
indices = [] of UInt32
if score = matcher.fuzzy_indices("hello world", "hlo", indices)
  puts "Match indices: #{indices}"  # => [0, 2, 3] (positions of h, l, o)
end

# Case insensitive matching (default)
matcher.fuzzy_match("Hello", "hello") # => 0 (exact match)

# Case sensitive matching
config = Nucleoc::Config.new(ignore_case: false)
matcher = Nucleoc::Matcher.new(config)
matcher.fuzzy_match("Hello", "hello") # => nil (no match)

# Substring matching
if score = matcher.substring_match("hello world", "world")
  puts "Substring match found with score: #{score}"
end

# Pattern parsing for advanced queries
pattern = Nucleoc::Pattern.parse("foo|bar")
if score = matcher.fuzzy_match("foo bar baz", pattern)
  puts "Pattern match found with score: #{score}"
end

Configuration

# Default configuration
config = Nucleoc::Config::DEFAULT

# Custom configuration
config = Nucleoc::Config.new(
  ignore_case: false,
  normalize: true,
  prefer_prefix: false,
  delimiter_chars: "/,:;|"
)

# Configure for file path matching
config = Nucleoc::Config::DEFAULT.match_paths

Debugging

Nucleoc uses Crystal's Log system. Set LOG_LEVEL=DEBUG to see detailed matcher traces, including matrix layout, scoring, and reconstruction steps:

LOG_LEVEL=DEBUG crystal spec

Development Status

This project is a complete port of the Rust nucleo library. The implementation includes:

  1. Complete matching algorithms - Fuzzy (greedy and optimal), exact, substring, prefix/postfix
  2. Pattern parsing - Full pattern syntax with operators and escaping
  3. Unicode support - Full Unicode normalization and character classification
  4. Performance optimizations - Compressed matrix representation, prefiltering, efficient scoring
  5. Configuration - Flexible scoring parameters and matching options

Feature Parity with Rust Nucleo

  • Core matching algorithms - All algorithms from Rust implementation
  • Scoring system - Exact scoring constants and bonus calculations
  • Unicode handling - Full Unicode normalization and case folding
  • Pattern parsing - Complete pattern syntax with operators
  • Test coverage - 125/125 tests passing with exact behavior matching

Missing Features (Future Development)

  • 🔄 MultiPattern - Incremental pattern updates (tracked in issue nucleoc-wu9)
  • 🔄 Core components - Boxcar, parallel sort, worker threads (tracked in issue nucleoc-i2i)
  • 🔄 Agent system - CML-based concurrent processing architecture

Development

Prerequisites

  • Crystal 1.18.2 or later
  • Git

Setup

git clone https://github.com/dsisnero/nucleoc.git
cd nucleoc
shards install

Running Tests

crystal spec

Code Quality

# Format code
crystal tool format src/ spec/

# Run linter
ameba

Contributing

Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Contributors

See the full list of contributors who participated in this project.

Acknowledgments

  • Based on the nucleo Rust library by Pascal Kuthe and the Helix editor team
  • Inspired by fzf and skim fuzzy matching algorithms
  • Uses CML for concurrent ML patterns

License

This project is licensed under the MIT License - see the LICENSE file for details.

Repository

nucleoc

Owner
Statistic
  • 0
  • 0
  • 0
  • 0
  • 2
  • about 3 hours ago
  • December 18, 2025
License

MIT License

Links
Synced at

Sun, 21 Dec 2025 16:47:43 GMT

Languages