{"id":20234929,"url":"https://github.com/majidimanzade/searchkon","last_synced_at":"2025-04-10T18:51:57.422Z","repository":{"id":56894627,"uuid":"266483936","full_name":"majidimanzade/searchkon","owner":"majidimanzade","description":"Advanced active_record Search/Filter Command","archived":false,"fork":false,"pushed_at":"2020-06-12T10:07:40.000Z","size":25,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T16:38:48.560Z","etag":null,"topics":["activerecord","ruby","ruby-on-rails","search"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/majidimanzade.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":"2020-05-24T06:31:39.000Z","updated_at":"2020-07-17T19:24:06.000Z","dependencies_parsed_at":"2022-08-21T01:20:31.451Z","dependency_job_id":null,"html_url":"https://github.com/majidimanzade/searchkon","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/majidimanzade%2Fsearchkon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majidimanzade%2Fsearchkon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majidimanzade%2Fsearchkon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majidimanzade%2Fsearchkon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/majidimanzade","download_url":"https://codeload.github.com/majidimanzade/searchkon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248274388,"owners_count":21076375,"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":["activerecord","ruby","ruby-on-rails","search"],"created_at":"2024-11-14T08:13:49.432Z","updated_at":"2025-04-10T18:51:57.403Z","avatar_url":"https://github.com/majidimanzade.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Searchkon\n\nSearchkon is Advanced active record search(filter) command that makes easy to search throw models and  their relationships.\n\n## Introduction\n\nLets say we want to return a list of products filtered by multiple parameters. our request contain below parameters:\n\n```\n{\n  title: 'foobar',\n  id: [1, 2, 3, 4],\n  created_at: '(2012-12-21..2019-12-21)'\n  categories.name: 'mobile'\n}\n\n```\n\nFilter above parameters with Searchkon gem:\n\n```rb\nSearchkon::QueryBuilder.filter('Product', filters)\n```\n\n## Getting Start\n\n\nAdd Searchkon to your Gemfile:\n```sh\ngem 'searchkon'\n```\n\n### Searchable columns\n\nat the first we should determine witch columns of model can be filter in Searchkon\n\n```rb\nclass Product \u003c ActiveRecord::Base\n\n  has_many :coupons\n  has_many :payments\n\n  def self.searchable_columns\n    {\n      like: ['title', 'coupons.code'],\n      exact: [\n        'created_at',\n        'coupons.title', ## relational filter on coupons table\n        'payments.id', ## relational filter on payments table\n        'id'\n      ]\n    }\n  end\nend\n\n```\n\n\n\u003cb\u003e like: \u003c/b\u003e if you add specific column in your like scope, your query will be like below sql.\n```sql\nselect * from products where title like %foo%\n```\n\n\u003cb\u003eexact:\u003c/b\u003e Searchkon create query using equal operation.\n\n```sql\nselect * from products where created_at = foo\n```\n\n### Simple where query\n\n\n```rb\nparams =  {\n  id: 1,\n  title: 'foobar'\n}\n```\n\n```rb\nSearchkon::QueryBuilder.filter('Product', params)\n```\n\nsql result:\n```sql\nSELECT \"products\".* FROM \"products\" WHERE (products.title like '%foobar%') AND \"products\".\"id\" = 1\n```\n\n### Search Range\n\n```rb\nparams = {\n  id: '(1..10)',\n  created_at: '(2012-12-21..2019-12-21)'\n}\n```\n\nsql result:\n\n```sql\nSELECT \"products\".* FROM \"products\" WHERE (products.title like '%foobar%') AND \"products\".\"id\" = 1\n```\n\n\n### Search in relational table\n\n\n```rb\nparams = {\n 'coupons.id': [1,4,8] \n}\n```\n\nsql result:\n\n```sql\nSELECT \"products\".* FROM \"products\" INNER JOIN \"coupons\" ON \"coupons\".\"product_id\" = \"products\".\"id\" WHERE \"coupons\".\"id\" IN (1, 4, 8)\n```\n\n\n### Invalid Column in query\n\nif your filter parameters contain invalid column name, Searchkon skip it and create query without that column.\n\n```rb\ninvalid_mock_params = {\n  id: 1,\n  foo: 'foobar'\n}\n```\n\n```rb\nSearchkon::QueryBuilder.filter('Product', invalid_mock_params)\n```\n\nsql result:\n\n\n```sql\nSELECT \"products\".* FROM \"products\" WHERE \"products\".\"id\" = 1\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmajidimanzade%2Fsearchkon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmajidimanzade%2Fsearchkon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmajidimanzade%2Fsearchkon/lists"}