{"id":18310303,"url":"https://github.com/torann/laravel-cloudsearch","last_synced_at":"2025-04-05T17:33:28.127Z","repository":{"id":57071909,"uuid":"94698173","full_name":"Torann/laravel-cloudsearch","owner":"Torann","description":"Index and search Laravel models on Amazon's CloudSearch","archived":false,"fork":false,"pushed_at":"2020-02-13T15:11:38.000Z","size":41,"stargazers_count":22,"open_issues_count":6,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-21T08:34:52.487Z","etag":null,"topics":["aws","cloudsearch","laravel","search"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Torann.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":"2017-06-18T16:07:24.000Z","updated_at":"2022-11-18T15:12:06.000Z","dependencies_parsed_at":"2022-08-24T10:52:13.223Z","dependency_job_id":null,"html_url":"https://github.com/Torann/laravel-cloudsearch","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Torann%2Flaravel-cloudsearch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Torann%2Flaravel-cloudsearch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Torann%2Flaravel-cloudsearch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Torann%2Flaravel-cloudsearch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Torann","download_url":"https://codeload.github.com/Torann/laravel-cloudsearch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247375980,"owners_count":20929161,"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":["aws","cloudsearch","laravel","search"],"created_at":"2024-11-05T16:14:01.628Z","updated_at":"2025-04-05T17:33:23.116Z","avatar_url":"https://github.com/Torann.png","language":"PHP","funding_links":["https://www.patreon.com/torann","https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=4CJA2A97NPYVU"],"categories":[],"sub_categories":[],"readme":"# Laravel CloudSearch\n\n[![Latest Stable Version](https://poser.pugx.org/torann/laravel-cloudsearch/v/stable.png)](https://packagist.org/packages/torann/laravel-cloudsearch)\n[![Total Downloads](https://poser.pugx.org/torann/laravel-cloudsearch/downloads.png)](https://packagist.org/packages/torann/laravel-cloudsearch)\n[![Patreon donate button](https://img.shields.io/badge/patreon-donate-yellow.svg)](https://www.patreon.com/torann)\n[![Donate weekly to this project using Gratipay](https://img.shields.io/badge/gratipay-donate-yellow.svg)](https://gratipay.com/~torann)\n[![Donate to this project using Flattr](https://img.shields.io/badge/flattr-donate-yellow.svg)](https://flattr.com/profile/torann)\n[![Donate to this project using Paypal](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=4CJA2A97NPYVU)\n\nIndex and search Laravel models on Amazon's CloudSearch. To get started, you should have a basic knowledge of how CloudSearch works.\n\n## Installation\n\n### Composer\n\nFrom the command line run:\n\n```\n$ composer require torann/laravel-cloudsearch\n```\n\n### Laravel\n\nOnce installed you need to register the service provider with the application. Open up `config/app.php` and find the `providers` key.\n\n``` php\n'providers' =\u003e [\n\n    LaravelCloudSearch\\LaravelCloudSearchServiceProvider::class,\n\n]\n```\n\n### Lumen\n\nFor Lumen register the service provider in `bootstrap/app.php`.\n\n``` php\n$app-\u003eregister(LaravelCloudSearch\\LaravelCloudSearchServiceProvider::class);\n```\n\n### Publish the configurations\n\nRun this on the command line from the root of your project:\n\n```\n$ php artisan vendor:publish --provider=\"LaravelCloudSearch\\LaravelCloudSearchServiceProvider\" --tag=config\n```\n\nA configuration file will be publish to `config/cloud-search.php`.\n\n\n### Migration\n\nThe package uses a batch queue system for updating the documents on AWS. This is done to help reduce the number of calls made to the API (will save money in the long run).\n\n```bash\nphp artisan vendor:publish --provider=\"LaravelCloudSearch\\LaravelCloudSearchServiceProvider\" --tag=migrations\n```\n\nRun this on the command line from the root of your project to generate the table for storing currencies:\n\n```bash\n$ php artisan migrate\n```\n\n## Fields\n\nThe better help manage fields, the package ships with a simple field management command. This is completely optional, as you can manage them in the AWS console.\n\n\u003e **NOTE:** If you choose not to use this command to manage or setup your fields, you will still need to add the field `searchable_type` as a `literal`. This is used to store the model type.\n\nThey can be found in the `config/cloud-search.php` file under the `fields` property:\n\n```php\n'fields' =\u003e [\n    'title' =\u003e 'text',\n    'status' =\u003e 'literal',\n],\n```\n\n## Artisan Commands\n\n#### `search:fields`\n\nInitialize an Eloquent model map.\n\n#### `search:index \u003cmodel\u003e`\n\nName or comma separated names of the model(s) to index.\n\nArguments:\n\n```\n model               Name or comma separated names of the model(s) to index\n```\n\n#### `search:flush \u003cmodel\u003e`\n\nFlush all of the model documents from the index.\n\nArguments:\n\n```\n model               Name or comma separated names of the model(s) to index\n```\n\n#### `search:queue`\n\nReduces the number of calls made to the CloudSearch server by queueing the updates and deletes.\n\n## Indexing\n\nOnce you have added the `LaravelCloudSearch\\Eloquent\\Searchable` trait to a model, all you need to do is save a model instance and it will automatically be added to your index when the `search:queue` command is ran.\n\n```php\n$post = new App\\Post;\n\n// ...\n\n$post-\u003esave();\n```\n\n\u003e **Note**: if the model document has already been indexed, then it will simply be updated. If it does not exist, it will be added.\n\n## Updating Documents\n\nTo update an index model, you only need to update the model instance's properties and `save`` the model to your database. The package will automatically persist the changes to your search index:\n\n```php\n$post = App\\Post::find(1);\n\n// Update the post...\n\n$post-\u003esave();\n```\n\n## Removing Documents\n\nTo remove a document from your index, simply `delete` the model from the database. This form of removal is even compatible with **soft deleted** models:\n\n```php\n$post = App\\Post::find(1);\n\n$post-\u003edelete();\n```\n\n## Searching\n\nYou may begin searching a model using the `search` method. The search method accepts a single string that will be used to search your models. You should then chain the `get` method onto the search query to retrieve the Eloquent models that match the given search query:\n\n```php\n$posts = App\\Post::search('Kitten fluff')-\u003eget();\n```\n\nSince package searches return a collection of Eloquent models, you may even return the results directly from a route or controller and they will automatically be converted to JSON:\n\n```php\nuse Illuminate\\Http\\Request;\n\nRoute::get('/search', function (Request $request) {\n    return App\\Post::search($request-\u003esearch)-\u003eget();\n});\n```\n\n## Pagination\n\nIn addition to retrieving a collection of models, you may paginate your search results using the `paginate` method. This method will return a `Paginator` instance just as if you had paginated a traditional Eloquent query:\n\n```php\n$posts = App\\Post::search('Kitten fluff')-\u003epaginate();\n```\nYou may specify how many models to retrieve per page by passing the amount as the first argument to the `paginate` method:\n\n```php\n$posts = App\\Post::search('Kitten fluff')-\u003epaginate(15);\n```\nOnce you have retrieved the results, you may display the results and render the page links using Blade just as if you had paginated a traditional Eloquent query:\n\n```blade\n\u003cdiv class=\"container\"\u003e\n    @foreach ($posts as $post)\n        {{ $post-\u003etitle }}\n    @endforeach\n\u003c/div\u003e\n\n{{ $posts-\u003elinks() }}\n```\n\n## Basic Builder Usage\n\nInitialize a builder instance:\n\n```php\n$query = app(\\LaravelCloudSearch\\CloudSearcher::class)-\u003enewQuery();\n```\n\nYou can chain query methods like so:\n\n```php\n$query-\u003ephrase('ford')\n    -\u003eterm('National Equipment', 'seller')\n    -\u003erange('year', '2010');\n```\n\nuse the `get()` or `paginate()` methods to submit query and retrieve results from AWS.\n\n```php\n$results = $query-\u003eget();\n```\n\nIn the example above we did not set the search type, so this means the results that are returned will match any document on CloudSearch domain. To refine you search to certain model, either use the model like shown in the example previously or use the `searchableType()` method to set the class name of the model (this is done automatically in the model instance call):\n\n```php\n$query = app(\\LaravelCloudSearch\\CloudSearcher::class)-\u003enewQuery();\n\n$results = $query-\u003esearchableType(\\App\\LawnMower::class)\n    -\u003eterm('honda', 'name')\n    -\u003eget();\n```\n\n### Search Query Operators and Nested Queries\n\nYou can use the `and`, `or`, and `not` operators to build compound and nested queries. The corresponding `and()`, `or()`, and `not()` methods expect a closure as their argument. You can chain all available methods as well nest more sub-queries inside of closures.\n\n```php\n$query-\u003eor(function($builder) {\n    $builder-\u003ephrase('ford')\n        -\u003ephrase('truck');\n});\n```\n\n## Queue\n\nThe help reduce the number of bulk requests made to the CloudSearch endpoint (because they cost) a queue system is used. This can be set in Laravel [Task Scheduling](https://laravel.com/docs/5.4/scheduling). You can decide how often it is ran using the scheduled task frequency options. Please note this uses the DB to function.\n\nExample of the task added to `/app/Console/Kernel.php`:\n\n```php\n    /**\n     * Define the application's command schedule.\n     *\n     * @param  \\Illuminate\\Console\\Scheduling\\Schedule $schedule\n     *\n     * @return void\n     */\n    protected function schedule(Schedule $schedule)\n    {\n        $schedule-\u003ecommand('search:queue')-\u003eeveryTenMinutes();\n    }\n```\n\n## Multilingual\n\n\u003e This feature is experimental\n\nLaravel CloudSearch can support multiple languages by appending the language code to the index type, so when the system performs a search it will only look for data that is on in the current system locale suffixed index type. For this to work the model needs to use the `LaravelCloudSearch\\Eloquent\\Localized` trait or something similar to it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftorann%2Flaravel-cloudsearch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftorann%2Flaravel-cloudsearch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftorann%2Flaravel-cloudsearch/lists"}