{"id":18418625,"url":"https://github.com/bsm/searchable-by","last_synced_at":"2025-04-07T13:31:22.594Z","repository":{"id":43260156,"uuid":"185623204","full_name":"bsm/searchable-by","owner":"bsm","description":"ActiveRecord plugin to quickly create search scopes","archived":false,"fork":false,"pushed_at":"2023-09-18T11:01:21.000Z","size":63,"stargazers_count":0,"open_issues_count":1,"forks_count":5,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-22T19:02:45.616Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bsm.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-05-08T14:33:04.000Z","updated_at":"2021-11-16T12:49:56.000Z","dependencies_parsed_at":"2023-02-10T17:01:16.105Z","dependency_job_id":null,"html_url":"https://github.com/bsm/searchable-by","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsm%2Fsearchable-by","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsm%2Fsearchable-by/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsm%2Fsearchable-by/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsm%2Fsearchable-by/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bsm","download_url":"https://codeload.github.com/bsm/searchable-by/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247661669,"owners_count":20975096,"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":[],"created_at":"2024-11-06T04:14:10.438Z","updated_at":"2025-04-07T13:31:22.327Z","avatar_url":"https://github.com/bsm.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Searchable By\n\n[![Test](https://github.com/bsm/searchable-by/actions/workflows/test.yml/badge.svg)](https://github.com/bsm/searchable-by/actions/workflows/test.yml)\n\nActiveRecord plugin to quickly create search scopes.\n\n## Installation\n\nAdd `gem 'searchable-by'` to your Gemfile.\n\n## Usage\n\n```ruby\nclass Post \u003c ActiveRecord::Base\n  belongs_to :author\n\n  # Limit the number of terms per query to 3.\n  # Ignore search terms shorter than 3 characters (useful for trigram indexes).\n  searchable_by max_terms: 3, min_length: 3 do\n    # Allow to search strings with custom match type.\n    column :title,\n      match: :prefix,       # Use btree index-friendly prefix match, e.g. `ILIKE 'term%'` instead of default `ILIKE '%term%'`.\n      match_phrase: :exact, # For phrases use exact match type, e.g. searching for `\"My Post\"` will query `WHERE LOWER(title) = 'my post'`.\n\n    # ... and integers.\n    column :id, type: :integer\n\n    # Allow custom arel nodes.\n    column { Author.arel_table[:name] }\n    column { Arel::Nodes::NamedFunction.new('CONCAT', [arel_table[:prefix], arel_table[:suffix]]) }\n\n    # Support custom scopes.\n    scope do\n      joins(:author)\n    end\n  end\n\n  # Multiple profiles can be defined. This one only searches title and metadata.\n  searchable_by :metadata do\n    column :title, match: :prefix\n\n    # Allow custom wildcard replacement using a match e.g. searching for `\"My*Post\"` will query `ILIKE 'My%Post'`.\n    column :metadata, match: :prefix, wildcard: '*'\n  end\nend\n\n# Search for 'alice'\nPost.search_by('alice') # =\u003e ActiveRecord::Relation\n\n# Search for 'alice' AND 'pie recipe'\nPost.search_by('alice \"pie recipe\"')\n\n# Search for 'alice' but NOT for 'pie recipe'\nPost.search_by('alice -\"pie recipe\"')\n\n# Search using metadata profile\nPost.search_by('meta', profile: :metadata)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsm%2Fsearchable-by","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbsm%2Fsearchable-by","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsm%2Fsearchable-by/lists"}