db_text_search 0.2.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGES.md +23 -0
- data/README.md +1 -1
- data/RELEASE-CHECKLIST.md +17 -0
- data/db_text_search.gemspec +4 -4
- data/lib/db_text_search.rb +1 -1
- data/lib/db_text_search/case_insensitive.rb +17 -5
- data/lib/db_text_search/case_insensitive/abstract_adapter.rb +7 -0
- data/lib/db_text_search/case_insensitive/collate_nocase_adapter.rb +5 -0
- data/lib/db_text_search/case_insensitive/insensitive_column_adapter.rb +6 -1
- data/lib/db_text_search/case_insensitive/lower_adapter.rb +7 -1
- data/lib/db_text_search/full_text.rb +2 -1
- data/lib/db_text_search/full_text/sqlite_adapter.rb +1 -2
- data/lib/db_text_search/version.rb +1 -1
- data/rubocop.gemfile +1 -0
- data/shared.gemfile +1 -6
- metadata +25 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f1cd1c9c3fac9de18b145e38bbb51b61bb686aa7c4a750bb3857170ee29afdd0
|
4
|
+
data.tar.gz: 2b87d5dc1d79444fffe06eb5686de7f8bf52d2e1a1cfb650ddcc61ff1328e6c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb396b8558c1f6bce6ed3eb9f2c1c70179a729d0f22578fbadbf85503eeeef098596fb7c9dbb26e3a81bc099dcd708ba9746ff69245968de7cda9aea03aba6e1
|
7
|
+
data.tar.gz: bfaff15b9d3e0bb7416d190723e54e9900239421af12faa329f9d8bf2dd9161d9e22b6e17b402b079bd103d3218a689f0b45fa123fba0b526a764691192d2a14
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,26 @@
|
|
1
|
+
## v0.3.2
|
2
|
+
|
3
|
+
* Allow Ruby 3.0
|
4
|
+
|
5
|
+
## v0.3.1
|
6
|
+
|
7
|
+
* Rails 6 support.
|
8
|
+
[ff16189f](https://github.com/thredded/db_text_search/commit/ff16189fdc7b1bf7b66e4bedc27483aaf3e75414)
|
9
|
+
|
10
|
+
## v0.3.0
|
11
|
+
|
12
|
+
* **Feature** Case insensitive sorting via the new `CaseInsensitive#column_for_order(asc_or_desc)` method. Use it like `SomeModel.some_scope.order(CaseInsensitive.new(SomeModel, :some_field).column_for_order(:asc))`
|
13
|
+
|
14
|
+
## v0.2.2
|
15
|
+
|
16
|
+
* Raises a more helpful error if the column is not found when calling
|
17
|
+
`DbTextSearch::CaseInsensitive`.
|
18
|
+
|
19
|
+
## v0.2.1
|
20
|
+
|
21
|
+
* Support for PostGIS adapters.
|
22
|
+
[#2](https://github.com/thredded/db_text_search/issues/2)
|
23
|
+
|
1
24
|
## v0.2.0
|
2
25
|
|
3
26
|
* **Feature** Prefix matching via the new `CaseInsensitive#prefix` method.
|
data/README.md
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
The checklist for releasing a new version of db_text_search.
|
2
|
+
|
3
|
+
Pre-requisites for the releaser:
|
4
|
+
|
5
|
+
* Push access to RubyGems.
|
6
|
+
|
7
|
+
Release checklist:
|
8
|
+
|
9
|
+
- [ ] Update gem version in `version.rb` and `README.md`.
|
10
|
+
- [ ] Update `CHANGELOG.md`.
|
11
|
+
- [ ] Wait for the Travis build to come back green.
|
12
|
+
- [ ] Tag the release and push it to rubygems:
|
13
|
+
|
14
|
+
```bash
|
15
|
+
rake release
|
16
|
+
```
|
17
|
+
- [ ] Copy the release notes from the changelog to [GitHub Releases](https://github.com/thredded/thredded/releases).
|
data/db_text_search.gemspec
CHANGED
@@ -20,15 +20,15 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|bin|script)/|^\.|Rakefile|Gemfile}) }
|
21
21
|
|
22
22
|
s.require_paths = ['lib']
|
23
|
-
s.required_ruby_version = '
|
23
|
+
s.required_ruby_version = '>= 2.1', '< 4.0'
|
24
24
|
|
25
|
-
s.add_dependency 'activerecord', '>= 4.1.15', '<
|
25
|
+
s.add_dependency 'activerecord', '>= 4.1.15', '< 7.0'
|
26
26
|
|
27
27
|
s.add_development_dependency 'mysql2', '>= 0.3.20'
|
28
28
|
s.add_development_dependency 'pg', '>= 0.18.4'
|
29
29
|
s.add_development_dependency 'sqlite3', '>= 1.3.11'
|
30
30
|
|
31
|
-
s.add_development_dependency '
|
32
|
-
s.add_development_dependency 'rake', '~> 11.0'
|
31
|
+
s.add_development_dependency 'rake', '~> 13.0'
|
33
32
|
s.add_development_dependency 'rspec', '~> 3.4'
|
33
|
+
s.add_development_dependency 'simplecov'
|
34
34
|
end
|
data/lib/db_text_search.rb
CHANGED
@@ -29,13 +29,20 @@ module DbTextSearch
|
|
29
29
|
@adapter.prefix(query)
|
30
30
|
end
|
31
31
|
|
32
|
+
# @param asc_or_desc [Symbol]
|
33
|
+
# @return [Arel::Collectors::SQLString] a string to be used within an `.order()`
|
34
|
+
def column_for_order(asc_or_desc)
|
35
|
+
fail 'Pass either :asc or :desc' unless %i[asc desc].include?(asc_or_desc)
|
36
|
+
@adapter.column_for_order(asc_or_desc)
|
37
|
+
end
|
38
|
+
|
32
39
|
# Adds a case-insensitive column to the given table.
|
33
40
|
# @param connection [ActiveRecord::ConnectionAdapters::AbstractAdapter]
|
34
41
|
# @param table_name [String, Symbol]
|
35
42
|
# @param column_name [String, Symbol]
|
36
43
|
# @param options [Hash] passed to ActiveRecord::ConnectionAdapters::SchemaStatements#add_index
|
37
44
|
def self.add_ci_text_column(connection, table_name, column_name, options = {})
|
38
|
-
|
45
|
+
type, options = DbTextSearch.match_adapter(
|
39
46
|
connection,
|
40
47
|
mysql: -> { [:text, options] },
|
41
48
|
postgres: -> {
|
@@ -48,7 +55,9 @@ module DbTextSearch
|
|
48
55
|
else
|
49
56
|
['TEXT COLLATE NOCASE', options]
|
50
57
|
end
|
51
|
-
}
|
58
|
+
}
|
59
|
+
)
|
60
|
+
connection.add_column table_name, column_name, type, **options
|
52
61
|
end
|
53
62
|
|
54
63
|
# Add an index for case-insensitive string search.
|
@@ -78,7 +87,8 @@ module DbTextSearch
|
|
78
87
|
postgres: lower_or_insensitive,
|
79
88
|
# Always use COLLATE NOCASE for SQLite, as we can't check if the column is case-sensitive.
|
80
89
|
# It has no performance impact apart from slightly longer query strings for case-insensitive columns.
|
81
|
-
sqlite: -> { CollateNocaseAdapter }
|
90
|
+
sqlite: -> { CollateNocaseAdapter }
|
91
|
+
)
|
82
92
|
end
|
83
93
|
|
84
94
|
# @param connection [ActiveRecord::ConnectionAdapters::AbstractAdapter]
|
@@ -87,13 +97,15 @@ module DbTextSearch
|
|
87
97
|
# @return [Boolean]
|
88
98
|
# @note sqlite not supported.
|
89
99
|
# @api private
|
90
|
-
def self.column_case_sensitive?(connection, table_name, column_name)
|
100
|
+
def self.column_case_sensitive?(connection, table_name, column_name) # rubocop:disable Metrics/AbcSize
|
91
101
|
column = connection.schema_cache.columns(table_name).detect { |c| c.name == column_name.to_s }
|
102
|
+
fail "Column #{column_name.to_s.inspect} not found on table #{table_name.inspect}" if column.nil?
|
92
103
|
DbTextSearch.match_adapter(
|
93
104
|
connection,
|
94
105
|
mysql: -> { column.case_sensitive? },
|
95
106
|
postgres: -> { column.sql_type !~ /citext/i },
|
96
|
-
sqlite: -> { DbTextSearch.unsupported_adapter! connection }
|
107
|
+
sqlite: -> { DbTextSearch.unsupported_adapter! connection }
|
108
|
+
)
|
97
109
|
end
|
98
110
|
end
|
99
111
|
end
|
@@ -30,6 +30,13 @@ module DbTextSearch
|
|
30
30
|
fail 'abstract'
|
31
31
|
end
|
32
32
|
|
33
|
+
# @param asc_or_desc [Symbol]
|
34
|
+
# @return [Arel::Collectors::SQLString]
|
35
|
+
# @abstract
|
36
|
+
def column_for_order(asc_or_desc)
|
37
|
+
fail 'abstract'
|
38
|
+
end
|
39
|
+
|
33
40
|
# Add an index for case-insensitive string search.
|
34
41
|
#
|
35
42
|
# @param connection [ActiveRecord::ConnectionAdapters::AbstractAdapter]
|
@@ -22,6 +22,11 @@ module DbTextSearch
|
|
22
22
|
escaped_query
|
23
23
|
end
|
24
24
|
|
25
|
+
# (see AbstractAdapter#column_for_order)
|
26
|
+
def column_for_order(asc_or_desc)
|
27
|
+
Arel.sql("#{quoted_scope_column} COLLATE NOCASE #{asc_or_desc}")
|
28
|
+
end
|
29
|
+
|
25
30
|
# (see AbstractAdapter.add_index)
|
26
31
|
def self.add_index(connection, table_name, column_name, options = {})
|
27
32
|
# TODO: Switch to the native Rails solution once it's landed, as the current one requires SQL dump format.
|
@@ -16,9 +16,14 @@ module DbTextSearch
|
|
16
16
|
@scope.where "#{quoted_scope_column} LIKE ?", "#{sanitize_sql_like(query)}%"
|
17
17
|
end
|
18
18
|
|
19
|
+
# (see AbstractAdapter#column_for_order)
|
20
|
+
def column_for_order(asc_or_desc)
|
21
|
+
Arel.sql("#{quoted_scope_column} #{asc_or_desc}")
|
22
|
+
end
|
23
|
+
|
19
24
|
# (see AbstractAdapter.add_index)
|
20
25
|
def self.add_index(connection, table_name, column_name, options = {})
|
21
|
-
connection.add_index table_name, column_name, options
|
26
|
+
connection.add_index table_name, column_name, **options
|
22
27
|
end
|
23
28
|
end
|
24
29
|
end
|
@@ -17,6 +17,11 @@ module DbTextSearch
|
|
17
17
|
@scope.where "LOWER(#{quoted_scope_column}) LIKE LOWER(?)", "#{sanitize_sql_like(query)}%"
|
18
18
|
end
|
19
19
|
|
20
|
+
# (see AbstractAdapter#column_for_order)
|
21
|
+
def column_for_order(asc_or_desc)
|
22
|
+
Arel.sql("LOWER(#{quoted_scope_column}) #{asc_or_desc}")
|
23
|
+
end
|
24
|
+
|
20
25
|
# (see AbstractAdapter.add_index)
|
21
26
|
def self.add_index(connection, table_name, column_name, options = {})
|
22
27
|
unsupported = -> { DbTextSearch.unsupported_adapter! connection }
|
@@ -31,7 +36,8 @@ module DbTextSearch
|
|
31
36
|
connection.exec_query(quoted_create_index(connection, table_name, **options))
|
32
37
|
},
|
33
38
|
mysql: unsupported,
|
34
|
-
sqlite: unsupported
|
39
|
+
sqlite: unsupported
|
40
|
+
)
|
35
41
|
end
|
36
42
|
end
|
37
43
|
end
|
@@ -20,8 +20,7 @@ module DbTextSearch
|
|
20
20
|
end
|
21
21
|
|
22
22
|
# A no-op, as we just use LIKE for sqlite.
|
23
|
-
def self.add_index(_connection, _table_name, _column_name, name:, pg_ts_config:)
|
24
|
-
end
|
23
|
+
def self.add_index(_connection, _table_name, _column_name, name:, pg_ts_config:); end
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
data/rubocop.gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gem 'rubocop', '= 0.49.1'
|
data/shared.gemfile
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db_text_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gleb Mazovetskiy
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: 4.1.15
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '7.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: 4.1.15
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '7.0'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: mysql2
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,47 +73,47 @@ dependencies:
|
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: 1.3.11
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
76
|
+
name: rake
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: '
|
81
|
+
version: '13.0'
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
88
|
+
version: '13.0'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
90
|
+
name: rspec
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
95
|
+
version: '3.4'
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '
|
102
|
+
version: '3.4'
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
|
-
name:
|
104
|
+
name: simplecov
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
|
-
- - "
|
107
|
+
- - ">="
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: '
|
109
|
+
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
|
-
- - "
|
114
|
+
- - ">="
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: '
|
116
|
+
version: '0'
|
117
117
|
description: Different relational databases treat text search very differently. DbTextSearch
|
118
118
|
provides a unified interface on top of ActiveRecord for SQLite, MySQL, and PostgreSQL
|
119
119
|
to do case-insensitive string-in-set querying and CI index creation, and basic full-text
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- CODE_OF_CONDUCT.md
|
129
129
|
- LICENSE.txt
|
130
130
|
- README.md
|
131
|
+
- RELEASE-CHECKLIST.md
|
131
132
|
- db_text_search.gemspec
|
132
133
|
- lib/db_text_search.rb
|
133
134
|
- lib/db_text_search/case_insensitive.rb
|
@@ -142,31 +143,33 @@ files:
|
|
142
143
|
- lib/db_text_search/full_text/sqlite_adapter.rb
|
143
144
|
- lib/db_text_search/query_building.rb
|
144
145
|
- lib/db_text_search/version.rb
|
146
|
+
- rubocop.gemfile
|
145
147
|
- shared.gemfile
|
146
148
|
homepage: https://github.com/thredded/db_text_search
|
147
149
|
licenses:
|
148
150
|
- MIT
|
149
151
|
metadata: {}
|
150
|
-
post_install_message:
|
152
|
+
post_install_message:
|
151
153
|
rdoc_options: []
|
152
154
|
require_paths:
|
153
155
|
- lib
|
154
156
|
required_ruby_version: !ruby/object:Gem::Requirement
|
155
157
|
requirements:
|
156
|
-
- - "
|
158
|
+
- - ">="
|
157
159
|
- !ruby/object:Gem::Version
|
158
160
|
version: '2.1'
|
161
|
+
- - "<"
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '4.0'
|
159
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
165
|
requirements:
|
161
166
|
- - ">="
|
162
167
|
- !ruby/object:Gem::Version
|
163
168
|
version: '0'
|
164
169
|
requirements: []
|
165
|
-
|
166
|
-
|
167
|
-
signing_key:
|
170
|
+
rubygems_version: 3.2.3
|
171
|
+
signing_key:
|
168
172
|
specification_version: 4
|
169
173
|
summary: A unified interface on top of ActiveRecord for SQLite, MySQL, and PostgreSQLfor
|
170
174
|
case-insensitive string search and basic full-text search.
|
171
175
|
test_files: []
|
172
|
-
has_rdoc:
|