alchemy-pg_search 5.0.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1896b14c7a0f65b1b14ca0f2de751ee14c68219bbd24893f6561725ab69fd622
4
- data.tar.gz: 8e5759cd3d6f12f57c544ba5a2290d98f5600808f61b9e03e9ae3530a9e6aaaf
3
+ metadata.gz: bd79aeea752492e2162f8338e15726c51af184f2ee0025cffd6f7eb98914eb8c
4
+ data.tar.gz: 5b8bd8894f18350baffdb0537bcbdebc9e781f8aa86251919972b6a076c3171f
5
5
  SHA512:
6
- metadata.gz: 6fb5a90e1e4a562dd4c71cabbb91dc173be473e2eb2100fe83b0d317f6c6120bf2af66589a369fd0a39355f3996811e80e2399320c7e19c44eb6f1ac8e5c0830
7
- data.tar.gz: cc3d81d2e4e798b57e47109890b8e97f40a12c16e33446887789ee3f5aa377d68ab4c58430834adfc2e75f2b12f4a57afa6348d2372af9464a91658dc5d84570
6
+ metadata.gz: c0333bfcb6a05dc82aa69c7147429bbe337315d90c61bcbbf3ae6d4ef3d11b28137e934dde2d38f98ce02288dcfb4d08cadc099b6d2d998da0c69abe044d3089
7
+ data.tar.gz: f1b6ac52bdfc1cb2199344eca5f691c03063b1d9d1a56d28236512621650640390adf093842c8111998992a26bfed2b2927360f2bddcbc286e9bc0910226ec5e
@@ -9,7 +9,7 @@ jobs:
9
9
  RAILS_ENV: test
10
10
  services:
11
11
  postgres:
12
- image: postgres:11
12
+ image: postgres:12
13
13
  env:
14
14
  POSTGRES_USER: postgres
