Looking to hire Laravel developers? Try LaraJobs

laravel-smart-search maintained by traore225

Description
A lightweight, configurable, scoring-based search engine for Laravel with FULLTEXT support and automatic fallback.
Author
Last update
2026/02/18 11:45 (dev-main)
License
Links
Downloads
0

Comments
comments powered by Disqus

Laravel Smart Search

Latest Version on Packagist Total Downloads License

A lightweight, configurable, scoring-based search engine for Laravel.

Laravel Smart Search provides:

  • Exact match priority
  • Weighted scoring system
  • FULLTEXT support (MySQL/MariaDB)
  • Automatic fallback to LIKE search
  • Configurable columns
  • Safe FULLTEXT detection (no crashes)
  • Optional fallback disabling per request

Installation

Install via Composer:

composer require traore225/laravel-smart-search

Requirements

  • PHP 8.1+
  • Laravel 10+ / 11+
  • MySQL or MariaDB recommended for FULLTEXT support

Publish Configuration

php artisan vendor:publish --tag=smart-search-config

This creates:

config/smart-search.php


FULLTEXT Setup (Recommended)

Generate a migration for your FULLTEXT index:

php artisan smart-search:make-index --table=posts --columns=title
php artisan migrate

Check if FULLTEXT is installed:

php artisan smart-search:install --table=posts --column=title

If you prefer to add it manually:

ALTER TABLE posts ADD FULLTEXT (title);

FULLTEXT is optional but recommended for performance. Smart Search automatically detects if FULLTEXT is available and safely disables it if missing.


Basic Usage

use Traore225\LaravelSmartSearch\Search\SearchEngine;

$engine = app(SearchEngine::class);

$query = \App\Models\Post::query();

$query = $engine->apply($query, [
    'description' => 'ps3 controller',
]);

$results = $query->paginate();

Disable Fallback (Per Request)

$query = $engine->apply($query, [
    'description' => 'ps3 controller',
    'fallback' => false,
]);

Configuration Example

return [
    'max_title_tokens' => 3,

    'columns' => [
        'title' => 'title',
        'description' => 'description',
    ],

    'fulltext' => [
        'enabled' => true,
        'multiplier' => 10,
    ],

    'weights' => [
        'exact_title' => 1000000,
        'title_word_base' => 4000,
        'title_word_step' => 500,
        'title_cumulative_base' => 3000,
        'title_cumulative_step' => 300,
    ],

    'fallback' => [
        'enabled' => true,
        'min_words' => 2,
        'fields' => ['title', 'description'],
    ],
];

How It Works

Priority order:

  1. Exact match
  2. Weighted LIKE scoring
  3. FULLTEXT boolean scoring (if available)
  4. Fallback LIKE search (if enabled)

FULLTEXT is auto-detected and safely disabled when the index is missing.


Database Support

Database Support
MySQL Full
MariaDB Full
PostgreSQL LIKE fallback only
SQLite LIKE fallback only

Performance

  • FULLTEXT auto-detected and cached
  • No crash if index is missing
  • Minimal overhead
  • No external dependencies

License

MIT License © 2026 Traore Sidiki