{"id":18716083,"url":"https://github.com/provisionbg/searchable","last_synced_at":"2025-08-18T15:31:38.593Z","repository":{"id":52712211,"uuid":"227601431","full_name":"ProVisionBG/searchable","owner":"ProVisionBG","description":"Laravel searchable with MySQL full text search","archived":false,"fork":false,"pushed_at":"2024-06-18T07:28:07.000Z","size":35,"stargazers_count":23,"open_issues_count":2,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-09T06:11:39.661Z","etag":null,"topics":["fulltext","laravel","mysql","search"],"latest_commit_sha":null,"homepage":"https://pvmg.co","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ProVisionBG.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-12T12:26:52.000Z","updated_at":"2024-04-07T12:13:26.000Z","dependencies_parsed_at":"2024-11-07T13:12:03.218Z","dependency_job_id":"625892aa-d4cb-4911-8620-6a72f8b5858e","html_url":"https://github.com/ProVisionBG/searchable","commit_stats":{"total_commits":42,"total_committers":3,"mean_commits":14.0,"dds":"0.11904761904761907","last_synced_commit":"fd9a48969c293a2af4dfcc380b839a9cb910341c"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProVisionBG%2Fsearchable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProVisionBG%2Fsearchable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProVisionBG%2Fsearchable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProVisionBG%2Fsearchable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ProVisionBG","download_url":"https://codeload.github.com/ProVisionBG/searchable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230245333,"owners_count":18196134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fulltext","laravel","mysql","search"],"created_at":"2024-11-07T13:11:30.580Z","updated_at":"2024-12-18T09:09:40.925Z","avatar_url":"https://github.com/ProVisionBG.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/ProVisionBG/searchable.svg?branch=master)](https://travis-ci.org/ProVisionBG/searchable)\n\n# Laravel MySQL fulltext search\n\nThis package creates a MySQL fulltext index for models and enables you to search through those.\n\n## Requirements\n\n- Laravel \u003e= 5.7\n- MySQL \u003e= 5.6 / MariaDB \u003e= 10.0.15\n\n#### Important! \n\nIn `config/database.php` set \n```php\n'mysql' =\u003e [\n...\n    'strict' =\u003e false,\n...\n]\n```\n\n## Install\n\n1. Install with composer ``composer require provision/searchable``.\n2. Publish migrations and config ``php artisan vendor:publish --tag=searchable``\n3. Migrate the database ``php artisan migrate``\n\n## Usage\n\nThe 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.\n\n### Models\n\nAdd the ``SearchableTrait`` trait to the model you want to have indexed and define the columns you'd like to index as title and content.\n\n#### Example\n```\nclass Clients extends Model\n{\n\n    use \\ProVision\\Searchable\\Traits\\SearchableTrait;\n\n    /**\n     * @inheritDoc\n     */\n    protected function getSearchableTitleColumns(): array\n    {\n        return [\n            'name'\n        ];\n    }\n\n    /**\n     * @inheritDoc\n     */\n    protected function getSearchableContentColumns(): array\n    {\n        return [\n            'description',\n            'address',\n            'vat_number',\n            'contacts.value',\n            'contactPersons.first_name',\n            'contactPersons.last_name',\n            'contactPersons.contacts.value',\n        ];\n    }\n\n}\n```\n\nYou can use a dot notation to query relationships for the model, like ``contacts.value``.\n\n### Relation model indexing\n\nOn related model for indexing use `SearchableRelationTrait` and method `getSearchableRelationName` to return relation name.\n\nListen for changes on relation and update parent model\n\n#### Example\n\n```\nclass Contact extends Model\n{\n    use \\ProVision\\Searchable\\Traits\\SearchableRelationTrait;\n\n     /**\n     * @return MorphTo\n     */\n    public function contactable()\n    {\n        return $this-\u003emorphTo();\n    }\n\n    /**\n     * @inheritDoc\n     */\n    static function getSearchableRelationName(): string\n    {\n        return 'contactable';\n    }\n}\n```\n\n### Searching \n\nYou can search using the `search` method.\n\n```\n$clientsCollection = Clients::search('John Doe')-\u003epaginate();\n```\n\n#### Search with specific fulltext search mode\n\n```\nuse ProVision\\Searchable\\SearchableModes;\n---\n$clientsCollection = Clients::search('John Doe', SearchableModes::Boolean)-\u003epaginate();\n```\n\nAvailable modes\n- `NaturalLanguage` - IN NATURAL LANGUAGE MODE\n- `NaturalLanguageWithQueryExpression` - IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION \n- `Boolean` - IN BOOLEAN MODE\n- `QueryExpression` - WITH QUERY EXPANSION\n\nMySQL fulltext search documentation: https://dev.mysql.com/doc/refman/8.0/en/fulltext-search.html\n\n#### Search with relations \u0026 additional wheres\n\n```\n$clientsCollection = Clients::search('John Doe')-\u003ewhere('active', 1)-\u003ewith(['contacts'])-\u003epaginate();\n```\n\n#### Order searchable score\n\n```\n$clientsCollection = Clients::search('John Doe')-\u003esearchableOrder('asc')-\u003epaginate();\n```\n\nAvailable options:\n\n- `ASC`\n- `DESC`\n\n### Commands\n\n\n#### searchable:index\n\nIndex all models for a certain class\n```\n php artisan  searchable:index\n \nUsage:\n  searchable:index \u003cmodel_class\u003e {id?}\n\nArguments:\n  model_class           Classname of the model to index\n  id                    Model id to index (optional)\n\n```\n\n##### Example\n\n- Indexing all clients\n\n``php artisan  searchable:index \"\\App\\Models\\Client\"``\n \n- Indexing specific client by id\n\n``php artisan  searchable:index \"\\App\\Models\\Client\" 1`` \n\n#### searchable:unindex\n\nUnIndex all models for a certain class\n```\n php artisan  searchable:unindex\n \nUsage:\n  searchable:unindex \u003cmodel_class\u003e {id?}\n\nArguments:\n  model_class           Classname of the model to index\n  id                    Model id to unindex (optional)\n\n```\n\n##### Example\n\n- UnIndexing all clients\n\n``php artisan  searchable:unindex \"\\App\\Models\\Client\"``\n \n- UnIndexing specific client by id\n\n``php artisan  searchable:unindex \"\\App\\Models\\Client\" 1`` \n\n## Config options\n\n### `db_connection`\n\nChoose 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.\n\n### `table_name`\n\nTable name of index\n\n### `command_prefix`\n\nPrefix of commands\n \n### `weight.title`, `weight.content`\n\nResults on ``title`` or ``content`` are weighted in the results. Search result score is multiplied by the weight in this config \n\n### `cleaners`\n\nClean searching keywords for prevent breaking the MySQL query.\n\n## Testing\n\n``` bash\n$ composer test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprovisionbg%2Fsearchable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprovisionbg%2Fsearchable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprovisionbg%2Fsearchable/lists"}