{"id":25081773,"url":"https://github.com/rapideinternet/laravel-searchable","last_synced_at":"2025-04-01T09:43:04.096Z","repository":{"id":33482807,"uuid":"37128546","full_name":"rapideinternet/laravel-searchable","owner":"rapideinternet","description":"Laravel search provider","archived":false,"fork":false,"pushed_at":"2023-12-15T17:47:42.000Z","size":42,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-07T05:19:20.003Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rapideinternet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-09T11:41:46.000Z","updated_at":"2017-12-05T16:09:06.000Z","dependencies_parsed_at":"2022-08-19T01:20:55.672Z","dependency_job_id":null,"html_url":"https://github.com/rapideinternet/laravel-searchable","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rapideinternet%2Flaravel-searchable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rapideinternet%2Flaravel-searchable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rapideinternet%2Flaravel-searchable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rapideinternet%2Flaravel-searchable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rapideinternet","download_url":"https://codeload.github.com/rapideinternet/laravel-searchable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246620204,"owners_count":20806718,"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":[],"created_at":"2025-02-07T05:18:51.888Z","updated_at":"2025-04-01T09:43:04.069Z","avatar_url":"https://github.com/rapideinternet.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Searchable\nMakes models extending the SearchableModel class searchable by indexing them using two database tables and an extensive autmatically generated word list. It uses and improved version of the Metaphone phonetic algorithm, published by Lawrence Philips in 1990. The DoubleMetaphone method tries to account for spelling errors by generating two versions of the phonetic representation of the word.\nExample model\n-------\n\n``` php\n\u003c?php\n\nuse Searchable\\Models\\SearchableModel;\n\nclass Item extends SearchableModel {\n\t\n\t/**\n\t * The database table used by the model.\n\t *\n\t * @var string\n\t */\n\tprotected $table = 'items';\n\t\n\t/**\n\t * The attributes that are mass assignable.\n\t *\n\t * @var array\n\t */\n\tprotected $fillable = [ \n\t\t'name', \n\t\t'title',\n\t\t'content',\n\t\t];\n\t/**\n\t * The attributes that are automatically indexed and searchable.\n\t *\n\t * @var array\n\t */\n\tprotected $searchable = [\n\t\t'title' =\u003e 20,\n\t\t'content' =\u003e 5,\n\t\t];\t\n\n}\n```\n\nSetting up\n-------\nUpdate **composer.json** with the following entries\n```\n\"require\": {\n\t\"rapideinternet/laravel-searchable\": \"dev-master\"\n},\n\n\"repositories\": [\n\t{\n\t\t\"type\": \"vcs\",\n\t\t\"url\":  \"git@github.com:rapideinternet/laravel-searchable.git\"\n\t}\n],\n```\nUpdate your **config\\app.php**\n``` php\n'providers' =\u003e [\n\t...\n\t'Searchable\\SearchableServiceProvider',\n],\n\n'aliasses' =\u003e [\n\t...\n\t'Search'\t\t=\u003e 'Searchable\\Facades\\Search',\n],\n```\nRun the following shell commands\n```\ncomposer update\nphp artisan vendor:publish\nphp artisan migrate\n```\nUpdate your models by changing the following lines\n``` php\nclass Website extends Model {\n```\nTo extend the SearchableModel class instead of the Model class\n``` php\nclass Website extends SearchableModel {\n```\nAdd an array of searchable attributes. Each attribute carries a weight. More weight means higher relevance.\n``` php\nprotected $searchable = [\n\t'name' =\u003e 20,\n\t'comments' =\u003e 5,\n\t...\n];\n```\nFor example if searching for the word **\"John\"**, one item may contain 1 occurence of the query in the **'name'** attribute while another item contains 3 occurences of the query in the **'comments'** attribute.\n\nThe result would be that the first item has a score of 20 while the second item has a score of 15 and is ranked lower because the 'name' attirubte is more relevant.\n\nIndexing\n-------\nEvery time a model is saved or stored, it will automatically index the words present in the searchable array. This method is opportunistic and requires you to add new models through the ORM.\n\n###Artisan\nIf you already have data present in your database that you need to index. You can simply run the following command:\n\n```\nphp artisan searchable:index\n```\n\n###Scheduler\nIf you want to schedule this index you can add it to the Kernel like this.\n``` php\nprotected $commands = [\n\t...\n\t'Searchable\\Console\\Commands\\IndexCommand',\n];\n\nprotected function schedule(Schedule $schedule)\n{\n\t...\n\t$schedule-\u003ecommand('searchable:index')-\u003edailyAt('4:00');\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frapideinternet%2Flaravel-searchable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frapideinternet%2Flaravel-searchable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frapideinternet%2Flaravel-searchable/lists"}