Download the PHP package openplain/laravel-lightsearch without Composer
On this page you can find all versions of the php package openplain/laravel-lightsearch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download openplain/laravel-lightsearch
More information about openplain/laravel-lightsearch
Files in openplain/laravel-lightsearch
Package laravel-lightsearch
Short Description A lightweight Laravel Scout driver using database-backed search index. Perfect for small to medium datasets (1K-50K records) without external search services.
License MIT
Homepage https://github.com/openplain/laravel-lightsearch
Informations about the package laravel-lightsearch
Laravel LightSearch
Fast, database-backed search for Laravel Scout. No external services, no monthly fees, no infrastructure complexity.
Why This Package?
We created LightSearch because most Laravel applications don't need the complexity of external search services like Algolia or Meilisearch. For small to medium datasets, your existing database is perfectly capable of delivering fast, relevant search results.
Our Goal: Make search simple enough for MVPs, powerful enough for production, and cost-effective for bootstrapped projects.
Real-world performance: 2.95ms average search time on 26,000+ records (view benchmark)
Built on Proven Technology
Rather than reinventing the wheel, LightSearch leverages:
- Laravel Scout - Familiar API that works across all search drivers
- Inverted Index Pattern - Classic search architecture used by Meilisearch, Algolia, and Typesense
- Database-Specific Optimizations - PostgreSQL
pg_trgmfor fuzzy search, MySQL/SQLite optimized queries
Features
- π Database-Backed - Uses your existing MySQL, PostgreSQL, or SQLite database
- π° Zero Cost - No external services, no monthly fees
- β‘ Fast Setup - From install to working search in under 5 minutes
- π― Field Weighting - Boost relevance of important fields (title > content)
- π Fuzzy Search - Typo-tolerant search on PostgreSQL with
pg_trgm - π Unicode Support - Perfect handling of special characters (ΓΈ, Γ‘, Γ±, etc.)
- π§ Customizable - Stopwords, token length, field weights all configurable
- π¦ Scout Compatible - Drop-in replacement for Scout drivers
- π UUID Support - Works with string primary keys, not just integers
When to Use LightSearch
Perfect for:
- Small to medium datasets (1K-50K records)
- Budget-constrained projects
- MVPs and prototypes
- Applications already using Laravel Scout
- Simple hosting environments (no Docker required)
Not Ideal for:
- Large datasets (>100K records) β use Meilisearch, Algolia, or Typesense
- Complex multi-language search β use Algolia or Typesense
- Real-time autocomplete with sub-10ms response times
- Advanced features like faceted search, geo-search, or AI-powered ranking
Requirements
- PHP 8.2 or higher
- Laravel 11 or 12
- Laravel Scout 10 or higher
Installation
Install the package via Composer:
Publish and run migrations:
Optionally publish the configuration file:
Quick Start
1. Configure Scout Driver
Set LightSearch as your Scout driver in .env:
2. Make Your Model Searchable
Add the Searchable trait and define searchable fields:
3. Import Existing Data
Import your existing records into the search index:
For large datasets, use chunking:
4. Start Searching
Use Scout's familiar API to search your models:
Configuration
LightSearch is configured via config/lightsearch.php. All settings are optional with sensible defaults.
Field Weights
Boost relevance of specific fields by giving them higher weights. Fields with higher weights appear multiple times in the index, making matches more significant.
How it works: A post with "Laravel" in the title gets 3 index entries for "Laravel", while the same word in content gets only 1. This makes title matches score higher in results.
Stopwords
Common words to exclude from the search index. This reduces index size and improves performance.
Set to [] to disable stopword filtering.
Minimum Token Length
Minimum character length for a token to be indexed:
Note: Setting this too high (e.g., 4) prevents searching for short terms like "API" or "PHP".
Database Connection
Override the default database connection:
Useful if your search index should live on a different database than your application data.
How It Works
LightSearch uses an inverted index pattern (like Meilisearch, Algolia, and Typesense) implemented in your database:
- Indexing: Text is tokenized, normalized, and stored with field weights
- Search: Queries use prefix matching (or fuzzy matching on PostgreSQL)
- Ranking: Results ordered by occurrence count - more matches rank higher
Field weighting example: with title weight 3 and content weight 1, a match in the title counts 3Γ more than content.
Advanced Features
Fuzzy Search (PostgreSQL)
PostgreSQL users get automatic typo-tolerant search when the pg_trgm extension is enabled. It handles typos, missing accents, and character substitutions.
Enable pg_trgm (one-time setup):
That's it! Fuzzy search is now automatic:
Adjust threshold (optional):
See FUZZY_SEARCH_RESULTS.md for benchmarks.
Performance
Benchmarked with 26,191 addresses featuring special characters (ΓΈ, Γ‘, Γ°):
- Average search time: 2.95ms
- Dataset: 26,191 records
- Fuzzy search: ~110ms (PostgreSQL with pg_trgm)
Full benchmark report β
Comparison
| Solution | Setup | Speed | Cost | Typo Tolerance |
|---|---|---|---|---|
| LightSearch | 5 min | ~3ms | $0 | Yes (PostgreSQL) |
| Meilisearch | 30 min | ~1-5ms | $0-$$ | Yes |
| Algolia | 15 min | ~1-3ms | $$$ | Yes |
| Typesense | 30 min | ~1-5ms | $0-$ | Yes |
Limitations
Be aware of these limitations when choosing LightSearch:
- Prefix matching only - "search" finds "searching" but not "research"
- No typo tolerance on MySQL/SQLite - Only PostgreSQL with
pg_trgmsupports fuzzy search - Index size growth - ~4 index entries per record with default field weights
- Not optimized for autocomplete - Better solutions exist for real-time suggestions
- No faceted search - Can't filter by category/price/etc. in search results
- Single-language only - No multi-language stemming or morphology
Maintenance
Models are automatically indexed on create/update/delete.
Testing
Contributing
We welcome contributions! Please see CONTRIBUTING.md for details.
Security
If you discover a security vulnerability, please email [email protected]. All security vulnerabilities will be promptly addressed.
Please do not open public issues for security vulnerabilities.
License
The MIT License (MIT). Please see License File for more information.
Built with β€οΈ by Openplain
All versions of laravel-lightsearch with dependencies
laravel/scout Version ^9.0 || ^10.0 || ^11.0
illuminate/support Version ^10.0 || ^11.0 || ^12.0
illuminate/database Version ^10.0 || ^11.0 || ^12.0