textacular 5.1.0 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +4 -0
- data/Gemfile +3 -1
- data/README.md +1 -1
- data/Rakefile +10 -4
- data/lib/textacular.rb +13 -12
- data/lib/textacular/version.rb +1 -1
- data/spec/textacular/searchable_spec.rb +29 -0
- data/spec/textacular_spec.rb +7 -0
- metadata +19 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f9a8ae35c8edfea5bfe856e76614e2689eed90d4c41beee8a3271d1c3749586e
|
4
|
+
data.tar.gz: 4e88e50d311cdbccf5aae2fc71f0c3ef2d0af22b284a5bb772c7687f311eb50b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c5f2531575beb68748b2c4458ea7e4e57af212f901270c45e08c359c7e535c81f18a785ea95c8679e8a0be688472f4d798bdec0329212cb89d52789fae785ff
|
7
|
+
data.tar.gz: '0811ce97f78f63a84d41f4576115a07b8b2f01896e8a2d3d9904ff293cf8b95235919a83c66ab02c3f81a9c48653f798bb59d1cd7facb03d0d1f7ba24a97ef1c'
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -43,12 +43,18 @@ namespace :db do
|
|
43
43
|
|
44
44
|
desc 'Run the test database migrations'
|
45
45
|
task :up => :'db:connect' do
|
46
|
-
|
47
|
-
ActiveRecord::Migration.new.migration_context
|
46
|
+
if ActiveRecord.version >= Gem::Version.new('6.0.0')
|
47
|
+
context = ActiveRecord::Migration.new.migration_context
|
48
|
+
migrations = context.migrations
|
49
|
+
schema_migration = context.schema_migration
|
50
|
+
elsif ActiveRecord.version >= Gem::Version.new('5.2')
|
51
|
+
migrations = ActiveRecord::Migration.new.migration_context.migrations
|
52
|
+
schema_migration = nil
|
48
53
|
else
|
49
|
-
ActiveRecord::Migrator.migrations('db/migrate')
|
54
|
+
migrations = ActiveRecord::Migrator.migrations('db/migrate')
|
55
|
+
schema_migration = nil
|
50
56
|
end
|
51
|
-
ActiveRecord::Migrator.new(:up, migrations,
|
57
|
+
ActiveRecord::Migrator.new(:up, migrations, schema_migration).migrate
|
52
58
|
end
|
53
59
|
|
54
60
|
desc 'Reverse the test database migrations'
|
data/lib/textacular.rb
CHANGED
@@ -12,29 +12,29 @@ module Textacular
|
|
12
12
|
'english'
|
13
13
|
end
|
14
14
|
|
15
|
-
def search(query = "", exclusive = true)
|
16
|
-
basic_search(query, exclusive)
|
15
|
+
def search(query = "", exclusive = true, rank_alias = nil)
|
16
|
+
basic_search(query, exclusive, rank_alias)
|
17
17
|
end
|
18
18
|
|
19
|
-
def basic_search(query = "", exclusive = true)
|
19
|
+
def basic_search(query = "", exclusive = true, rank_alias = nil)
|
20
20
|
exclusive, query = munge_exclusive_and_query(exclusive, query)
|
21
21
|
parsed_query_hash = parse_query_hash(query)
|
22
22
|
similarities, conditions = basic_similarities_and_conditions(parsed_query_hash)
|
23
|
-
assemble_query(similarities, conditions, exclusive)
|
23
|
+
assemble_query(similarities, conditions, exclusive, rank_alias)
|
24
24
|
end
|
25
25
|
|
26
|
-
def advanced_search(query = "", exclusive = true)
|
26
|
+
def advanced_search(query = "", exclusive = true, rank_alias = nil)
|
27
27
|
exclusive, query = munge_exclusive_and_query(exclusive, query)
|
28
28
|
parsed_query_hash = parse_query_hash(query)
|
29
29
|
similarities, conditions = advanced_similarities_and_conditions(parsed_query_hash)
|
30
|
-
assemble_query(similarities, conditions, exclusive)
|
30
|
+
assemble_query(similarities, conditions, exclusive, rank_alias)
|
31
31
|
end
|
32
32
|
|
33
|
-
def fuzzy_search(query = '', exclusive = true)
|
33
|
+
def fuzzy_search(query = '', exclusive = true, rank_alias = nil)
|
34
34
|
exclusive, query = munge_exclusive_and_query(exclusive, query)
|
35
35
|
parsed_query_hash = parse_query_hash(query)
|
36
36
|
similarities, conditions = fuzzy_similarities_and_conditions(parsed_query_hash)
|
37
|
-
assemble_query(similarities, conditions, exclusive)
|
37
|
+
assemble_query(similarities, conditions, exclusive, rank_alias)
|
38
38
|
end
|
39
39
|
|
40
40
|
private
|
@@ -113,15 +113,16 @@ module Textacular
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def fuzzy_similarity_string(table_name, column, search_term)
|
116
|
-
"COALESCE(similarity(#{table_name}.#{column}, #{search_term}), 0)"
|
116
|
+
"COALESCE(similarity(#{table_name}.#{column}::text, #{search_term}), 0)"
|
117
117
|
end
|
118
118
|
|
119
119
|
def fuzzy_condition_string(table_name, column, search_term)
|
120
|
-
"(#{table_name}.#{column} % #{search_term})"
|
120
|
+
"(#{table_name}.#{column}::text % #{search_term})"
|
121
121
|
end
|
122
122
|
|
123
|
-
def assemble_query(similarities, conditions, exclusive)
|
124
|
-
|
123
|
+
def assemble_query(similarities, conditions, exclusive, rank_alias)
|
124
|
+
rank_alias ||= 'rank' + rand(100000000000000000).to_s
|
125
|
+
rank = connection.quote_column_name(rank_alias)
|
125
126
|
|
126
127
|
select(Arel.sql("#{quoted_table_name + '.*,' if select_values.empty?} #{similarities.join(" + ")} AS #{rank}")).
|
127
128
|
where(conditions.join(exclusive ? " AND " : " OR ")).
|
data/lib/textacular/version.rb
CHANGED
@@ -190,5 +190,34 @@ RSpec.describe "Searchable" do
|
|
190
190
|
).to eq([penny_arcade])
|
191
191
|
end
|
192
192
|
end
|
193
|
+
|
194
|
+
context 'custom rank' do
|
195
|
+
let!(:questionable_content) do
|
196
|
+
WebComicWithSearchableName.create(
|
197
|
+
name: 'Questionable Content',
|
198
|
+
author: nil,
|
199
|
+
)
|
200
|
+
end
|
201
|
+
|
202
|
+
it "is selected for search" do
|
203
|
+
search_result = WebComicWithSearchableNameAndAuthor.search('Questionable Content', true, 'my_rank')
|
204
|
+
expect(search_result.first.attributes['my_rank']).to be_truthy
|
205
|
+
end
|
206
|
+
|
207
|
+
it "is selected for basic_search" do
|
208
|
+
search_result = WebComicWithSearchableNameAndAuthor.basic_search('Questionable Content', true, 'my_rank')
|
209
|
+
expect(search_result.first.attributes['my_rank']).to be_truthy
|
210
|
+
end
|
211
|
+
|
212
|
+
it "is selected for advanced_search" do
|
213
|
+
search_result = WebComicWithSearchableNameAndAuthor.advanced_search('Questionable Content', true, 'my_rank')
|
214
|
+
expect(search_result.first.attributes['my_rank']).to be_truthy
|
215
|
+
end
|
216
|
+
|
217
|
+
it "is selected for fuzzy_search" do
|
218
|
+
search_result = WebComicWithSearchableNameAndAuthor.fuzzy_search('Questionable Content', true, 'my_rank')
|
219
|
+
expect(search_result.first.attributes['my_rank']).to be_truthy
|
220
|
+
end
|
221
|
+
end
|
193
222
|
end
|
194
223
|
end
|
data/spec/textacular_spec.rb
CHANGED
@@ -181,6 +181,13 @@ RSpec.describe Textacular do
|
|
181
181
|
expect(GameExtendedWithTextacular).to respond_to(:search)
|
182
182
|
end
|
183
183
|
|
184
|
+
describe "#fuzzy_search" do
|
185
|
+
it 'searches non-text columns' do
|
186
|
+
expect(GameExtendedWithTextacular.fuzzy_search(id: mario.id)
|
187
|
+
).to eq([mario])
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
184
191
|
describe "#advanced_search" do
|
185
192
|
context "with a String argument" do
|
186
193
|
it "searches across all :string columns (if not indexes have been specified)" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: textacular
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Hamill
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2019-08-20 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: pg
|
@@ -97,6 +97,20 @@ dependencies:
|
|
97
97
|
- - ">="
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
|
+
- !ruby/object:Gem::Dependency
|
101
|
+
name: byebug
|
102
|
+
requirement: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
type: :development
|
108
|
+
prerelease: false
|
109
|
+
version_requirements: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
100
114
|
- !ruby/object:Gem::Dependency
|
101
115
|
name: activerecord
|
102
116
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,7 +120,7 @@ dependencies:
|
|
106
120
|
version: '5.0'
|
107
121
|
- - "<"
|
108
122
|
- !ruby/object:Gem::Version
|
109
|
-
version: '6.
|
123
|
+
version: '6.1'
|
110
124
|
type: :runtime
|
111
125
|
prerelease: false
|
112
126
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -116,7 +130,7 @@ dependencies:
|
|
116
130
|
version: '5.0'
|
117
131
|
- - "<"
|
118
132
|
- !ruby/object:Gem::Version
|
119
|
-
version: '6.
|
133
|
+
version: '6.1'
|
120
134
|
description: |-
|
121
135
|
Textacular exposes full text search capabilities from PostgreSQL, extending
|
122
136
|
ActiveRecord with scopes making search easy and fun!
|
@@ -181,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
195
|
version: '0'
|
182
196
|
requirements: []
|
183
197
|
rubyforge_project:
|
184
|
-
rubygems_version: 2.6
|
198
|
+
rubygems_version: 2.7.6
|
185
199
|
signing_key:
|
186
200
|
specification_version: 4
|
187
201
|
summary: Textacular exposes full text search capabilities from PostgreSQL
|
@@ -207,4 +221,3 @@ test_files:
|
|
207
221
|
- spec/textacular/migration_generator_spec.rb
|
208
222
|
- spec/textacular/searchable_spec.rb
|
209
223
|
- spec/textacular/trigram_installer_spec.rb
|
210
|
-
has_rdoc:
|