alchemy-pg_search 5.0.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/CHANGELOG.md +20 -0
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/README.md +40 -8
- data/alchemy-pg_search.gemspec +2 -0
- data/app/controller/alchemy/pg_search/controller_methods.rb +11 -3
- data/db/migrate/20141211105526_add_searchable_to_alchemy_essence_texts.rb +2 -2
- data/db/migrate/20141211105942_add_searchable_to_alchemy_essence_richtexts.rb +2 -2
- data/db/migrate/20141211110126_add_searchable_to_alchemy_essence_pictures.rb +2 -2
- data/db/migrate/20210923081905_move_searchable_to_contents.rb +5 -1
- data/db/migrate/20220826125413_add_page_id_column_to_pg_search_documents.rb +3 -1
- data/db/migrate/20231218165617_add_searchable_content.rb +9 -0
- data/lib/alchemy/pg_search/config.rb +1 -0
- data/lib/alchemy/pg_search/engine.rb +12 -5
- data/lib/alchemy/pg_search/version.rb +1 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd79aeea752492e2162f8338e15726c51af184f2ee0025cffd6f7eb98914eb8c
|
4
|
+
data.tar.gz: 5b8bd8894f18350baffdb0537bcbdebc9e781f8aa86251919972b6a076c3171f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0333bfcb6a05dc82aa69c7147429bbe337315d90c61bcbbf3ae6d4ef3d11b28137e934dde2d38f98ce02288dcfb4d08cadc099b6d2d998da0c69abe044d3089
|
7
|
+
data.tar.gz: f1b6ac52bdfc1cb2199344eca5f691c03063b1d9d1a56d28236512621650640390adf093842c8111998992a26bfed2b2927360f2bddcbc286e9bc0910226ec5e
|
data/.github/workflows/ci.yml
CHANGED
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
data/LICENSE
CHANGED
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
|
-
|
91
|
-
|
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
|
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
|
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
|
-
|
155
|
+
- searchresults
|
130
156
|
autogenerate:
|
131
|
-
|
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
|
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
|
|
data/alchemy-pg_search.gemspec
CHANGED
@@ -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
|
-
|
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[
|
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[
|
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[
|
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[
|
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
|
-
|
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
|
@@ -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::
|
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: {
|
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
|
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.
|
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:
|
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:
|
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
|
-
|
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
|