{"id":15501627,"url":"https://github.com/taq/torm-elastic","last_synced_at":"2026-04-28T20:31:50.684Z","repository":{"id":34848629,"uuid":"38842099","full_name":"taq/torm-elastic","owner":"taq","description":"ElasticSearch integration for TORM","archived":false,"fork":false,"pushed_at":"2015-07-11T14:46:10.000Z","size":172,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-24T13:27:53.311Z","etag":null,"topics":["elasticsearch","orm","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/taq.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":"2015-07-09T19:55:11.000Z","updated_at":"2015-09-02T12:34:39.000Z","dependencies_parsed_at":"2022-09-03T09:11:12.320Z","dependency_job_id":null,"html_url":"https://github.com/taq/torm-elastic","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taq%2Ftorm-elastic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taq%2Ftorm-elastic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taq%2Ftorm-elastic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taq%2Ftorm-elastic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/taq","download_url":"https://codeload.github.com/taq/torm-elastic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246076930,"owners_count":20719894,"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":["elasticsearch","orm","php"],"created_at":"2024-10-02T09:05:05.333Z","updated_at":"2026-04-28T20:31:45.664Z","avatar_url":"https://github.com/taq.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TORM-elasticsearch\n\nThis is a trait to insert ElasticSearch funcionality on\n[TORM](https://github.com/taq/torm) objects. \n\n## Installation\n\nChange (or create, if needed) your Composer file to include it:\n\n```\n{\n    \"require\": {\n        \"taq/torm-elastic\": \"\u003e=0\"\n    }\n}\n```\n\n## Usage\n\nJust open your model and insert the trait, like:\n\n```\nclass User extends TORM\\Model {\n    use TORM\\ElasticSearch;\n}\nUser::setElasticSearchIndex(\"myapp\");\n```\n\nand, after every object saving, it will be send for ElasticSearch indexing,\nusing some rules:\n\n- Need to insert the trait using `use TORM\\ElasticSearch` on the model;\n- Need to specify the app name using setElasticSearchIndex(\u003cname\u003e). This will be\n  the ElasticSearch index.\n- After inserting the trait, a new `afterInitialize` method will be added on the\n  model. If the model already has a `afterInitialize` method, **the\n  `TORM\\ElasticSearch` `afterInitialize` method must be called explicity on its\n  end**. This is because of the way PHP traits works.\n- If not specified, **all the model attributes** will be indexed. To define just\n  some key attributes, we can use the `setElasticSearchValues(\u003cattributes\u003e)`\n  method, sending an array with the attributes, like:\n  ```\n  User::setElasticSearchValues([\"name\"]);\n  ```\n  then only the `name` attribute will be indexed.\n\n## Searching\n\nThen we can search using something like:\n\n```\n$rtn = ElasticUser::elasticSearch(\"name\", \"john\");\nvar_dump($rtn);\n```\n\nresulting in something like\n\n```\narray(2) {\n  'id' =\u003e\n  string(1) \"1\"\n  'name' =\u003e\n  string(12) \"John Doe Jr.\"\n}\n```\n\n## Importing \n\nWhen importing a new data collection, we can use the `import` method, like:\n\n```\nUser::elasticImport();\n```\n\n## Getting document count\n\n```\nUser:;elasticCount();\n```\n\n## Updating a document\n\nWe can explicity update a document using:\n\n```\n$obj-\u003eupdateElasticSearch();\n```\n\n## Deleting a document\n\nWe can explicity delete a document using:\n\n```\n$obj-\u003edeleteElasticSearch();\n```\n\n## Disabling\n\nWe can disable updating documents using\n\n```\nTORM\\ElasticSearchConfigs::disabled(true);\n```\n\nand enable again sending `false` on the same method.\n\n## Testing\n\nIf using a `TORM` test enviroment (defined setting the enviroment var `TORM_ENV`\nto `test`), the index name will be automatically changed to `\u003cindex_name\u003e_test`.\n\nIf we want to avoid updating a document on the test enviroment, we can use \n\n```\nTORM\\ElasticSearchConfigs::avoidOnTests(true);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaq%2Ftorm-elastic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftaq%2Ftorm-elastic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaq%2Ftorm-elastic/lists"}