{"id":25254229,"url":"https://github.com/alchemycms/alchemy-pg_search","last_synced_at":"2025-10-27T01:31:01.860Z","repository":{"id":24687846,"uuid":"28098941","full_name":"AlchemyCMS/alchemy-pg_search","owner":"AlchemyCMS","description":"PostgreSQL full text search for AlchemyCMS","archived":false,"fork":false,"pushed_at":"2024-12-12T17:02:34.000Z","size":290,"stargazers_count":5,"open_issues_count":0,"forks_count":10,"subscribers_count":10,"default_branch":"main","last_synced_at":"2024-12-12T18:19:01.781Z","etag":null,"topics":["alchemy-cms","fulltext-search","postgresql","rails"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlchemyCMS.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2014-12-16T17:52:09.000Z","updated_at":"2024-12-12T17:02:43.000Z","dependencies_parsed_at":"2023-12-19T16:35:10.570Z","dependency_job_id":"2d0a2b48-d0c9-446a-bc92-ff2cbce66dc2","html_url":"https://github.com/AlchemyCMS/alchemy-pg_search","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlchemyCMS%2Falchemy-pg_search","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlchemyCMS%2Falchemy-pg_search/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlchemyCMS%2Falchemy-pg_search/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlchemyCMS%2Falchemy-pg_search/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlchemyCMS","download_url":"https://codeload.github.com/AlchemyCMS/alchemy-pg_search/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238418214,"owners_count":19468865,"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":["alchemy-cms","fulltext-search","postgresql","rails"],"created_at":"2025-02-12T05:31:22.929Z","updated_at":"2025-10-27T01:31:01.851Z","avatar_url":"https://github.com/AlchemyCMS.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CI](https://github.com/AlchemyCMS/alchemy-pg_search/actions/workflows/ci.yml/badge.svg)](https://github.com/AlchemyCMS/alchemy-pg_search/actions/workflows/ci.yml)\n\n# Alchemy CMS Postgresql Fulltext Search\n\nThis gem provides full text search for projects using postgresql databases to Alchemy CMS 7.0 and above.\n\n## Requirements\n\n* Ruby 3.0 or newer\n* Alchemy CMS 7.0 or newer\n* PostgreSQL 12.x or newer\n\n## Installation\n\nAdd this line to your application's `Gemfile`:\n\n```ruby\ngem 'alchemy-pg_search', github: 'AlchemyCMS/alchemy-pg_search', branch: 'main'\n```\n\nAnd then execute:\n\n```shell\n$ bundle install\n```\n\nRun install script:\n\n```shell\n$ bin/rails g alchemy:pg_search:install\n```\n\n\u003e [!NOTE]  \n\u003e The installation will generate an autogenerated column which can be configured with a language. The default\n\u003e value should work for the most languages. If you wish to change this behavior you should add\n\u003e the `Alchemy::PgSearch.config`\n\u003e into the project initializer before running the install script. (See [Configure Behavior](#configure-behavior))\n\n## Usage\n\nEvery `Ingredient` will be indexed unless you tell Alchemy to not index a specific content.\n\n### Disable Indexing\n\n#### Exclude whole pages from the search index\n\nPass `searchable: false` to your page layout definitions and Alchemy will not index that particular page.\n\n```yaml\n# page_layouts.yml\n- name: secret_page\n  searchable: false\n  elements:\n    - secret_sauce\n```\n\n#### Exclude whole elements from the search index\n\nPass `searchable: false` to your element definitions and Alchemy will not index that particular element.\n\n```yaml\n# elements.yml\n- name: secret_sauce\n  searchable: false\n  ingredients:\n    - role: sauce\n      type: Text\n      default: 'This is my secret sauce.'\n```\n\n#### Exclude single contents from being indexed\n\nPass `searchable: false` to your content definitions and Alchemy will not index that particular content.\n\n```yaml\n# elements.yml\n- name: secrets\n  ingredients:\n    - role: passwords\n      type: Text\n      searchable: false\n      default: 'This is my secret password.'\n```\n\nThe same works for `ingredients` as well\n\n```yaml\n# elements.yml\n- name: secrets\n  ingredients:\n    - role: passwords\n      type: Text\n      searchable: false\n      default: 'This is my secret password.'\n```\n\n### Configure Behavior\n\nConfigure the gem in an initializer. The default configurations are:\n\n```ruby\nRails.application.config.before_initialize do\n  Alchemy::PgSearch.config = {\n    dictionary: 'simple',\n    paginate_per: 10\n  }\nend\n```\n\n\u003e [!NOTE]  \n\u003e Be aware that `before_initialize` is used. Otherwise the configuration will not have an effect, because of the load\n\u003e order in Rails.\n\n Configuration Name | Default Value | Description                                                                                                                                                                                                                                                                                                 \n--------------------|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n dictionary         | simple        | Dictionary for the multisearch tsearch - config, which is used to find the content. The dictionary can impact the amout found documents, because it removes language specific stop words. See more in the [PostgreSQL documentation](https://www.postgresql.org/docs/current/textsearch-dictionaries.html). \n paginate_per       | 10            | Amount of results per page. The value can be set to `nil` to disable the pagination.                                                                                                                                                                                                                        \n\nYou can also overwrite the default multisearch configuration to use other search strategies. For more information take\na look into the [PgSearch Readme](https://github.com/Casecommons/pg_search#configuring-multi-search).\n\n```ruby\nRails.application.config.after_initialize do\n  ::PgSearch.multisearch_options = {\n    using: {\n      tsearch: { prefix: true }\n    }\n  }\nend\n```\n\n### Rendering search results.\n\nIn order to render the search results, you'll need a page layout that represents the search result page. Simply mark a\npage layout as `searchresults: true`. The search form will pick this page as result page.\n\n#### Search Results Page\n                          \nAdd a search layout to the `page_layout.yml` and mark it with a `searchresults` flag. These flag is used to find the \ncorrect page path for search form.\n\n```yaml\n# page_layouts.yml\n- name: search\n  searchresults: true\n  unique: true\n  elements:\n    - searchresults\n  autogenerate:\n    - searchresults\n\n# elements.yml\n- name: searchresults\n  unique: true\n```\n\nand then use the view helpers to render the search form on the page layout partial.\n\n```erb\n\u003c!-- app/views/alchemy/page_layouts/_search.html.erb --\u003e\n\u003c%= render_elements %\u003e\n\n\u003c!-- app/views/alchemy/elements/_searchresults.html.erb --\u003e\n\u003c%= element_view_for(searchresults) do |el| -%\u003e\n  \u003c% search_results = Alchemy::Search::SearchPage.perform_search(params, ability: current_ability) %\u003e\n  \u003c%= render \"alchemy/search/results\", search_results: search_results %\u003e\n\u003c% end %\u003e\n```\n\n### View Helpers\n\nThis gem provides some helper methods that let you render the form and the search results.\n\n* Render the search form:\n  `render_search_form`\n\n### Customize Views\n\nIf you want to override the search form and search result views please use this generator.\n\n```shell\n$ bin/rails g alchemy:pg_search:views\n```\n\n### Translating Views\n\nThe views are fully translatable. German and english translations are already provided with this gem.\n\nIf you want add your own translation, just place a locale file into your projects `config/locales` folder.\n\nHere is the english example:\n\n```yaml\nen:\n  alchemy:\n\n    search_form:\n      placeholder: 'Search query'\n      submit: 'Search'\n\n    search_result_page:\n      result_page: Page\n      no_results: \"Your search for '%{query}' offers no result\"\n      result_heading: \"Your search for '%{query}'\"\n      result_count:\n        one: 'Offers one result'\n        other: 'Offers %{count} results'\n```\n\n## Upgrading\n\n## 6.0\n\nUpgrading to 6.0 makes it necessary to update you search result partials.\n\nMake sure to use `Alchemy::Search::SearchPage.perform_search(params, ability: current_ability)` and pass the `search_results` into `alchemy/search/results` (or whatever partial you are rendering the results) and make sure to use the local `search_results` variable over the `@search_results` instance variable.\n\n```diff\n-\u003c%= render \"alchemy/search/results\" %\u003e\n+\u003c%= render \"alchemy/search/results\", search_results: Alchemy::Search::SearchPage.perform_search(params, ability: current_ability) %\u003e\n```\n\n## 4.0\n\nIf you are upgrading from v3.0.0 please run the install generator:\n\n```shell\n$ bin/rails g alchemy:pg_search:install\n$ bin/rake db:migrate\n```\n\nand reindex your database in your Rails console\n\n```rb\n# rails console\n$ Alchemy::PgSearch.rebuild\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falchemycms%2Falchemy-pg_search","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falchemycms%2Falchemy-pg_search","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falchemycms%2Falchemy-pg_search/lists"}