{"id":13879994,"url":"https://github.com/thredded/db_text_search","last_synced_at":"2025-05-06T18:05:54.074Z","repository":{"id":6197938,"uuid":"54716678","full_name":"thredded/db_text_search","owner":"thredded","description":"A unified interface on top of ActiveRecord for case-insensitive string-in-set and prefix querying, and full-text search on SQLite, MySQL, and PostgreSQL.","archived":false,"fork":false,"pushed_at":"2022-06-05T14:37:25.000Z","size":108,"stargazers_count":65,"open_issues_count":1,"forks_count":7,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-06T18:05:46.675Z","etag":null,"topics":[],"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/thredded.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-25T12:14:01.000Z","updated_at":"2025-04-29T09:08:30.000Z","dependencies_parsed_at":"2022-08-06T19:15:21.272Z","dependency_job_id":null,"html_url":"https://github.com/thredded/db_text_search","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thredded%2Fdb_text_search","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thredded%2Fdb_text_search/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thredded%2Fdb_text_search/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thredded%2Fdb_text_search/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thredded","download_url":"https://codeload.github.com/thredded/db_text_search/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252741372,"owners_count":21797027,"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-08-06T08:02:42.694Z","updated_at":"2025-05-06T18:05:54.048Z","avatar_url":"https://github.com/thredded.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# DbTextSearch [![Build Status](https://travis-ci.org/thredded/db_text_search.svg?branch=main)](https://travis-ci.org/thredded/db_text_search) [![Code Climate](https://codeclimate.com/github/thredded/db_text_search/badges/gpa.svg)](https://codeclimate.com/github/thredded/db_text_search) [![Test Coverage](https://codeclimate.com/github/thredded/db_text_search/badges/coverage.svg)](https://codeclimate.com/github/thredded/db_text_search/coverage)\n\nDifferent relational databases treat text search very differently.\nDbTextSearch provides a unified interface on top of ActiveRecord for SQLite, MySQL, and PostgreSQL to do:\n\n* Case-insensitive string-in-set querying, prefix querying, and case-insensitive index creation.\n* Basic full-text search for a list of terms, and FTS index creation.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'db_text_search', '~\u003e 1.0'\n```\n\n## Usage\n\n### Case-insensitive string matching\n\nAdd an index in a migration to an existing CI (case-insensitive) or CS (case-sensitive) column:\n\n```ruby\nDbTextSearch::CaseInsensitive.add_index connection, :users, :username\n# Options: name, unique\n```\n\nOr, create a new CI column:\n\n```ruby\nDbTextSearch::CaseInsensitive.add_ci_text_column connection, :users, :username\n```\n\nPerform a search for records with column that case-insensitively equals to one of the strings in a given set:\n\n```ruby\n# Find all confirmed users that have either the username Alice or Bob (case-insensitively):\nDbTextSearch::CaseInsensitive.new(User.confirmed, :username).in(%w(Alice Bob))\n #=\u003e ActiveRecord::Relation\n```\n\nPerform a case-insensitive prefix search:\n \n```ruby\nDbTextSearch::CaseInsensitive.new(User.confirmed, :username).prefix('Jo')\n```\n\nSee also: [API documentation][api-docs].\n\n### Full text search\n\nAdd an index:\n\n```ruby\nDbTextSearch::FullText.add_index connection, :posts, :content\n# Options: name\n```\n\nPerform a full-text search:\n\n```ruby\nDbTextSearch::FullText.new(Post.published, :content).search('peace')\nDbTextSearch::FullText.new(Post.published, :content).search(%w(love kaori))\n```\n\n## Under the hood\n\n### Case-insensitive string matching\n\n\u003ctable\u003e\n\u003ccaption\u003eCase-insensitive equality methods\u003c/caption\u003e\n\u003cthead\u003e\n  \u003ctr\u003e\u003cth rowspan=\"2\"\u003eColumn type\u003c/th\u003e\u003cth colspan=\"2\"\u003eSQLite\u003c/th\u003e\u003cth colspan=\"2\"\u003eMySQL\u003c/th\u003e\u003cth colspan=\"2\"\u003ePostgreSQL\u003c/th\u003e\u003c/tr\u003e\n  \u003ctr\u003e\u003cth\u003eDetected types\u003c/th\u003e\u003cth\u003eSearch / index\u003c/th\u003e\u003cth\u003eDetected types\u003c/th\u003e\u003cth\u003eSearch / index\u003c/th\u003e\u003cth\u003eDetected types\u003c/th\u003e\u003cth\u003eSearch / index\u003c/th\u003e\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody style=\"text-align: center\"\u003e\n  \u003ctr\u003e\u003cth\u003eCI\u003c/th\u003e\n      \u003ctd rowspan=\"2\"\u003ealways treated as CS\u003c/td\u003e \u003ctd rowspan=\"2\"\u003e\u003ccode\u003eCOLLATE\u0026nbsp;NOCASE\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003ci\u003edefault\u003c/i\u003e\u003c/td\u003e \u003ctd\u003e\u003ci\u003edefault\u003c/i\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003ccode\u003eCITEXT\u003c/code\u003e\u003c/td\u003e \u003ctd\u003e\u003ci\u003edefault\u003c/i\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\u003cth\u003eCS\u003c/th\u003e\n    \u003ctd\u003enon-\u003ccode\u003eci\u003c/code\u003e collations\u003c/td\u003e \u003ctd\u003e\u003ccode\u003eLOWER\u003c/code\u003e\u003cbr\u003e\u003cb\u003eno index\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ci\u003edefault\u003c/i\u003e\u003c/td\u003e \u003ctd\u003e\u003ccode\u003eLOWER\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003ctable\u003e\n\u003ccaption\u003eCase-insensitive prefix matching (using \u003ccode\u003eLIKE\u003c/code\u003e)\u003c/caption\u003e\n\u003cthead\u003e\n  \u003ctr\u003e\u003cth\u003eColumn type\u003c/th\u003e\u003cth\u003eSQLite\u003c/th\u003e\u003cth\u003eMySQL\u003c/th\u003e\u003cth\u003ePostgreSQL\u003c/th\u003e\u003c/tr\u003e  \n\u003c/thead\u003e\n\u003ctbody style=\"text-align: center\"\u003e\n  \u003ctr\u003e\u003cth\u003eCI\u003c/th\u003e\n      \u003ctd rowspan=\"2\"\u003e\n        \u003ci\u003edefault\u003c/i\u003e, \u003ca href=\"https://www.sqlite.org/optoverview.html#prefix_opt\"\u003e\u003cb\u003ecannot always use an index\u003c/b\u003e\u003c/a\u003e,\u003cbr\u003e\n        even for prefix queries\n      \u003c/td\u003e\n      \u003ctd\u003e\u003ci\u003edefault\u003c/i\u003e\u003c/td\u003e\n      \u003ctd\u003e\u003cb\u003ecannot use an index\u003c/b\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\u003cth\u003eCS\u003c/th\u003e\n    \u003ctd\u003e\u003cb\u003ecannot use an index\u003c/b\u003e\u003c/td\u003e    \n    \u003ctd\u003e\u003ccode\u003eLOWER(column text_pattern_ops)\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\n\n### Full-text search\n\n#### MySQL\n\nA `FULLTEXT` index, and a `MATCH AGAINST` query. MySQL v5.6.4+ is required.\n\n#### PostgreSQL\n\nA `gist(to_tsvector(...))` index, and a `@@ plainto_tsquery` query.\nMethods also accept an optional `pg_ts_config` argument (default: `\"'english'\"`) that is ignored for other databases.\n\n#### SQLite\n\n**No index**, a `LIKE %term%` query for each term joined with `AND`.\n\n## Development\n\nMake sure you have a working installation of SQLite, MySQL, and PostgreSQL.\nAfter checking out the repo, run `bin/setup` to install dependencies.\nThen, run `rake test_all` to run the tests with all databases and gemfiles.\n\nSee the Rakefile for other available test tasks.\n\nYou can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/thredded/db_text_search. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n[api-docs]: http://www.rubydoc.info/gems/db_text_search\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthredded%2Fdb_text_search","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthredded%2Fdb_text_search","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthredded%2Fdb_text_search/lists"}