{"id":13484567,"url":"https://github.com/textacular/textacular","last_synced_at":"2025-11-11T18:30:29.563Z","repository":{"id":38554542,"uuid":"8466446","full_name":"textacular/textacular","owner":"textacular","description":"Textacular exposes full text search capabilities from PostgreSQL, and allows you to declare full text indexes. Textacular will extend ActiveRecord with named_scope methods making searching easy and fun! ","archived":false,"fork":false,"pushed_at":"2025-03-20T21:33:53.000Z","size":475,"stargazers_count":953,"open_issues_count":10,"forks_count":88,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-04-28T01:19:07.962Z","etag":null,"topics":["activerecord","postgresql","rails","ruby"],"latest_commit_sha":null,"homepage":"https://github.com/textacular","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/textacular.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-02-27T21:57:45.000Z","updated_at":"2025-04-18T17:33:22.000Z","dependencies_parsed_at":"2023-02-13T23:01:13.359Z","dependency_job_id":"e405e3b4-6e50-4e4a-9983-7f8aaef63a35","html_url":"https://github.com/textacular/textacular","commit_stats":{"total_commits":449,"total_committers":56,"mean_commits":8.017857142857142,"dds":0.6414253897550111,"last_synced_commit":"dce8515b766bd701ff3baae4492f4b2592e60691"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textacular%2Ftextacular","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textacular%2Ftextacular/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textacular%2Ftextacular/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textacular%2Ftextacular/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/textacular","download_url":"https://codeload.github.com/textacular/textacular/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254010811,"owners_count":21998993,"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","postgresql","rails","ruby"],"created_at":"2024-07-31T17:01:26.259Z","updated_at":"2025-11-11T18:30:29.518Z","avatar_url":"https://github.com/textacular.png","language":"Ruby","readme":"# textacular\n[![Gem Version](http://img.shields.io/gem/v/textacular.svg)][rubygems]\n[![Build Status](https://github.com/textacular/textacular/actions/workflows/main.yml/badge.svg)](https://github.com/textacular/textacular/actions/workflows/main.yml)\n\n[rubygems]: http://rubygems.org/gems/textacular\n\n## DESCRIPTION:\n\nTextacular exposes full text search capabilities from PostgreSQL,\nextending ActiveRecord with scopes making search easy and fun!\n\n\n## FEATURES/PROBLEMS:\n\n* Only works with PostgreSQL\n* Anything that mucks with the `SELECT` statement (notably `pluck`), is likely\n  to [cause problems](https://github.com/textacular/textacular/issues/28).\n\n\n## SYNOPSIS:\n\n### Quick Start\n\nIn the project's Gemfile add\n\n```ruby\ngem 'textacular', '~\u003e 5.0'\n```\n\n#### Rails 3, Rails 4\n\nIn the project's Gemfile add\n\n```ruby\ngem 'textacular', '~\u003e 4.0'\n```\n\n#### ActiveRecord outside of Rails\n\n```ruby\nrequire 'textacular'\n\nActiveRecord::Base.extend(Textacular)\n```\n\n\n### Usage\n\nYour models now have access to search methods:\n\nThe `#basic_search` method is what you might expect: it looks literally for what\nyou send to it, doing nothing fancy with the input:\n\n```ruby\nGame.basic_search('Sonic') # will search through the model's :string columns\nGame.basic_search(title: 'Mario', system: 'Nintendo')\n```\n\nThe `#advanced_search` method lets you use Postgres's search syntax like '|',\n'\u0026' and '!' ('or', 'and', and 'not') as well as some other craziness. The ideal\nuse for advanced_search is to take a search DSL you make up for your users and\ntranslate it to PG's syntax. If for some reason you want to put user input\ndirectly into an advanced search, you should be sure to catch exceptions from\nsyntax errors. Check [the Postgres docs]\n(http://www.postgresql.org/docs/9.2/static/datatype-textsearch.html) for more:\n\n```ruby\nGame.advanced_search(title: 'Street|Fantasy')\nGame.advanced_search(system: '!PS2')\n```\n\nThe `#web_search` method lets you use Postgres' 11+ `websearch_to_tsquery` function\n supporting websearch like syntax:\n\n- unquoted text: text not inside quote marks will be converted to terms separated by \u0026 operators, as if processed by plainto_tsquery.\n- \"quoted text\": text inside quote marks will be converted to terms separated by \u003c-\u003e operators, as if processed by phraseto_tsquery.\n- OR: logical or will be converted to the | operator.\n- -: the logical not operator, converted to the the ! operator.\n\n```ruby\nGame.web_search(title: '\"Street Fantasy\"')\nGame.web_search(title: 'Street OR Fantasy')\nGame.web_search(system: '-PS2')\n```\n\nFinally, the `#fuzzy_search` method lets you use Postgres's trigram search\nfunctionality.\n\nIn order to use this, you'll need to make sure your database has the `pg_trgm`\nmodule installed. Create and run a migration to install the module:\n\n```\nrake textacular:create_trigram_migration\nrake db:migrate\n```\n\nOnce that's installed, you can use it like this:\n\n```ruby\nComic.fuzzy_search(title: 'Questio') # matches Questionable Content\n```\n\nNote that fuzzy searches are subject to a similarity threshold imposed by the `pg_trgm` module. The default is 0.3, meaning that at least 30% of the total string must match your search content. For example:\n\n```ruby\nComic.fuzzy_search(title: 'Pearls') # matches Pearls Before Swine\nComic.fuzzy_search(title: 'Pear') # does not match Pearls Before Swine\n```\n\nThe similarity threshold is hardcoded in PostgreSQL and can be modified on a per-connection basis, for example:\n\n```ruby\nActiveRecord::Base.connection.execute(\"SELECT set_limit(0.9);\")\n```\n\nFor more info, view the `pg_trgm` documentation, specifically [F.35.2. Functions and Operators](http://www.postgresql.org/docs/9.1/static/pgtrgm.html).\n\nSearches are also chainable:\n\n```ruby\nGame.fuzzy_search(title: 'tree').basic_search(system: 'SNES')\n```\n\nIf you want to search on two or more fields with the OR operator use a hash for\nthe conditions and pass false as the second parameter:\n\n```ruby\nGame.basic_search({name: 'Mario', nickname: 'Mario'}, false)\n```\n\n\n### Setting Language\n\nTo set proper searching dictionary just override class method on your model:\n\n```ruby\ndef self.searchable_language\n  'russian'\nend\n```\n\nAnd all your queries would go right! And don`t forget to change the migration for indexes, like shown below.\n\n### Setting Searchable Columns\n\nTo change the default behavior of searching all text and string columns,\noverride the searchable_columns class method on your model:\n\n```ruby\ndef self.searchable_columns\n  [:column1, :column2]\nend\n```\n\n### Creating Indexes for Super Speed\nYou can have Postgresql use an index for the full-text search.  To declare a full-text index, in a\nmigration add code like the following:\n\n#### For basic_search\n```ruby\nadd_index :email_logs, %{to_tsvector('english', subject)}, using: :gin\nadd_index :email_logs, %{to_tsvector('english', email_address)}, using: :gin\n```\n\n#### For fuzzy_search\n```ruby\nadd_index :email_logs, :subject, using: :gist, opclass: :gist_trgm_ops\nadd_index :email_logs, :email_address, using: :gist, opclass: :gist_trgm_ops\n```\n\nIn the above example, the table email_logs has two text columns that we search against, subject and email_address.\nYou will need to add an index for every text/string column you query against, or else Postgresql will revert to a\nfull table scan instead of using the indexes.\n\n## REQUIREMENTS:\n\n* ActiveRecord\n* Ruby 1.9.2\n\n\n## INSTALL:\n\n```\n$ gem install textacular\n```\n\n## Contributing\n\nIf you'd like to contribute, please see the [contribution guidelines](CONTRIBUTING.md).\n\n\n## Releasing\n\nMaintainers: Please make sure to follow the [release steps](RELEASING.md) when\nit's time to cut a new release.\n\n\n## LICENSE:\n\n(The MIT License)\n\nCopyright (c) 2011 Aaron Patterson\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":["Ruby","Search","Gems"],"sub_categories":["Full-text Search"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftextacular%2Ftextacular","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftextacular%2Ftextacular","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftextacular%2Ftextacular/lists"}