### Dart: E-commerce Product Search Integration with Fuzzy Bolt Source: https://context7.com/vishwa-karthik/fuzzy_bolt/llms.txt This Dart example showcases a complete integration of Fuzzy Bolt into an e-commerce product search system. It includes data cleaning using `StandardDatasetCleaner.forEcommerce`, initialization of the search service, and a search function that utilizes advanced Fuzzy Bolt parameters like `strictThreshold`, `typeThreshold`, `maxResults`, and `enableStemming` for precise results. The example also defines a `Product` model and a `SearchResultItem` to structure the output. ```dart import 'package:fuzzy_bolt/fuzzy_bolt.dart'; class Product { final String id; final String name; final String description; final String category; final List tags; final double price; Product(this.id, this.name, this.description, this.category, this.tags, this.price); } class ProductSearchService { late List _cleanedProducts; final _cleaner = StandardDatasetCleaner.forEcommerce(); Future initialize(List products) async { // Clean dataset once during initialization final result = _cleaner.cleanDataset( products, [(p) => p.name, (p) => p.description, (p) => p.category], removeDuplicates: true, qualityThreshold: 0.3, ); _cleanedProducts = result.cleanedItems; print('Initialized with ${_cleanedProducts.length} products'); print('Removed ${result.removedItems.length} low-quality items'); } Future> search(String query) async { final results = await FuzzyBolt.searchWithScores( _cleanedProducts, query, selectors: [ (p) => p.name, (p) => p.description, (p) => p.category, (p) => p.tags.join(' '), ], strictThreshold: 0.75, typeThreshold: 0.60, maxResults: 20, enableStemming: true, ); return results.map((r) => SearchResultItem( product: r.item, relevanceScore: r.score, matchedText: r.matchedText, )).toList(); } } class SearchResultItem { final Product product; final double relevanceScore; final String matchedText; SearchResultItem({ required this.product, required this.relevanceScore, required this.matchedText, }); } // Usage void main() async { final products = [ Product('1', 'Nike Air Max Running Shoes', 'Comfortable running shoes', 'Footwear', ['running', 'sports'], 129.99), Product('2', 'Adidas Running Shorts', 'Lightweight athletic shorts', 'Apparel', ['running', 'shorts'], 39.99), Product('3', 'Running Belt with Water Bottle', 'Hydration belt for runners', 'Accessories', ['running', 'hydration'], 24.99), ]; final searchService = ProductSearchService(); await searchService.initialize(products); // User searches with typos final results = await searchService.search('runing shuz'); for (final result in results) { print('${result.product.name}'); print(' Relevance: ${(result.relevanceScore * 100).toInt()}%'); print(' Price: $${result.product.price}'); print(' Matched: "${result.matchedText}"'); print(''); } } ``` -------------------------------- ### API Guide: FuzzyBolt.search() Parameters and Usage in Dart Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Details the parameters for the FuzzyBolt.search() method, including dataset, query, selectors for target fields, and optional parameters like strictThreshold, typeThreshold, maxResults, and skipIsolate. Provides examples for searching single/multiple fields and limiting results. ```dart Future> FuzzyBolt.search( List dataset, String query, { required List selectors, // Tell it which fields to search double strictThreshold = 0.85, // How strict for exact matches (0.0-1.0) double typeThreshold = 0.65, // How forgiving for typos (0.0-1.0) int? maxResults, // Cap the results bool skipIsolate = false, // Set true for web } ) // Simple name search final results = await FuzzyBolt.search( users, 'alice', selectors: [(u) => u.name], ); // Search across multiple fields (name, email, department, etc.) final results = await FuzzyBolt.search( products, 'running shoes', selectors: [(p) => p.name, (p) => p.description, (p) => p.category], ); // Just give me the top 5 results final top5 = await FuzzyBolt.search( users, 'john', selectors: [(u) => u.name], maxResults: 5, ); ``` -------------------------------- ### Dataset Cleaner Strategies Comparison in Dart Source: https://context7.com/vishwa-karthik/fuzzy_bolt/llms.txt Demonstrates the use of different predefined dataset cleaner strategies: minimal, e-commerce, and aggressive. Each strategy applies different levels of cleaning to a list of items, and the example shows how to compare the number of removed items from each strategy. ```dart import 'package:fuzzy_bolt/fuzzy_bolt.dart'; class Item { final String text; Item(this.text); } final items = [ Item('Valid item one'), Item('Valid item two'), Item('a'), // Very short ]; // Minimal cleaning - gentle approach final minimalCleaner = StandardDatasetCleaner.minimal(); final minimalResult = minimalCleaner.cleanDataset(items, [(i) => i.text]); // E-commerce cleaning - balanced (recommended) final ecommerceCleaner = StandardDatasetCleaner.forEcommerce(); final ecommerceResult = ecommerceCleaner.cleanDataset(items, [(i) => i.text]); // Aggressive cleaning - maximum quality enforcement final aggressiveCleaner = StandardDatasetCleaner.aggressive(); final aggressiveResult = aggressiveCleaner.cleanDataset(items, [(i) => i.text]); print('Minimal removed: ${minimalResult.removedItems.length}'); print('E-commerce removed: ${ecommerceResult.removedItems.length}'); print('Aggressive removed: ${aggressiveResult.removedItems.length}'); ``` -------------------------------- ### Performance Tip: Limit Search Results Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md A concise example demonstrating how to limit the maximum number of results returned by a search query. This is a simple yet effective way to optimize performance when only a subset of matches is needed. ```dart maxResults: 10 // Stop after finding 10 matches ``` -------------------------------- ### Quick Start: Basic and Scored Fuzzy Search in Dart Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Demonstrates the basic usage of FuzzyBolt.search to find matching items and FuzzyBolt.searchWithScores to retrieve items along with their confidence scores. It highlights built-in typo tolerance and the process of iterating through scored results. ```dart import 'package:fuzzy_bolt/fuzzy_bolt.dart'; final users = [ User(name: 'Alice Johnson', email: 'alice@example.com'), User(name: 'Bob Smith', email: 'bob@example.com'), ]; // Basic search - just give me the matching items final results = await FuzzyBolt.search( users, 'Alise', // Yep, typo tolerance built-in! selectors: [(u) => u.name], ); // Want to see how confident each match is? final scored = await FuzzyBolt.searchWithScores( users, 'alice', selectors: [(u) => u.name], ); for (final result in scored) { print('${result.item.name}: ${(result.score * 100).toInt()}% match'); // Output: Alice Johnson: 100% match } ``` -------------------------------- ### Performance Tip: Disable Unused Features Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Provides examples of disabling optional text processing features like stemming and cleaning. Turning off features not required for a specific search can lead to significant performance improvements. ```dart enableStemming: false // Skip if you don't need word variation matching enableCleaning: false // Skip if your data is already clean ``` -------------------------------- ### Running Tests Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Provides the command to execute the project's test suite. This is essential for verifying the library's functionality and ensuring its quality across various features and edge cases. ```bash dart test ``` -------------------------------- ### Web Platform Note: Skip Isolates Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Explains how to handle web platform limitations where isolates are not available. By setting `skipIsolate: true` when `kIsWeb` is true, the library can function correctly in a web environment. ```dart import 'package:flutter/foundation.dart' show kIsWeb; final results = await FuzzyBolt.search( users, 'query', selectors: [(u) => u.name], skipIsolate: kIsWeb, // Handles web automatically ); ``` -------------------------------- ### Understanding Strict Threshold for Matching Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Illustrates the use of `strictThreshold` to control the precision of search matches. Higher values require near-perfect matches, while lower values allow for more variation, affecting which results are considered valid. ```dart strictThreshold: 0.95 // "Alice" matches "Alice" only strictThreshold: 0.85 // "Alice" matches "Alice" and "Alicia" strictThreshold: 0.7 // "Alice" matches "Alice", "Alicia", "Alise" ``` -------------------------------- ### Configure Fuzzy Search Behavior with FuzzySearchConfig Source: https://context7.com/vishwa-karthik/fuzzy_bolt/llms.txt Utilize FuzzySearchConfig objects to define precise search parameters such as strictness thresholds, maximum results, and isolate usage. This allows for reusable and adaptable search settings for different scenarios. The `copyWith` method enables easy modification of existing configurations. ```dart import 'package:fuzzy_bolt/fuzzy_bolt.dart'; class User { final String username; final String email; User(this.username, this.email); } final users = [ User('alice_johnson', 'alice@example.com'), User('bob_smith', 'bob@example.com'), ]; // Create reusable strict configuration final strictConfig = FuzzySearchConfig( strictThreshold: 0.95, // Very strict matching typeThreshold: 0.85, // Less forgiving on typos maxResults: 10, // Limit results isolateThreshold: 1000, // Use isolates at 1000+ items skipIsolate: false, // Allow isolate usage ); final results = await FuzzyBolt.searchWithConfig( users, 'alice', [(u) => u.username, (u) => u.email], strictConfig, ); // Create a modified configuration final relaxedConfig = strictConfig.copyWith( strictThreshold: 0.70, typeThreshold: 0.50, ); final relaxedResults = await FuzzyBolt.searchWithConfig( users, 'alce', // More typos tolerated [(u) => u.username], relaxedConfig, ); ``` -------------------------------- ### Performance Tip: Pre-clean Data for Multiple Searches Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Demonstrates an optimization strategy where data is cleaned once and then reused for multiple subsequent searches. This avoids redundant cleaning operations, improving overall efficiency when performing many searches on the same dataset. ```dart // Clean your dataset once final cleaned = cleaner.cleanDataset(products, [(p) => p.name]); // Then reuse the cleaned data for multiple searches for (final query in userQueries) { final results = await FuzzyBolt.search( cleaned.cleanedItems, // Already clean! query, selectors: [(p) => p.name], enableCleaning: false, // No need to clean again ); } ``` -------------------------------- ### Access and Utilize Direct Similarity Algorithms Source: https://context7.com/vishwa-karthik/fuzzy_bolt/llms.txt Fuzzy Bolt provides direct access to underlying similarity algorithms like Jaro-Winkler and Levenshtein. This allows for custom implementations, detailed analysis of string comparisons, and fine-tuning of similarity calculations based on specific use cases. ```dart import 'package:fuzzy_bolt/fuzzy_bolt.dart'; // Jaro-Winkler Similarity (good for typos and prefix matches) final jaroWinkler = JaroWinklerSimilarity( scalingFactor: 0.1, // Prefix weight maxPrefixLength: 4, // Max prefix length to consider ); final score1 = jaroWinkler.calculateSimilarity('hello', 'hallo'); print('Jaro-Winkler: ${(score1 * 100).toInt()}%'); // Output: ~93% // Levenshtein Similarity (edit distance based) final levenshtein = LevenshteinSimilarity(); final score2 = levenshtein.calculateSimilarity('kitten', 'sitting'); print('Levenshtein: ${(score2 * 100).toInt()}%'); // Output: ~57% // Compare both algorithms final testStrings = [ ['apple', 'aple'], // Missing letter ['apple', 'appel'], // Transposition ['apple', 'apples'], // Extra letter ]; for (final pair in testStrings) { final jw = jaroWinkler.calculateSimilarity(pair[0], pair[1]); final lv = levenshtein.calculateSimilarity(pair[0], pair[1]); print('${pair[0]} vs ${pair[1]}: JW=${(jw*100).toInt()}% LV=${(lv*100).toInt()}%'); } ``` -------------------------------- ### Dart: Robust Search with Input Validation and Error Handling Source: https://context7.com/vishwa-karthik/fuzzy_bolt/llms.txt This Dart snippet demonstrates how to implement robust search functionality using Fuzzy Bolt, including handling empty queries, ensuring null safety, managing results, and gracefully handling excessively long input strings to prevent denial-of-service attacks. It uses a try-catch block to manage potential errors during the search process. ```dart import 'package:fuzzy_bolt/fuzzy_bolt.dart'; class Item { final String name; Item(this.name); } final items = [Item('Test Item')]; try { // Empty query handling final results1 = await FuzzyBolt.search( items, '', // Empty query returns empty list selectors: [(i) => i.name], ); print('Empty query results: ${results1.length}'); // Output: 0 // Null safety - items cannot be null (enforced by type system) final results2 = await FuzzyBolt.search( items, 'test', selectors: [(i) => i.name], ); // Check if results exist if (results2.isEmpty) { print('No matches found'); } else { print('Found ${results2.length} matches'); } // Handle very long strings (protected against DoS) final longQuery = 'a' * 60000; // Exceeds 50,000 char limit final results3 = await FuzzyBolt.search( items, longQuery, selectors: [(i) => i.name], ); // Automatically handles gracefully } catch (e) { print('Search error: $e'); // Handle error appropriately } ``` -------------------------------- ### E-commerce Product Search with Typos Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Demonstrates how to perform fuzzy searches on product data, allowing for user typos in search queries. It targets specific fields like 'name' and 'description' for matching. This is useful for maintaining a good user experience even when users misspell product names. ```dart final results = await FuzzyBolt.searchWithScores( products, 'runing shos', // User can't spell? We got you. selectors: [(p) => p.name, (p) => p.description], ); ``` -------------------------------- ### Performance Tip: Adjust Isolate Threshold Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Shows how to configure the `isolateThreshold` to control when parallel processing (using isolates) is activated. Lowering this value can improve performance on medium-sized datasets by enabling parallelism earlier. ```dart isolateThreshold: 500 // Use parallel processing at 500+ items (default: 1000) ``` -------------------------------- ### Dataset Cleaning for E-commerce in Dart Source: https://context7.com/vishwa-karthik/fuzzy_bolt/llms.txt Cleans datasets by removing duplicates and low-quality entries using a standard cleaner configured for e-commerce. This method takes a list of products, selectors for fields to evaluate, a quality threshold, and flags to enable duplicate and outlier removal, returning statistics and the cleaned dataset. ```dart import 'package:fuzzy_bolt/fuzzy_bolt.dart'; class Product { final String name; final String description; Product(this.name, this.description); } final products = [ Product('iPhone 15', 'Latest Apple smartphone with amazing features'), Product('iPhone 15', 'Latest Apple smartphone with amazing features'), // Duplicate Product('x', ''), // Low quality - very short Product('Samsung Galaxy S23', 'Premium Android phone'), ]; // Create cleaner with balanced settings final cleaner = StandardDatasetCleaner.forEcommerce(); final result = cleaner.cleanDataset( products, [(p) => p.name, (p) => p.description], qualityThreshold: 0.3, // Remove items below this quality removeDuplicates: true, // Remove exact duplicates removeOutliers: true, // Remove statistical outliers ); print('Original: ${result.statistics.originalCount}'); print('Cleaned: ${result.statistics.cleanedCount}'); print('Removed: ${result.statistics.removedCount}'); print('Duplicates: ${result.statistics.duplicatesRemoved}'); print('Quality: ${result.statistics.qualityScore}'); // Output: // Original: 4 // Cleaned: 2 // Removed: 2 // Duplicates: 1 // Quality: 0.95 // Use cleaned data for searching final searchResults = await FuzzyBolt.search( result.cleanedItems, 'galaxy', selectors: [(p) => p.name], ); ``` -------------------------------- ### Direct Porter Stemmer Access and Text Processing in Dart Source: https://context7.com/vishwa-karthik/fuzzy_bolt/llms.txt Provides direct access to the Porter Stemmer algorithm for word normalization and text preprocessing. It allows stemming individual words, processing entire texts by stemming and removing stop words, and accessing the list of stop words and cache statistics. ```dart import 'package:fuzzy_bolt/fuzzy_bolt.dart'; // Stem individual words print(PorterStemmer.stem('running')); // Output: run print(PorterStemmer.stem('flies')); // Output: fli print(PorterStemmer.stem('categories')); // Output: categori // Process entire text (stems and removes stop words) final processed = PorterStemmer.stemText('The runners were running quickly'); print(processed); // Output: runner run quickli // Access stop words print(PorterStemmer.stopWords.contains('the')); // Output: true print(PorterStemmer.stopWords.length); // Output: 77 // Check cache statistics print('Cache size: ${PorterStemmer.cacheSize}'); print('Hit rate: ${PorterStemmer.hitRate}'); ``` -------------------------------- ### Search With Config Method - FuzzyBolt Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Enables fine-tuned control over fuzzy search behavior through FuzzySearchConfig object. Allows customization of strictness thresholds, type tolerance, and result limits for specialized search requirements. ```dart final strictConfig = FuzzySearchConfig( strictThreshold: 0.95, // Very picky about matches typeThreshold: 0.85, // Don't be too forgiving with typos maxResults: 10, ); final results = await FuzzyBolt.searchWithConfig( products, 'iPhone 15', [(p) => p.name], strictConfig, ); ``` -------------------------------- ### Dataset Cleaning - StandardDatasetCleaner Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Cleans datasets by removing duplicates and low-quality entries before fuzzy searching. Offers three predefined strategies (minimal, forEcommerce, aggressive) to match different data quality needs. Returns cleaned items with statistics on removal counts. ```dart // Pick a cleaning strategy final cleaner = StandardDatasetCleaner.minimal(); // Gentle cleaning final cleaner = StandardDatasetCleaner.forEcommerce(); // Balanced (recommended) final cleaner = StandardDatasetCleaner.aggressive(); // Maximum cleaning // Clean your dataset final result = cleaner.cleanDataset( products, [(p) => p.name], qualityThreshold: 0.3, removeDuplicates: true, ); print('Original: ${result.statistics.originalCount}'); print('Cleaned: ${result.statistics.cleanedCount}'); print('Removed: ${result.statistics.duplicatesRemoved} duplicates'); // Now search the cleaned data final searchResults = await FuzzyBolt.search( result.cleanedItems, // Use the cleaned list 'running shoes', selectors: [(p) => p.name], ); ``` -------------------------------- ### Cache Management - FuzzyBolt Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Manages internal text processing cache for performance optimization. Provides methods to clear cache and retrieve cache statistics including current size and maximum capacity limits. ```dart // Clear the internal text processing cache FuzzyBolt.clearTextCache(); // Check cache stats final stats = FuzzyBolt.getTextCacheStats(); print('Cache has ${stats["cacheSize"]} items (max: ${stats["maxCacheSize"]})');' ``` -------------------------------- ### Understanding Type Threshold for Typos Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Demonstrates the `typeThreshold` parameter, which governs how forgiving the search is with typos. A higher threshold means stricter typo checking, while a lower threshold allows for more significant typing errors to still yield matches. ```dart typeThreshold: 0.85 // "Alise" might not match "Alice" typeThreshold: 0.65 // "Alise" matches "Alice" ✓ typeThreshold: 0.4 // "Alce" matches "Alice" ✓ ``` -------------------------------- ### Smart Document Search with Text Processing Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Illustrates advanced document searching capabilities, including stemming and stop-word removal for more robust matching. This is ideal for searching through large collections of text documents, like articles or knowledge bases. ```dart final results = await FuzzyBolt.searchWithTextProcessing( docs, 'professional runners training', selectors: [(d) => d.title, (d) => d.content], enableStemming: true, removeStopWords: true, ); ``` -------------------------------- ### Porter Stemmer - Word Manipulation Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Direct interface to Porter Stemmer algorithm for reducing words to their root form and accessing stop words list. Useful for text preprocessing, linguistic analysis, or custom search logic. Supports both individual word stemming and full text processing. ```dart // Stem individual words print(PorterStemmer.stem('running')); // "run" print(PorterStemmer.stem('flies')); // "fli" print(PorterStemmer.stem('dogs')); // "dog" // Process entire sentences final text = 'The runners were running quickly'; print(PorterStemmer.stemText(text)); // "runner were run quickli" // Check the stop words list (77 common English words) print(PorterStemmer.stopWords.contains('the')); // true ``` -------------------------------- ### Search with Confidence Scores - Dart Source: https://context7.com/vishwa-karthik/fuzzy_bolt/llms.txt Returns search results with similarity scores (0.0 to 1.0) allowing assessment of match quality and confidence-based filtering. Includes matched text information and supports limiting results with maxResults parameter. Useful for displaying ranked results to users. ```dart import 'package:fuzzy_bolt/fuzzy_bolt.dart'; class Product { final String name; final double price; Product(this.name, this.price); } final products = [ Product('Running Shoes Nike', 89.99), Product('Running Shorts', 29.99), Product('Walking Shoes', 69.99), ]; final results = await FuzzyBolt.searchWithScores( products, 'runing shos', // Multiple typos selectors: [(p) => p.name], maxResults: 5, ); for (final result in results) { print('${result.item.name}: ${(result.score * 100).toInt()}% match'); print('Matched on: "${result.matchedText}"'); } // Output: // Running Shoes Nike: 89% match // Matched on: "Running Shoes Nike" // Running Shorts: 71% match // Matched on: "Running Shorts" ``` -------------------------------- ### Search With Scores Method - FuzzyBolt Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Performs fuzzy search and returns results with confidence scores (0.0 to 1.0) indicating match quality. Useful for ranking results and displaying confidence levels to users. Accepts dataset, query string, selector functions, and optional threshold parameters. ```dart Future>> FuzzyBolt.searchWithScores( List dataset, String query, { required List selectors, double strictThreshold = 0.85, double typeThreshold = 0.65, int? maxResults, } ) ``` ```dart class FuzzyResult { final T item; // Your original item final double score; // How well it matched: 0.0 (terrible) to 1.0 (perfect) final String matchedText; // The actual text that matched } ``` ```dart final results = await FuzzyBolt.searchWithScores( products, 'runing shos', // Multiple typos? No problem! selectors: [(p) => p.name], ); for (final result in results) { final confidence = (result.score * 100).toStringAsFixed(1); print('${result.item.name} - $confidence% match'); } // Output: // Running Shoes Pro - 87.5% match // Walking Shoes - 65.2% match ``` -------------------------------- ### Search with Stemming and Stop Word Removal in Dart Source: https://context7.com/vishwa-karthik/fuzzy_bolt/llms.txt Performs a search on a list of documents, applying Porter stemming and stop word removal for more intelligent matching. This function takes a list of documents, a query string, selectors for fields to search, and flags to enable stemming and stop word removal, returning a list of matching documents with their scores. ```dart import 'package:fuzzy_bolt/fuzzy_bolt.dart'; class Document { final String title; final String body; Document(this.title, this.body); } final documents = [ Document('Runners Guide', 'A comprehensive guide for runners who are running marathons'), Document('Walking Tips', 'Tips for people who enjoy walking daily'), ]; // Search with stemming - "runners" and "running" both stem to "run" final results = await FuzzyBolt.searchWithTextProcessing( documents, 'the runners are running', // Contains stop words selectors: [(d) => d.title, (d) => d.body], enableStemming: true, // "runners"→"runner", "running"→"run" removeStopWords: true, // Removes "the", "are" strictThreshold: 0.80, ); for (final result in results) { print('${result.item.title}: ${(result.score * 100).toInt()}%'); } // Output: Runners Guide: 92% ``` -------------------------------- ### Ensure Web Platform Compatibility by Disabling Isolates Source: https://context7.com/vishwa-karthik/fuzzy_bolt/llms.txt For web applications where Dart isolates have limitations, Fuzzy Bolt can automatically disable isolate usage. This is typically controlled using the `skipIsolate` parameter in conjunction with platform checks like `kIsWeb`. ```dart import 'package:fuzzy_bolt/fuzzy_bolt.dart'; import 'package:flutter/foundation.dart' show kIsWeb; class User { final String name; User(this.name); } final users = List.generate(2000, (i) => User('User $i')); // Automatically disable isolates on web platform final results = await FuzzyBolt.search( users, 'User 42', selectors: [(u) => u.name], skipIsolate: kIsWeb, // Disable isolates on web ); print('Found: ${results.length} users'); ``` -------------------------------- ### Basic Fuzzy Search with Typo Tolerance - Dart Source: https://context7.com/vishwa-karthik/fuzzy_bolt/llms.txt Performs fuzzy search on a dataset returning matching items without scores. Automatically handles typos and variations in user input using configurable similarity thresholds (strictThreshold and typeThreshold). Requires defining selectors to specify which object properties to search. ```dart import 'package:fuzzy_bolt/fuzzy_bolt.dart'; class User { final String name; final String email; User(this.name, this.email); } final users = [ User('Alice Johnson', 'alice@example.com'), User('Bob Smith', 'bob@example.com'), User('Charlie Brown', 'charlie@example.com'), ]; // Search with typo - "Alise" instead of "Alice" final results = await FuzzyBolt.search( users, 'Alise', selectors: [(u) => u.name], strictThreshold: 0.85, // Minimum similarity score typeThreshold: 0.65, // Typo tolerance threshold ); print(results.first.name); // Output: Alice Johnson ``` -------------------------------- ### Multi-field Fuzzy Search - Dart Source: https://context7.com/vishwa-karthik/fuzzy_bolt/llms.txt Searches across multiple object properties simultaneously to find matches in any field. Accepts multiple selectors targeting different properties and concatenates text fields like lists. Enables comprehensive searching across complex data structures with typo tolerance. ```dart import 'package:fuzzy_bolt/fuzzy_bolt.dart'; class Article { final String title; final String content; final String author; final List tags; Article(this.title, this.content, this.author, this.tags); } final articles = [ Article( 'Getting Started with Flutter', 'Flutter is a UI toolkit for building natively compiled applications...', 'Jane Developer', ['flutter', 'mobile', 'tutorial'], ), Article( 'Advanced Dart Patterns', 'Exploring design patterns in Dart programming language...', 'John Coder', ['dart', 'patterns', 'advanced'], ), ]; // Search across title, content, author, and tags final results = await FuzzyBolt.search
( articles, 'fluter', // Typo: missing 't' selectors: [ (a) => a.title, (a) => a.content, (a) => a.author, (a) => a.tags.join(' '), ], ); print(results.first.title); // Output: Getting Started with Flutter ``` -------------------------------- ### Optimize Large Datasets with Automatic Isolate Processing Source: https://context7.com/vishwa-karthik/fuzzy_bolt/llms.txt Fuzzy Bolt automatically employs Dart isolates for datasets exceeding a defined threshold (defaulting to 1000 items) to ensure non-blocking UI and improved performance. This feature can be explicitly controlled using `isolateThreshold` and `skipIsolate` parameters. ```dart import 'package:fuzzy_bolt/fuzzy_bolt.dart'; class Record { final String id; final String data; Record(this.id, this.data); } // Generate large dataset (5000+ items) final largeDataset = List.generate( 5000, (i) => Record('ID_$i', 'Record number $i with searchable data'), ); // Automatically uses isolates when dataset >= 1000 items final results = await FuzzyBolt.search( largeDataset, 'searchable', selectors: [(r) => r.data], isolateThreshold: 1000, // Use isolates at 1000+ (default) maxResults: 20, // Limit results for performance ); print('Found ${results.length} results'); print('First match: ${results.first.data}'); // Force synchronous processing (not recommended for large datasets) final syncResults = await FuzzyBolt.search( largeDataset, 'searchable', selectors: [(r) => r.data], skipIsolate: true, // Disable isolates ); ``` -------------------------------- ### Big Data Search with Result Limits Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Shows how to efficiently search through very large datasets (10,000+ items) while limiting the number of returned results. This snippet also highlights the automatic use of parallel processing for performance gains on substantial data volumes. ```dart final results = await FuzzyBolt.search( massiveUserList, // 10,000+ users 'alice', selectors: [(u) => u.name], maxResults: 10, // Get top 10 only ); // Automatically uses parallel processing—no config needed! ``` -------------------------------- ### Optimize Search Performance with Text Cache Management Source: https://context7.com/vishwa-karthik/fuzzy_bolt/llms.txt Fuzzy Bolt features an internal cache for text processing to enhance search performance. You can monitor cache statistics using `getTextCacheStats()` and clear the cache manually with `clearTextCache()` if memory constraints require it. ```dart import 'package:fuzzy_bolt/fuzzy_bolt.dart'; // Perform searches - cache builds automatically await FuzzyBolt.search(items, 'query1', selectors: [(i) => i.text]); await FuzzyBolt.search(items, 'query2', selectors: [(i) => i.text]); // Check cache statistics final stats = FuzzyBolt.getTextCacheStats(); print('Cache size: ${stats['size']}'); print('Hits: ${stats['hits']}'); print('Misses: ${stats['misses']}'); print('Hit rate: ${stats['hitRate']}%'); // Clear cache if needed (e.g., memory pressure) FuzzyBolt.clearTextCache(); // Verify cache cleared final newStats = FuzzyBolt.getTextCacheStats(); print('Cache cleared: ${newStats['size'] == 0}'); ``` -------------------------------- ### HR/Directory Employee Search Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Enables searching for employees across multiple attributes such as name, department, and title. This functionality is valuable for internal company directories or HR systems, helping to quickly locate individuals. ```dart final results = await FuzzyBolt.search( employees, 'john engineering', selectors: [(e) => e.name, (e) => e.department, (e) => e.title], ); ``` -------------------------------- ### Search With Text Processing Method - FuzzyBolt Source: https://github.com/vishwa-karthik/fuzzy_bolt/blob/main/README.md Performs fuzzy search with advanced text processing capabilities including stemming and stop word removal. Useful for linguistic analysis where word variations should match the same root form. Accepts multiple selector functions for multi-field searching. ```dart final results = await FuzzyBolt.searchWithTextProcessing
( articles, 'the runners are running', selectors: [(a) => a.title, (a) => a.content], enableStemming: true, // "runners" becomes "runner", "running" becomes "run" removeStopWords: true, // Removes "the", "are", etc. ); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.