15
15
  POSTGRES_PASSWORD: password
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## [v5.2.0](https://github.com/AlchemyCMS/alchemy-pg_search/tree/v5.2.0) (2024-02-05)
4
+
5
+ [Full Changelog](https://github.com/AlchemyCMS/alchemy-pg_search/compare/v5.1.0...v5.2.0)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Allow different search strings in preview [\#46](https://github.com/AlchemyCMS/alchemy-pg_search/pull/46) ([sascha-karnatz](https://github.com/sascha-karnatz))
10
+ - Add support for Rails 7.1 [\#45](https://github.com/AlchemyCMS/alchemy-pg_search/pull/45) ([sascha-karnatz](https://github.com/sascha-karnatz))
11
+ - Update configuration section in README [\#44](https://github.com/AlchemyCMS/alchemy-pg_search/pull/44) ([sascha-karnatz](https://github.com/sascha-karnatz))
12
+ - Avoid duplicating Alchemy.publish\_targets in development environment [\#40](https://github.com/AlchemyCMS/alchemy-pg_search/pull/40) ([dbwinger](https://github.com/dbwinger))
13
+
14
+ ## [v5.1.0](https://github.com/AlchemyCMS/alchemy-pg_search/tree/v5.1.0) (2023-12-20)
15
+
16
+ [Full Changelog](https://github.com/AlchemyCMS/alchemy-pg_search/compare/v5.0.0...v5.1.0)
17
+
18
+ **Merged pull requests:**
19
+
20
+ - Improve search speed [\#42](https://github.com/AlchemyCMS/alchemy-pg_search/pull/42) ([sascha-karnatz](https://github.com/sascha-karnatz))
21
+ - Make migrations more error tolerant [\#41](https://github.com/AlchemyCMS/alchemy-pg_search/pull/41) ([sascha-karnatz](https://github.com/sascha-karnatz))
22
+
3
23
  ## [v5.0.0](https://github.com/AlchemyCMS/alchemy-pg_search/tree/v5.0.0) (2023-09-01)
4
24
 
5
25
  [Full Changelog](https://github.com/AlchemyCMS/alchemy-pg_search/compare/v4.2.0...v5.0.0)
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem "rails", "~> 7.0.0"
5
+ gem "rails", "~> 7.1.0"
6
6
  gem "alchemy_cms", "~> 7.0.0"
7
7
 
8
8
  gem "sassc-rails"
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014, magic labs GmbH
1
+ Copyright (c) Blish GmbH
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without modification,
data/README.md CHANGED
@@ -4,6 +4,12 @@
4
4
 
5
5
  This gem provides full text search for projects using postgresql databases to Alchemy CMS 6.0 and above.
6
6
 
7
+ ## Requirements
8
+
9
+ * Ruby 3.0 or newer
10
+ * Alchemy CMS 7.0 or newer
11
+ * PostgreSQL 12.x or newer
12
+
7
13
  ## Installation
8
14
 
9
15
  Add this line to your application's `Gemfile`:
@@ -24,6 +30,12 @@ Run install script:
24
30
  $ bin/rails g alchemy:pg_search:install
25
31
  ```
26
32
 
33
+ > [!NOTE]
34
+ > The installation will generate an autogenerated column which can be configured with a language. The default
35
+ > value should work for the most languages. If you wish to change this behavior you should add
36
+ > the `Alchemy::PgSearch.config`
37
+ > into the project initializer before running the install script. (See [Configure Behavior](#configure-behavior))
38
+
27
39
  ## Usage
28
40
 
29
41
  Every `Ingredient` will be indexed unless you tell Alchemy to not index a specific content.
@@ -87,11 +99,23 @@ The same works for `ingredients` as well
87
99
  Configure the gem in an initializer. The default configurations are:
88
100
 
89
101
  ```ruby
90
- Alchemy::PgSearch.config = {
91
- paginate_per: 10, # amount of results per page
92
- }
102
+ Rails.application.config.before_initialize do
103
+ Alchemy::PgSearch.config = {
104
+ dictionary: 'simple',
105
+ paginate_per: 10
106
+ }
107
+ end
93
108
  ```
94
109
 
110
+ > [!NOTE]
111
+ > Be aware that `before_initialize` is used. Otherwise the configuration will not have an effect, because of the load
112
+ > order in Rails.
113
+
114
+ Configuration Name | Default Value | Description
115
+ --------------------|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
116
+ 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).
117
+ paginate_per | 10 | Amount of results per page. The value can be set to `nil` to disable the pagination.
118
+
95
119
  You can also overwrite the default multisearch configuration to use other search strategies. For more information take
96
120
  a look into the [PgSearch Readme](https://github.com/Casecommons/pg_search#configuring-multi-search).
97
121
 
@@ -107,7 +131,8 @@ end
107
131
 
108
132
  ### Rendering search results.
109
133
 
110
- In order to render the search results, you'll need a page layout that represents the search result page. Simply mark a page layout as `searchresults: true`. The search form will pick this page as result page.
134
+ In order to render the search results, you'll need a page layout that represents the search result page. Simply mark a
135
+ page layout as `searchresults: true`. The search form will pick this page as result page.
111
136
 
112
137
  #### Search Results Page
113
138
 
@@ -118,7 +143,8 @@ In order to render the search results, you'll need a page layout that represents
118
143
  unique: true
119
144
  ```
120
145
 
121
- Tip: For maximum flexibility you could also add an element that represents the search results. This lets your editors to place additional elements (maybe a header image or additional text blocks) on the search result page.
146
+ Tip: For maximum flexibility you could also add an element that represents the search results. This lets your editors to
147
+ place additional elements (maybe a header image or additional text blocks) on the search result page.
122
148
 
123
149
  ```yaml
124
150
  # page_layouts.yml
@@ -126,16 +152,22 @@ Tip: For maximum flexibility you could also add an element that represents the s
126
152
  searchresults: true
127
153
  unique: true
128
154
  elements:
129
- - searchresults
155
+ - searchresults
130
156
  autogenerate:
131
- - searchresults
157
+ - searchresults
132
158
 
133
159
  # elements.yml
134
160
  - name: searchresults
135
161
  unique: true
162
+ ingredients:
163
+ - role: search_string
164
+ hint: The is only for presentational purposes in the Alchemy preview
165
+ default: lorem
166
+ type: Text
136
167
  ```
137
168
 
138
- and then use the view helpers to render the search form on the page layout partial and the search results on the element view partial.
169
+ and then use the view helpers to render the search form on the page layout partial and the search results on the element
170
+ view partial.
139
171
 
140
172
  ### View Helpers
141
173
 
@@ -12,6 +12,8 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = "This gem provides PostgreSQL full text search to Alchemy"
13
13
  spec.homepage = "https://alchemy-cms.com"
14
14
  spec.license = "BSD-3-Clause"
15
+ spec.required_ruby_version = ">= 3.0.0"
16
+ spec.requirements << 'PostgreSQL >= 12.x'
15
17
 
16
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
17
19
  spec.require_paths = ["lib"]
@@ -34,9 +34,7 @@ module Alchemy
34
34
  # @see Alchemy::PagesHelper#render_search_form
35
35
  #
36
36
  def perform_search
37
- if self.class == Alchemy::Admin::PagesController && params[:query].blank?
38
- params[:query] = "lorem"
39
- end
37
+ set_preview_query
40
38
  return if params[:query].blank?
41
39
  @search_results = search_results
42
40
  if paginate_per
@@ -83,6 +81,16 @@ module Alchemy
83
81
  def paginate_per
84
82
  Alchemy::PgSearch.config[:paginate_per]
85
83
  end
84
+
85
+ private
86
+
87
+ def set_preview_query
88
+ if self.class == Alchemy::Admin::PagesController && params[:query].blank?
89
+ element = search_result_page.draft_version.elements.named(:searchresults).first
90
+
91
+ params[:query] = element&.value_for("search_string") || "lorem"
92
+ end
93
+ end
86
94
  end
87
95
  end
88
96
  end
@@ -1,5 +1,5 @@
1
- class AddSearchableToAlchemyEssenceTexts < ActiveRecord::Migration[5.1]
1
+ class AddSearchableToAlchemyEssenceTexts < ActiveRecord::Migration[6.1]
2
2
  def change
3
- add_column :alchemy_essence_texts, :searchable, :boolean, default: true
3
+ add_column :alchemy_essence_texts, :searchable, :boolean, default: true, if_not_exists: true
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
- class AddSearchableToAlchemyEssenceRichtexts < ActiveRecord::Migration[5.1]
1
+ class AddSearchableToAlchemyEssenceRichtexts < ActiveRecord::Migration[6.1]
2
2
  def change
3
- add_column :alchemy_essence_richtexts, :searchable, :boolean, default: true
3
+ add_column :alchemy_essence_richtexts, :searchable, :boolean, default: true, if_not_exists: true
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
- class AddSearchableToAlchemyEssencePictures < ActiveRecord::Migration[5.1]
1
+ class AddSearchableToAlchemyEssencePictures < ActiveRecord::Migration[6.1]
2
2
  def change
3
- add_column :alchemy_essence_pictures, :searchable, :boolean, default: true
3
+ add_column :alchemy_essence_pictures, :searchable, :boolean, default: true, if_not_exists: true
4
4
  end
5
5
  end
@@ -1,5 +1,9 @@
1
- class MoveSearchableToContents < ActiveRecord::Migration[5.0]
1
+ class MoveSearchableToContents < ActiveRecord::Migration[6.1]
2
2
  def change
3
+ if column_exists? :alchemy_contents, :searchable
4
+ return
5
+ end
6
+
3
7
  add_column :alchemy_contents, :searchable, :boolean, default: true
4
8
 
5
9
  {
@@ -1,5 +1,7 @@
1
1
  class AddPageIdColumnToPgSearchDocuments < ActiveRecord::Migration[6.0]
2
2
  def change
3
- add_reference :pg_search_documents, :page, index: true
3
+ unless column_exists? :pg_search_documents, :page
4
+ add_reference :pg_search_documents, :page, index: true
5
+ end
4
6
  end
5
7
  end
@@ -0,0 +1,9 @@
1
+ class AddSearchableContent < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :pg_search_documents, :searchable_content, :virtual,
4
+ type: :tsvector,
5
+ as: "to_tsvector('#{Alchemy::PgSearch.config.fetch(:dictionary, "simple")}', coalesce(content, ''))",
6
+ stored: true,
7
+ if_not_exists: true
8
+ end
9
+ end
@@ -2,6 +2,7 @@ module Alchemy
2
2
  module PgSearch
3
3
  module Config
4
4
  @@config = {
5
+ dictionary: 'simple',
5
6
  paginate_per: 10
6
7
  }
7
8
 
@@ -12,11 +12,14 @@ module Alchemy
12
12
  end
13
13
 
14
14
  # We need to have the search methods present in all Alchemy controllers
15
- Alchemy::BaseController.send(:include, Alchemy::PgSearch::ControllerMethods)
16
-
17
- # reindex the page after it was published
18
- Alchemy.publish_targets << Alchemy::PgSearch::IndexPageJob
15
+ Alchemy::PagesController.send(:include, Alchemy::PgSearch::ControllerMethods)
16
+ Alchemy::Admin::PagesController.send(:include, Alchemy::PgSearch::ControllerMethods)
19
17
 
18
+ # In development environment, this runs on every code reload, so avoid multiple reindexing jobs
19
+ unless Alchemy.publish_targets.map(&:name).include? 'Alchemy::PgSearch::IndexPageJob'
20
+ # reindex the page after it was published
21
+ Alchemy.publish_targets << Alchemy::PgSearch::IndexPageJob
22
+ end
20
23
  # enable searchable flag in page form
21
24
  Alchemy.enable_searchable = true
22
25
 
@@ -24,7 +27,11 @@ module Alchemy
24
27
  # @link https://github.com/Casecommons/pg_search#searching-using-different-search-features
25
28
  ::PgSearch.multisearch_options = {
26
29
  using: {
27
- tsearch: { prefix: true }
30
+ tsearch: {
31
+ prefix: true,
32
+ dictionary: Alchemy::PgSearch.config.fetch(:dictionary, "simple"),
33
+ tsvector_column: 'searchable_content'
34
+ }
28
35
  }
29
36
  }
30
37
  end
@@ -1,5 +1,5 @@
1
1
  module Alchemy
2
2
  module PgSearch
3
- VERSION = "5.0.0"
3
+ VERSION = "5.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alchemy-pg_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas von Deyen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-01 00:00:00.000000000 Z
11
+ date: 2024-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alchemy_cms
@@ -134,6 +134,7 @@ files:
134
134
  - db/migrate/20141211110126_add_searchable_to_alchemy_essence_pictures.rb
135
135
  - db/migrate/20210923081905_move_searchable_to_contents.rb
136
136
  - db/migrate/20220826125413_add_page_id_column_to_pg_search_documents.rb
137
+ - db/migrate/20231218165617_add_searchable_content.rb
137
138
  - lib/alchemy-pg_search.rb
138
139
  - lib/alchemy/pg_search/config.rb
139
140
  - lib/alchemy/pg_search/engine.rb
@@ -154,14 +155,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
155
  requirements:
155
156
  - - ">="
156
157
  - !ruby/object:Gem::Version
157
- version: '0'
158
+ version: 3.0.0
158
159
  required_rubygems_version: !ruby/object:Gem::Requirement
159
160
  requirements:
160
161
  - - ">="
161
162
  - !ruby/object:Gem::Version
162
163
  version: '0'
163
- requirements: []
164
- rubygems_version: 3.4.17
164
+ requirements:
165
+ - PostgreSQL >= 12.x
166
+ rubygems_version: 3.5.5
165
167
  signing_key:
166
168
  specification_version: 4
167
169
  summary: This gem provides PostgreSQL full text search to Alchemy