| Crates.io | matchete |
| lib.rs | matchete |
| version | 0.0.24 |
| created_at | 2025-04-23 15:45:53.526177+00 |
| updated_at | 2025-07-10 21:30:13.718556+00 |
| description | A fast and flexible matcher for comparing and diffing data structures. |
| homepage | |
| repository | https://github.com/liagha/matchete |
| max_upload_size | |
| id | 1645845 |
| size | 45,806 |
Matchete is a versatile Rust library for similarity matching between query and candidate items. Designed for flexibility, it enables custom similarity metrics, weighted metric combinations, and configurable matching behavior via a builder pattern. Whether you're building search engines, recommendation systems, or fuzzy matching tools, Matchete provides a robust, generic framework that works with any data types implementing Clone and Debug.
The name Matchete draws inspiration from "machete," evoking precision and strength in cutting through complex matching tasks, while playfully nodding to its core purpose: finding the best match.
Clone and Debug traits.SimilarityMetric trait.MultiMatcher to aggregate results from multiple matchers.MatcherBuilder.Add Matchete to your project by including it in your Cargo.toml:
[dependencies]
matchete = "0.0.3" # Replace with the actual version
Ensure you have Rust installed via rustup.
Matchete offers a simple yet powerful API for matching tasks. Below is a basic example of string matching with a custom metric. For more examples, see the Examples section.
use matchete::{Matcher, SimilarityMetric};
// Define a simple string similarity metric
struct SimpleMetric;
impl SimilarityMetric<String, String> for SimpleMetric {
fn calculate(&self, query: &String, candidate: &String) -> f64 {
if query == candidate { 1.0 } else { 0.5 }
}
fn id(&self) -> &str { "simple" }
}
fn main() {
// Create a matcher
let matcher = Matcher::<String, String>::new()
.with_metric(SimpleMetric, 1.0)
.with_threshold(0.6);
// Match a query against candidates
let query = String::from("hello");
let candidates = vec![String::from("hello"), String::from("world")];
if let Some(result) = matcher.find_best_match(&query, &candidates) {
println!("Best match: {} (score: {:.2})", result.candidate, result.score);
}
}
The examples folder contains practical demonstrations of Matchete's capabilities:
string.rs: Simple string matching with a single metric.multimetrics.rs: Combining metrics using MatcherBuilder with conditional thresholds.numeric.rs: Matching f64 numbers with a custom metric.analysis.rs: Analyzing matches with per-metric score details.multimatcher.rs: Combining multiple matchers with MultiMatcher.Run an example using:
cargo run --example basic_string_matching
Each example includes detailed comments and instructions. The examples/common.rs file provides shared metrics used across these demos.
Customize Matchete's behavior with:
See multimetrics.rs for an example of complex configurations.
Contributions are welcome! To contribute:
git checkout -b feature/my-feature).git commit -m "Add my feature").git push origin feature/my-feature).Please include tests and update documentation. Adhere to the Rust Code of Conduct.
Matchete is licensed under the MIT License. See the LICENSE file for details.
For questions, suggestions, or issues, visit the GitHub repository.