{"id":19388808,"url":"https://github.com/james2doyle/laravel-scout-sonic","last_synced_at":"2025-04-23T23:31:46.161Z","repository":{"id":56331550,"uuid":"180035537","full_name":"james2doyle/laravel-scout-sonic","owner":"james2doyle","description":"Sonic driver for Laravel Scout","archived":false,"fork":false,"pushed_at":"2020-11-13T19:48:03.000Z","size":25,"stargazers_count":53,"open_issues_count":0,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-25T04:42:28.606Z","etag":null,"topics":["laravel","scout","search","sonic"],"latest_commit_sha":null,"homepage":null,"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/james2doyle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-07T23:19:37.000Z","updated_at":"2024-02-10T16:29:25.000Z","dependencies_parsed_at":"2022-08-15T16:50:24.848Z","dependency_job_id":null,"html_url":"https://github.com/james2doyle/laravel-scout-sonic","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james2doyle%2Flaravel-scout-sonic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james2doyle%2Flaravel-scout-sonic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james2doyle%2Flaravel-scout-sonic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/james2doyle%2Flaravel-scout-sonic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/james2doyle","download_url":"https://codeload.github.com/james2doyle/laravel-scout-sonic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250532110,"owners_count":21446118,"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":["laravel","scout","search","sonic"],"created_at":"2024-11-10T10:13:47.448Z","updated_at":"2025-04-23T23:31:45.845Z","avatar_url":"https://github.com/james2doyle.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Laravel Scout Sonic Driver\n==========================\n\nSearch Eloquent Models using [Sonic](https://github.com/valeriansaliou/sonic) indexes.\n\n1. [Implementation](#implementation)\n2. [Installation](#installation)\n3. [Usage](#usage)\n\nImplementation \u003cdiv id=\"implementation\"\u003e\u003c/div\u003e\n-------------\n\nWhen implementing the `toSearchableArray` method, you need to provide an array that will be coerced into a string (the engine just joins with a `' '`) as Sonic can only index strings. So you need to provide a \"stringified\" (index string) version of your model. The default `toArray` works but it is probably too much noise for reasonable usage.\n\nHere is an example of the string I used when I was developing this Engine:\n\n```php\npublic function toSearchableArray()\n{\n    return array_filter([$this-\u003edisplay_name, $this-\u003efirst_name, $this-\u003elast_name]);\n}\n```\n\nFor me, this builds a nice string for search that can match on a \"name\". In my application, the concept of \"name\" is either the User display name or first/last name.\n\n---\n\nIf the locale is known, you can also create the `getSonicLocale()` method on your model, which returns the locale. It will then get passed to the Sonic `PUSH` calls:\n\n```php\n// an ISO 639-3 locale code eg. eng for English (if set, the locale must be a valid ISO 639-3 code; if set to none, lexing will be disabled; if not set, the locale will be guessed from text)\npublic function getSonicLocale() {\n    return 'none';\n}\n```\n\nInstallation \u003cdiv id=\"installation\"\u003e\u003c/div\u003e\n------------\n\nIf you haven't already you should [install Laravel Scout](https://laravel.com/docs/5.8/scout#installation) to\nyour project and apply the `Laravel\\Scout\\Searchable` trait to any Eloquent models you would like to make searchable.\n\nInstall this package via **Composer**\n\n`composer require james2doyle/laravel-scout-sonic`\n\n**Note: if you have Laravel \u003e= 5.5 you can skip this step because of Package Auto-Discovery.**\n\nNext add the ServiceProvider to the Package Service Providers in `config/app.php`\n\n\n```php\n/*\n * Package Service Providers...\n */\njames2doyle\\SonicScout\\Providers\\SonicScoutServiceProvider::class,\n```\n\nAppend the default configuration to `config/scout.php`\n\n```php\n/*\n|--------------------------------------------------------------------------\n| Sonic Configuration\n|--------------------------------------------------------------------------\n|\n| Here you may configure your Sonic settings.\n|\n*/\n\n'sonic' =\u003e [\n    'address' =\u003e \\env('SONIC_ADDRESS', 'localhost'),\n    'port' =\u003e \\env('SONIC_PORT', 1491),\n    'password' =\u003e \\env('SONIC_PASSWORD'),\n    'connection_timeout' =\u003e \\env('SONIC_CONNECTION_TIMEOUT', 10),\n    'read_timeout' =\u003e \\env('SONIC_READ_TIMEOUT',  5)\n],\n```\n\nSet `SCOUT_DRIVER=sonic` in your `.env` file\n\nIn addition there is no need to use the `php artisan scout:import` command.\n\n\nUsage \u003cdiv id=\"usage\"\u003e\u003c/div\u003e\n-----\n\nSimply call the `search()` method on your `Searchable` models:\n\n`$users = App\\User::search('bro')-\u003eget();`\n\nSimple constraints can be applied using the `where()` builder method:\n\n`$users = App\\User::search('bro')-\u003ewhere('active', 1)-\u003eget();`\n\n**Note: Sonic does not support the concept of \"where\", so the where is applied at the collection level not the query!**\n\n### Pagination\n\nSonic cannot support real pagination because Sonic does not return proper paging or total information. It simply returns all the results for a given query.\n\nThere is a naive implementation of pagination in place but it probably isn't perfect as it doesn't take into account the \"where\" filter.\n\nFor more usage information see the [Laravel Scout Documentation](https://laravel.com/docs/5.3/scout).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjames2doyle%2Flaravel-scout-sonic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjames2doyle%2Flaravel-scout-sonic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjames2doyle%2Flaravel-scout-sonic/lists"}