{"id":13593582,"url":"https://github.com/typesense/laravel-scout-typesense-driver","last_synced_at":"2025-04-04T08:05:05.875Z","repository":{"id":41875105,"uuid":"382411325","full_name":"typesense/laravel-scout-typesense-driver","owner":"typesense","description":"Laravel Scout Driver for Typesense","archived":false,"fork":false,"pushed_at":"2024-04-07T13:34:59.000Z","size":154,"stargazers_count":136,"open_issues_count":16,"forks_count":39,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-28T07:02:25.756Z","etag":null,"topics":["laravel","laravel-package","laravel-scout","laravel-scout-driver","typesense"],"latest_commit_sha":null,"homepage":"https://typesense.org","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/typesense.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-02T17:01:07.000Z","updated_at":"2025-03-13T03:38:22.000Z","dependencies_parsed_at":"2023-11-27T21:30:29.378Z","dependency_job_id":"1b1168ef-b852-4406-82d8-ef581f4c6eff","html_url":"https://github.com/typesense/laravel-scout-typesense-driver","commit_stats":{"total_commits":139,"total_committers":15,"mean_commits":9.266666666666667,"dds":0.7410071942446044,"last_synced_commit":"115a70317f53b492aedb5b5d0ef45f3a3221d289"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typesense%2Flaravel-scout-typesense-driver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typesense%2Flaravel-scout-typesense-driver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typesense%2Flaravel-scout-typesense-driver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typesense%2Flaravel-scout-typesense-driver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/typesense","download_url":"https://codeload.github.com/typesense/laravel-scout-typesense-driver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247137027,"owners_count":20889792,"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","laravel-package","laravel-scout","laravel-scout-driver","typesense"],"created_at":"2024-08-01T16:01:21.809Z","updated_at":"2025-04-04T08:05:05.842Z","avatar_url":"https://github.com/typesense.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# Laravel Scout Typesense Driver \n\nThis package makes it easy to add full text search support to your models with Laravel 7.\\* to 11.\\*. \n\n\u003e [!IMPORTANT] \n\u003e The features from the Scout driver in this repo have been merged upstream into [Laravel Scout natively](https://laravel.com/docs/11.x/scout#typesense).\n\u003e \n\u003e So we've temporarily paused development in this repo and plan to instead address any issues or improvements in the native [Laravel Scout](https://github.com/laravel/scout) driver instead.\n\u003e \n\u003e If there are any Typesense-specific features that would be hard to implement in Laravel Scout natively (since we need to maintain consistency with all the other drivers), then at that point we plan to add those features into this driver and maintain it as a \"Scout Extended Driver\" of sorts. But it's too early to tell if we'd want to do this, so we're in a holding pattern on this repo for now.\n\u003e \n\u003e In the meantime, we recommend switching to the native Laravel Scout driver and report any issues in the [Laravel Scout repo](https://github.com/laravel/scout).\n\n\u003c!--\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/typesense/laravel-scout-typesense-driver.svg?style=flat-square)](https://packagist.org/packages/typesense/laravel-scout-typesense-driver) [![PHP from Packagist](https://img.shields.io/packagist/php-v/typesense/laravel-scout-typesense-driver?style=flat-square)](https://packagist.org/packages/typesense/laravel-scout-typesense-driver)\n\n--\u003e\n\n## Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Migrating from devloopsnet/laravel-typesense](#migrating-from-devloopsnetlaravel-typesense)\n- [Authors](#authors)\n- [License](#license)\n\n\n## Installation\nThe Typesense PHP SDK uses httplug to interface with various PHP HTTP libraries through a single API. \n\nFirst, install the correct httplug adapter based on your `guzzlehttp/guzzle` version. For example, if you're on \nLaravel 8, which includes Guzzle 7, then run this:\n\n```bash\ncomposer require php-http/guzzle7-adapter\n```\n\nThen install the driver:\n\n```bash\ncomposer require typesense/laravel-scout-typesense-driver\n```\n\nAnd add the service provider:\n\n```php\n// config/app.php\n'providers' =\u003e [\n    // ...\n    Typesense\\LaravelTypesense\\TypesenseServiceProvider::class,\n],\n```\n\nEnsure you have Laravel Scout as a provider too otherwise you will get an \"unresolvable dependency\" error\n\n```php\n// config/app.php\n'providers' =\u003e [\n    // ...\n    Laravel\\Scout\\ScoutServiceProvider::class,\n],\n```\n\nAdd `SCOUT_DRIVER=typesense` to your `.env` file\n\nThen you should publish `scout.php` configuration file to your config directory\n\n```bash\nphp artisan vendor:publish --provider=\"Laravel\\Scout\\ScoutServiceProvider\"\n```\n\nIn your `config/scout.php` add:\n\n```php\n\n'typesense' =\u003e [\n    'api_key'         =\u003e 'abcd',\n    'nodes'           =\u003e [\n      [\n        'host'     =\u003e 'localhost',\n        'port'     =\u003e '8108',\n        'path'     =\u003e '',\n        'protocol' =\u003e 'http',\n      ],\n    ],\n    'nearest_node'    =\u003e [\n        'host'     =\u003e 'localhost',\n        'port'     =\u003e '8108',\n        'path'     =\u003e '',\n        'protocol' =\u003e 'http',\n    ],\n    'connection_timeout_seconds'   =\u003e 2,\n    'healthcheck_interval_seconds' =\u003e 30,    \n    'num_retries'                  =\u003e 3,\n    'retry_interval_seconds'       =\u003e 1,\n  ],\n```\n\n## Usage\n\nIf you are unfamiliar with Laravel Scout, we suggest reading it's [documentation](https://laravel.com/docs/11.x/scout) first.\n\nAfter you have installed scout and the Typesense driver, you need to add the\n`Searchable` trait to your models that you want to make searchable. Additionaly,\ndefine the fields you want to make searchable by defining the `toSearchableArray` method on the model and implement `TypesenseSearch`:\n\n```php\n\u003c?php\n\nnamespace App;\n\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Typesense\\LaravelTypesense\\Interfaces\\TypesenseDocument;\nuse Laravel\\Scout\\Searchable;\n\nclass Todo extends Model implements TypesenseDocument\n{\n    use Searchable;\n    \n     /**\n     * Get the indexable data array for the model.\n     *\n     * @return array\n     */\n    public function toSearchableArray()\n    {\n        return array_merge(\n            $this-\u003etoArray(), \n            [\n                // Cast id to string and turn created_at into an int32 timestamp\n                // in order to maintain compatibility with the Typesense index definition below\n                'id' =\u003e (string) $this-\u003eid,\n                'created_at' =\u003e $this-\u003ecreated_at-\u003etimestamp,\n            ]\n        );\n    }\n\n     /**\n     * The Typesense schema to be created.\n     *\n     * @return array\n     */\n    public function getCollectionSchema(): array {\n        return [\n            'name' =\u003e $this-\u003esearchableAs(),\n            'fields' =\u003e [\n                [\n                    'name' =\u003e 'id',\n                    'type' =\u003e 'string',\n                ],\n                [\n                    'name' =\u003e 'name',\n                    'type' =\u003e 'string',\n                ],\n                [\n                    'name' =\u003e 'created_at',\n                    'type' =\u003e 'int64',\n                ],\n            ],\n            'default_sorting_field' =\u003e 'created_at',\n        ];\n    }\n\n     /**\n     * The fields to be queried against. See https://typesense.org/docs/0.24.0/api/search.html.\n     *\n     * @return array\n     */\n    public function typesenseQueryBy(): array {\n        return [\n            'name',\n        ];\n    }    \n}\n```\n\nThen, sync the data with the search service like:\n\n`php artisan scout:import App\\\\Models\\\\Todo`\n\nAfter that you can search your models with:\n\n`Todo::search('Test')-\u003eget();`\n\n## Adding via Query\nThe `searchable()` method will chunk the results of the query and add the records to your search index. Examples:\n\n```php\n$todo = Todo::find(1);\n$todo-\u003esearchable();\n\n$todos = Todo::where('created_at', '\u003c', now())-\u003eget();\n$todos-\u003esearchable();\n```\n\n### Multi Search\nYou can send multiple search requests in a single HTTP request, using the Multi-Search feature.\n```php\n$searchRequests = [\n    [\n      'collection' =\u003e 'todo',\n      'q' =\u003e 'todo'\n    ],\n    [\n      'collection' =\u003e 'todo',\n      'q' =\u003e 'foo'\n    ]\n];\n\nTodo::search('')-\u003esearchMulti($searchRequests)-\u003epaginateRaw();\n```\n\n### Generate Scoped Search Key\n\nYou can generate scoped search API keys that have embedded search parameters in them. This is useful in a few different scenarios:\n1. You can index data from multiple users/customers in a single Typesense collection (aka multi-tenancy) and create scoped search keys with embedded `filter_by` parameters that only allow users access to their own subset of data.\n2. You can embed any [search parameters](https://typesense.org/docs/0.24.0/api/search.html#search-parameters) (for eg: `exclude_fields` or `limit_hits`) to prevent users from being able to modify it client-side.\n\nWhen you use these scoped search keys in a search API call, the parameters you embedded in them will be automatically applied by Typesense and users will not be able to override them.\n\n```php\n\u003c?php\n\nnamespace App;\n\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Laravel\\Scout\\Searchable;\nuse Typesense\\LaravelTypesense\\Concerns\\HasScopedApiKey;\nuse Typesense\\LaravelTypesense\\Interfaces\\TypesenseDocument;\n\nclass Todo extends Model implements TypesenseDocument\n{\n    use Searchable, HasScopedApiKey;\n}\n```\n\n#### Usage\n```php\nTodo::setScopedApiKey('xyz')-\u003esearch('todo')-\u003eget();\n```\n\n## Migrating from devloopsnet/laravel-typesense\n- Replace `devloopsnet/laravel-typesense` in your composer.json requirements with `typesense/laravel-scout-typesense-driver`\n- The Scout driver is now called `typesense`, instead of `typesensesearch`. This should be reflected by setting the SCOUT_DRIVER env var to `typesense`,\n  and changing the config/scout.php config key from `typesensesearch` to `typesense`\n- Instead of importing `Devloops\\LaravelTypesense\\*`, you should import `Typesense\\LaravelTypesense\\*`\n- Instead of models implementing `Devloops\\LaravelTypesense\\Interfaces\\TypesenseSearch`, they should implement `Typesense\\LaravelTypesense\\Interfaces\\TypesenseDocument`\n\n## Authors\nThis package was originally authored by [Abdullah Al-Faqeir](https://github.com/AbdullahFaqeir) and his company DevLoops: https://github.com/devloopsnet/laravel-scout-typesense-engine. It has since been adopted into the Typesense Github org. \n\nOther key contributors include:\n\n- [hi019](https://github.com/hi019)\n- [Philip Manavopoulos](https://github.com/manavo)\n\n## License\n\nThe MIT License (MIT). Please see the [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypesense%2Flaravel-scout-typesense-driver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftypesense%2Flaravel-scout-typesense-driver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypesense%2Flaravel-scout-typesense-driver/lists"}