Download the PHP package provision/searchable without Composer
On this page you can find all versions of the php package provision/searchable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download provision/searchable
More information about provision/searchable
Files in provision/searchable
Package searchable
Short Description Searchable indexing with MySQL full text for Laravel
License MIT
Homepage https://github.com/provisionbg/searchable
Informations about the package searchable
Laravel MySQL fulltext search
This package creates a MySQL fulltext index for models and enables you to search through those.
Requirements
- Laravel >= 5.7
- MySQL >= 5.6 / MariaDB >= 10.0.15
Important!
In config/database.php
set
Install
- Install with composer
composer require provision/searchable
. - Publish migrations and config
php artisan vendor:publish --tag=searchable
- Migrate the database
php artisan migrate
Usage
The package uses a model observer to update the index when models change. If you want to run a full index you can use the console commands.
Models
Add the SearchableTrait
trait to the model you want to have indexed and define the columns you'd like to index as title and content.
Example
You can use a dot notation to query relationships for the model, like contacts.value
.
Relation model indexing
On related model for indexing use SearchableRelationTrait
and method getSearchableRelationName
to return relation name.
Listen for changes on relation and update parent model
Example
Searching
You can search using the search
method.
Search with specific fulltext search mode
Available modes
NaturalLanguage
- IN NATURAL LANGUAGE MODENaturalLanguageWithQueryExpression
- IN NATURAL LANGUAGE MODE WITH QUERY EXPANSIONBoolean
- IN BOOLEAN MODEQueryExpression
- WITH QUERY EXPANSION
MySQL fulltext search documentation: https://dev.mysql.com/doc/refman/8.0/en/fulltext-search.html
Search with relations & additional wheres
Order searchable score
Available options:
ASC
DESC
Commands
searchable:index
Index all models for a certain class
Example
- Indexing all clients
php artisan searchable:index "\App\Models\Client"
- Indexing specific client by id
php artisan searchable:index "\App\Models\Client" 1
searchable:unindex
UnIndex all models for a certain class
Example
- UnIndexing all clients
php artisan searchable:unindex "\App\Models\Client"
- UnIndexing specific client by id
php artisan searchable:unindex "\App\Models\Client" 1
Config options
db_connection
Choose the database connection to use, defaults to the default database connection. When you are NOT using the default database connection, this MUST be set before running the migration to work correctly.
table_name
Table name of index
command_prefix
Prefix of commands
weight.title
, weight.content
Results on title
or content
are weighted in the results. Search result score is multiplied by the weight in this config
cleaners
Clean searching keywords for prevent breaking the MySQL query.