{"id":28457048,"url":"https://github.com/mitchellhenke/sequel-pg-trgm","last_synced_at":"2025-06-30T00:31:39.243Z","repository":{"id":16021907,"uuid":"18765539","full_name":"mitchellhenke/sequel-pg-trgm","owner":"mitchellhenke","description":"Sequel plugin for Postgres' pg_trgm","archived":false,"fork":false,"pushed_at":"2022-03-31T20:17:20.000Z","size":11,"stargazers_count":3,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-06T23:09:54.998Z","etag":null,"topics":["pg-trgm","postgres","ruby","sequel","sequel-plugin"],"latest_commit_sha":null,"homepage":null,"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/mitchellhenke.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":"2014-04-14T15:20:05.000Z","updated_at":"2023-01-12T23:28:21.000Z","dependencies_parsed_at":"2022-08-30T15:40:29.881Z","dependency_job_id":null,"html_url":"https://github.com/mitchellhenke/sequel-pg-trgm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mitchellhenke/sequel-pg-trgm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitchellhenke%2Fsequel-pg-trgm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitchellhenke%2Fsequel-pg-trgm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitchellhenke%2Fsequel-pg-trgm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitchellhenke%2Fsequel-pg-trgm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mitchellhenke","download_url":"https://codeload.github.com/mitchellhenke/sequel-pg-trgm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitchellhenke%2Fsequel-pg-trgm/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262689473,"owners_count":23349133,"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":["pg-trgm","postgres","ruby","sequel","sequel-plugin"],"created_at":"2025-06-06T23:09:59.066Z","updated_at":"2025-06-30T00:31:39.233Z","avatar_url":"https://github.com/mitchellhenke.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"sequel-pg-trgm\n==============\n\nSequel plugin for Postgres' [pg_trgm](http://www.postgresql.org/docs/9.1/static/pgtrgm.html).\n\n## Installation\n\n```ruby\ngem install sequel-pg-trgm\n```\n\nInstall the pg_trgm extension in Postgres:\n```bash\npsql\n\u003e CREATE EXTENSION pg_trgm;\n```\n\n\n## Usage\nsequel-pg-trgm creates a dataset method and a helper for creating an index in migrations.\n\nTo create the index column for searching, create a new migration like the following:\n\n```ruby\nSequel.migration do\n  up do\n    extension :pg_trgm\n    add_pg_trgm(:foods, :name)\n  end\n\n  down do\n    extension :pg_trgm\n    drop_pg_trgm(:foods, :name)\n  end\nend\n```\n\n```ruby\nclass Food \u003c Sequel::Model\n  plugin :pg_trgm\nend\n```\n\n### Querying\nIf you have an application that lets a user search for foods, the query to search the name column on the `Food` model would be:\n\n```ruby\nFood.dataset.text_search(:name, 'Banana Pancakes')\n```\n\n## Notes:\nWill only work for Postgres databases.  Right now, all results are ordered by their similarity to the query.\n\n### pg_trgm search threshold\nPostgres' pg_trgm has a default threshold of 0.3, and will not return results if any results do not match at least that percentage.\n\n#### Example:\n\nIf you are trying to get the Food with name 'Banana Pancakes', you may expect to get that back when searching 'ba' or 'ban', but you will not.\n\n```ruby\nFood.dataset.text_search(:name, 'ba').first\n# =\u003e nil\nFood.dataset.text_search(:name, 'ban').first\n# =\u003e nil\nFood.dataset.text_search(:name, 'bana').first\n# =\u003e \u003cFood @values={:id=\u003e12, :name=\u003e\"Banana Pancakes\"}\u003e\n```\n\nHowever, if you set the limit to be lower, say 0.1, you will get results for less accurate searches.  It seems to get set per connection, so just calling ``select set_limit(0.1);`` once after connecting won't guarantee the value is always going to be set. Calling it in Sequel's after_connect hook usually solves this.\n\n```ruby\nafter_connect = proc do |connection|\n  begin\n    connection.query(\"select set_limit(0.1);\")\n  rescue PG::UndefinedFunction\n  end\nend\nSequel.connect(\"postgres://localhost/foods\", :loggers =\u003e [logger], after_connect: after_connect)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitchellhenke%2Fsequel-pg-trgm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmitchellhenke%2Fsequel-pg-trgm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitchellhenke%2Fsequel-pg-trgm/lists"}