plusinfolab / search
Advanced search package for Laravel with multiple algorithms, Eloquent integration, and SQLite FTS support
Fund package maintenance!
plusinfolab
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/plusinfolab/search
Requires
- php: ^8.2
- illuminate/contracts: ^11.0||^12.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.8
- orchestra/testbench: ^10.0.0||^9.0.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- spatie/laravel-ray: ^1.35
This package is auto-updated.
Last update: 2025-12-05 09:36:03 UTC
README
A comprehensive, production-ready search solution for Laravel applications with 9 powerful search algorithms, seamless Eloquent integration, and SQLite FTS support. Make searching in your Laravel apps incredibly easy and powerfulβno external services required!
β¨ Features
π Multiple Search Algorithms
- Exact Match - Perfect for precise searches
- Partial Match - Substring matching with intelligent scoring
- Prefix/Suffix - Great for autocomplete
- Fuzzy Search - Levenshtein distance for typo tolerance
- Trigram Search - Advanced similarity matching
- Boolean Search - AND/OR/NOT operators with phrase support
- Regex Search - Pattern matching with safety checks
- Phonetic Search - Soundex/Metaphone for "sounds-like" searches
π Advanced Features
- Smart Ranking - Multi-factor scoring (algorithm weights, field weights, recency, popularity)
- Result Highlighting - Automatic highlighting of matched terms
- Search Suggestions - Autocomplete and "did you mean" functionality
- Synonym Expansion - Configurable synonym dictionaries
- Caching - Built-in result caching for performance
- Search History - Track and analyze search queries
π Eloquent Integration
- Simple
Searchabletrait for models - Fluent query builder API
- Automatic index synchronization
- Configurable field weights
- No external dependencies required!
ποΈ SQLite FTS Support
- Automatic FTS5 table creation
- Real-time index synchronization
- Optimized full-text search
π¦ Installation
Install via Composer:
composer require plusinfolab/search
Publish the configuration file:
php artisan vendor:publish --tag="search-config"
Optionally, publish and run migrations for search history:
php artisan vendor:publish --tag="search-migrations"
php artisan migrate
π Quick Start
1. Make Your Model Searchable
use Illuminate\Database\Eloquent\Model; use PlusInfoLab\Search\Traits\Searchable; class Post extends Model { use Searchable; // Define searchable fields protected $searchable = ['title', 'content', 'tags']; // Optional: Define field weights for ranking protected $searchWeights = [ 'title' => 10, // Title matches score higher 'content' => 5, // Content matches score medium 'tags' => 3, // Tag matches score lower ]; }
2. Search Your Models
// Simple search using default algorithm (partial match) $posts = Post::search('laravel')->get(); // Search with specific algorithm $posts = Post::search('laravle', 'fuzzy')->get(); // Get search results with scores and metadata $results = Post::searchQuery('laravel framework'); foreach ($results as $result) { echo $result->getItem()->title; echo "Score: " . $result->getScore(); echo "Matched fields: " . implode(', ', $result->getMatchedFields()); }
π Usage Examples
Using the Search Facade
use PlusInfoLab\Search\Facades\Search; // Create a search query $query = Search::query('laravel framework') ->in(['title', 'content']) ->weights(['title' => 10, 'content' => 5]) ->using('fuzzy') ->minScore(0.5) ->limit(10); // Execute search on Eloquent builder $results = Search::search($query->setBuilder(Post::query()));
Boolean Search
// AND operator $posts = Post::search('laravel AND framework', 'boolean')->get(); // OR operator $posts = Post::search('laravel OR symfony', 'boolean')->get(); // NOT operator $posts = Post::search('framework NOT deprecated', 'boolean')->get(); // Complex queries with grouping $posts = Post::search('(laravel OR symfony) AND framework NOT old', 'boolean')->get(); // Exact phrases $posts = Post::search('"laravel framework" AND tutorial', 'boolean')->get();
Fuzzy Search (Typo Tolerance)
// Will match "Laravel", "Laravle", "Laravell", etc. $posts = Post::search('Laravle', 'fuzzy')->get(); // Configure threshold in config/search.php 'fuzzy' => [ 'threshold' => 2, // Maximum Levenshtein distance ],
Phonetic Search (Sounds-Like)
// Will match "Stephen", "Steven", "Stefan" $users = User::search('Stephen', 'phonetic')->get(); // Configure algorithm (soundex or metaphone) 'phonetic' => [ 'algorithm' => 'metaphone', // or 'soundex' ],
Prefix Search (Autocomplete)
// Match titles starting with "lar" $posts = Post::search('lar', 'prefix')->get(); // Returns: "Laravel Tutorial", "Laravel Tips", etc.
With Highlighting
$results = Post::searchQuery('laravel framework'); foreach ($results as $result) { $highlights = $result->getHighlights(); // Highlights contain matched fragments with <mark> tags echo $highlights['title'][0]; // Output: "The <mark>Laravel</mark> <mark>Framework</mark> Guide" }
Search Suggestions
use PlusInfoLab\Search\Facades\Search; // Get autocomplete suggestions $suggestions = Search::suggest('larav', ['Laravel', 'JavaScript', 'Laravel Nova'], 5); // Returns: ['Laravel', 'Laravel Nova'] // "Did you mean" functionality $suggester = app(\PlusInfoLab\Search\Features\SearchSuggester::class); $suggestion = $suggester->didYouMean('laravle', ['Laravel', 'Symfony', 'CodeIgniter']); // Returns: 'Laravel'
Synonym Expansion
// Configure synonyms in config/search.php 'synonyms' => [ 'enabled' => true, 'dictionary' => [ 'car' => ['automobile', 'vehicle'], 'phone' => ['mobile', 'smartphone', 'cellphone'], ], ], // Search for "car" will also search for "automobile" and "vehicle" $results = Product::searchQuery('car');
Advanced Ranking
// Configure ranking in config/search.php 'ranking' => [ 'enabled' => true, // Boost recent results 'recency_boost' => [ 'enabled' => true, 'field' => 'created_at', 'decay_days' => 30, 'boost_factor' => 1.5, ], // Boost popular results 'popularity_boost' => [ 'enabled' => true, 'field' => 'views_count', 'boost_factor' => 0.1, ], ],
SQLite FTS Integration
// Enable in config/search.php 'fts' => [ 'enabled' => true, 'version' => 'fts5', 'auto_sync' => true, // Automatically sync model changes ], // FTS tables are created automatically // Search uses FTS when available for better performance $posts = Post::search('laravel')->get();
βοΈ Configuration
The package is highly configurable. Here are some key options:
// config/search.php return [ // Default search algorithm 'default_algorithm' => 'partial', // Algorithm-specific settings 'algorithms' => [ 'fuzzy' => [ 'threshold' => 2, 'max_length' => 255, ], 'trigram' => [ 'min_similarity' => 0.3, ], // ... more algorithms ], // Ranking configuration 'ranking' => [ 'enabled' => true, 'algorithm_weights' => [ 'exact' => 100, 'prefix' => 80, 'partial' => 60, 'fuzzy' => 40, ], ], // Caching 'cache' => [ 'enabled' => true, 'ttl' => 3600, ], // Highlighting 'highlighting' => [ 'enabled' => true, 'prefix' => '<mark>', 'suffix' => '</mark>', ], ];
π§ͺ Testing
composer test
Run tests with coverage:
composer test-coverage
π Performance
- Zero external dependencies - Pure PHP implementation
- Optimized algorithms - Efficient string matching
- Built-in caching - Cache search results
- FTS support - Use SQLite FTS5 for large datasets
- Configurable limits - Prevent performance issues
π― Use Cases
- E-commerce - Product search with typo tolerance
- Blog/CMS - Content search with highlighting
- Documentation - Technical documentation search
- User Directory - Name search with phonetic matching
- Knowledge Base - Boolean search for complex queries
- Autocomplete - Prefix search for suggestions
π Requirements
- PHP 8.2 or higher
- Laravel 11.x or 12.x
- SQLite 3.9.0+ (optional, for FTS support)
π§ͺ Testing
Run the test suite:
composer test
Run tests with coverage:
composer test-coverage
Run static analysis:
composer analyse
π Changelog
Please see CHANGELOG for more information on what has changed recently.
π€ Contributing
Contributions are welcome! Please see CONTRIBUTING for details.
Development Setup
- Clone the repository
- Install dependencies:
composer install - Run tests:
composer test - Run static analysis:
composer analyse - Format code:
composer format
π Security
If you discover any security issues, please email aditya@plusinfolab.in instead of using the issue tracker.
π License
The MIT License (MIT). Please see License File for more information.
π Credits
- Aditya Jodhani - Creator & Maintainer
- PlusInfoLab - Development Company
- All Contributors
π¬ Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: aditya@plusinfolab.in
π Why This Package?
Unlike other search solutions that require external services (Elasticsearch, Algolia) or complex setup, this package:
- β Works out of the box with zero configuration
- β No external dependencies or services required
- β Multiple algorithms for different use cases
- β Seamless Eloquent integration
- β Production-ready with caching and optimization
- β Highly configurable and extensible
- β Comprehensive documentation and examples
- β 100% Free and Open Source
π Roadmap
Future features planned:
- MySQL Full-Text Search integration
- PostgreSQL Full-Text Search integration
- Elasticsearch adapter
- Multi-language support
- Advanced analytics dashboard
- Performance monitoring tools
β Show Your Support
If you find this package useful, please consider giving it a β on GitHub!
Make search awesome in your Laravel apps! π
Version: 1.0.0 | Released: December 2025 | License: MIT