pg_search 0.6.4 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cdc3e1fa91903e87b5f1a6dfb0ac0318061e7646
4
+ data.tar.gz: 16186ed72bc2e8bbc57c0c7949a6b051756db408
5
+ SHA512:
6
+ metadata.gz: 58ded3351aca03cc89d6c23815845a4f8835b981f68755bae65ba202360e4afb5273e11683d6de1896d21f52f4c81fb921ed6b37c544113aa4bde01cc8c28018
7
+ data.tar.gz: 7603d827a286170f0a69a7e77b452ba7919f5e858a0ed0ee2eea196108d25654070417386ccdee7a377d7221c0a06091bd6e4608ea5627697716b5f55988af73
data/.travis.yml CHANGED
@@ -1,45 +1,24 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 1.8.7
5
4
  - 1.9.3
6
5
  - 2.0.0
7
- - jruby-18mode
8
6
  - jruby-19mode
9
- - rbx-18mode
10
7
  - rbx-19mode
11
- - ree
12
8
 
13
9
  env:
14
10
  - ACTIVE_RECORD_BRANCH="master"
15
11
  - ACTIVE_RECORD_BRANCH="4-0-stable"
12
+ - ACTIVE_RECORD_VERSION="~> 4.0.0"
16
13
  - ACTIVE_RECORD_VERSION="~> 3.2.0"
17
14
  - ACTIVE_RECORD_VERSION="~> 3.1.0"
18
15
 
19
16
  matrix:
20
17
  allow_failures:
21
- - rvm: rbx-18mode
22
18
  - rvm: rbx-19mode
23
19
  - rvm: jruby-19mode
24
20
  - env: ACTIVE_RECORD_BRANCH="master"
25
21
  - env: ACTIVE_RECORD_BRANCH="4-0-stable"
26
- exclude:
27
- - rvm: 1.8.7
28
- env: ACTIVE_RECORD_BRANCH="master"
29
- - rvm: 1.8.7
30
- env: ACTIVE_RECORD_BRANCH="4-0-stable"
31
- - rvm: jruby-18mode
32
- env: ACTIVE_RECORD_BRANCH="master"
33
- - rvm: jruby-18mode
34
- env: ACTIVE_RECORD_BRANCH="4-0-stable"
35
- - rvm: rbx-18mode
36
- env: ACTIVE_RECORD_BRANCH="master"
37
- - rvm: rbx-18mode
38
- env: ACTIVE_RECORD_BRANCH="4-0-stable"
39
- - rvm: ree
40
- env: ACTIVE_RECORD_BRANCH="master"
41
- - rvm: ree
42
- env: ACTIVE_RECORD_BRANCH="4-0-stable"
43
22
 
44
23
  before_script:
45
24
  - "psql -c 'create database pg_search_test;' -U postgres >/dev/null"
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,9 @@
1
1
  = PgSearch
2
2
 
3
+ == 0.7.0
4
+
5
+ * Start requiring Ruby 1.9.2 or later
6
+
3
7
  == 0.6.4
4
8
 
5
9
  * Fix issue with using more than two features in the same scope
data/Gemfile CHANGED
@@ -8,7 +8,9 @@ gem "activerecord-jdbcpostgresql-adapter", :platform => :jruby
8
8
  gem "activerecord", ENV["ACTIVE_RECORD_VERSION"] if ENV["ACTIVE_RECORD_VERSION"]
9
9
  gem "activerecord", :github => "rails", :branch => ENV["ACTIVE_RECORD_BRANCH"] if ENV["ACTIVE_RECORD_BRANCH"]
10
10
 
11
- gem 'coveralls', :require => false, :platform => :mri_20
11
+ if ENV["TRAVIS"]
12
+ gem 'coveralls', :require => false, :platform => :mri_20
13
+ end
12
14
 
13
15
  group :development do
14
16
  gem 'guard-rspec', :require => false
data/README.rdoc CHANGED
@@ -16,6 +16,7 @@ Read the blog post introducing PgSearch at http://pivotallabs.com/pg-search/
16
16
 
17
17
  == REQUIREMENTS
18
18
 
19
+ * Ruby 1.9.2 or later
19
20
  * Active Record 3.1 or later
20
21
  * PostgreSQL
21
22
  * {PostgreSQL contrib packages for certain features}[https://github.com/Casecommons/pg_search/wiki/Installing-Postgres-Contrib-Modules]
@@ -24,7 +25,7 @@ Read the blog post introducing PgSearch at http://pivotallabs.com/pg-search/
24
25
 
25
26
  gem install pg_search
26
27
 
27
- === Rails 3.1 or later
28
+ === Rails 3.1 or later, Ruby 1.9.2 or later
28
29
 
29
30
  In Gemfile
30
31
 
@@ -52,6 +53,14 @@ In addition to installing and requiring the gem, you may want to include the PgS
52
53
 
53
54
  load "pg_search/tasks.rb"
54
55
 
56
+ === Ruby 1.8.7 or earlier
57
+
58
+ The newest versions of PgSearch no longer support Ruby 1.8.7. However, the 0.6 series still works. It's not actively maintained, but submissions are welcome for backports and bugfixes.
59
+
60
+ gem 'pg_search', "~> 0.6.4"
61
+
62
+ The 0.6 branch lives at https://github.com/Casecommons/pg_search/tree/0.6-stable
63
+
55
64
  == USAGE
56
65
 
57
66
  To add PgSearch to an Active Record model, simply include the PgSearch module.
@@ -598,6 +607,51 @@ To use this functionality you'll need to do a few things:
598
607
 
599
608
  Please note that the :against column is only used when the tsvector_column is not present for the search type.
600
609
 
610
+ === Configuring ranking and ordering
611
+
612
+ ==== :ranked_by (Choosing a ranking algorithm)
613
+
614
+ By default, pg_search ranks results based on the :tsearch similarity between the searchable text and the query. To use a different ranking algorithm, you can pass a :ranked_by option to pg_search_scope.
615
+
616
+ pg_search_scope :search_by_tsearch_but_rank_by_trigram,
617
+ :against => :title,
618
+ :using => [:tsearch],
619
+ :ranked_by => ":trigram"
620
+
621
+ Note that :ranked_by using a String to represent the ranking expression. This allows for more complex possibilities. Strings like ":tsearch", ":trigram", and ":dmetaphone" are automatically expanded into the appropriate SQL expressions.
622
+
623
+ # Weighted ranking to balance multiple approaches
624
+ :ranked_by => ":dmetaphone + (0.25 * :trigram)"
625
+
626
+ # A more complex example, where books.num_pages is an integer column in the table itself
627
+ :ranked_by => "(books.num_pages * :trigram) + (:tsearch / 2.0)"
628
+
629
+ ==== :order_within_rank (Breaking ties)
630
+
631
+ PostgreSQL does not guarantee a consistent order when multiple records have the same value in the ORDER BY clause. This can cause trouble with pagination.
632
+
633
+ Imagine a case where 12 records all have the same ranking value. If you use a pagination library such as {kaminari}[https://github.com/amatsuda/kaminari] or {will_paginate}[https://github.com/mislav/will_paginate] to return results in pages of 10, then you would expect to see 10 of the records on page 1, and the remaining 2 records at the top of the next page, ahead of lower-ranked results.
634
+
635
+ But since there is no consistent ordering, PostgreSQL might choose to rearrange the order of those 12 records between different SQL statements. You might end up getting some of the same records from page 1 on page 2 as well, and likewise there may be records that don't show up at all.
636
+
637
+ pg_search fixes this problem by adding a second expression to the ORDER BY clause, after the :ranked_by expression explained above. By default, the tiebreaker order is ascending by id.
638
+
639
+ ORDER BY [complicated :ranked_by expression...], id ASC
640
+
641
+ This might not be desirable for your application, especially if you do not want old records to outrank new records. By passing an :order_within_rank, you can specify an alternate tiebreaker expression. A common example would be descending by updated_at, to rank the most recently updated records first.
642
+
643
+ pg_search_scope :search_and_break_ties_by_latest_update,
644
+ :against => [:title, :content],
645
+ :order_within_rank => "blog_posts.updated_at DESC"
646
+
647
+ ==== PgSearch#pg_search_rank (Reading a record's rank as a Float)
648
+
649
+ It may be useful or interesting to see the rank of a particular record. This can be helpful for debugging why one record outranks another. You could also use it to show some sort of relevancy value to end users of an application. Just call .pg_search_rank on a record returned by a pg_search_scope.
650
+
651
+ shirt_brands = ShirtBrand.search_by_name("Penguin")
652
+ shirt_brands[0].pg_search_rank #=> 0.0759909
653
+ shirt_brands[1].pg_search_rank #=> 0.0607927
654
+
601
655
  == ATTRIBUTIONS
602
656
 
603
657
  PgSearch would not have been possible without inspiration from
@@ -1,3 +1,3 @@
1
1
  module PgSearch
2
- VERSION = "0.6.4"
2
+ VERSION = "0.7.0"
3
3
  end
data/pg_search.gemspec CHANGED
@@ -28,4 +28,6 @@ Gem::Specification.new do |s|
28
28
  s.add_development_dependency 'rspec'
29
29
  s.add_development_dependency 'with_model'
30
30
  s.add_development_dependency 'will_paginate'
31
+
32
+ s.required_ruby_version = ">= 1.9.2"
31
33
  end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  require "bundler/setup"
2
2
  require "pg_search"
3
3
 
4
- begin
5
- require 'coveralls'
6
- Coveralls.wear!
7
- rescue LoadError
4
+ if ENV["TRAVIS"]
5
+ begin
6
+ require 'coveralls'
7
+ Coveralls.wear!
8
+ rescue LoadError
9
+ end
8
10
  end
9
11
 
10
12
  begin
metadata CHANGED
@@ -1,162 +1,151 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pg_search
3
- version: !ruby/object:Gem::Version
4
- hash: 15
5
- prerelease:
6
- segments:
7
- - 0
8
- - 6
9
- - 4
10
- version: 0.6.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Grant Hutchins
14
8
  - Case Commons, LLC
15
9
  autorequire:
16
10
  bindir: bin
17
11
  cert_chain: []
18
-
19
- date: 2013-05-26 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2013-07-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: activerecord
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 5
30
- segments:
31
- - 3
32
- - 1
33
- version: "3.1"
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '3.1'
34
21
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: activesupport
38
22
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 5
45
- segments:
46
- - 3
47
- - 1
48
- version: "3.1"
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '3.1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: activesupport
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '3.1'
49
35
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: arel
53
36
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '3.1'
42
+ - !ruby/object:Gem::Dependency
43
+ name: arel
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
63
49
  type: :runtime
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
66
- name: rake
67
50
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
69
- none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
- version: "0"
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
77
63
  type: :development
78
- version_requirements: *id004
79
- - !ruby/object:Gem::Dependency
80
- name: rdoc
81
64
  prerelease: false
82
- requirement: &id005 !ruby/object:Gem::Requirement
83
- none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- version: "0"
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rdoc
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
91
77
  type: :development
92
- version_requirements: *id005
93
- - !ruby/object:Gem::Dependency
94
- name: pry
95
78
  prerelease: false
96
- requirement: &id006 !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- hash: 3
102
- segments:
103
- - 0
104
- version: "0"
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: pry
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
105
91
  type: :development
106
- version_requirements: *id006
107
- - !ruby/object:Gem::Dependency
108
- name: rspec
109
92
  prerelease: false
110
- requirement: &id007 !ruby/object:Gem::Requirement
111
- none: false
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- hash: 3
116
- segments:
117
- - 0
118
- version: "0"
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rspec
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
119
105
  type: :development
120
- version_requirements: *id007
121
- - !ruby/object:Gem::Dependency
122
- name: with_model
123
106
  prerelease: false
124
- requirement: &id008 !ruby/object:Gem::Requirement
125
- none: false
126
- requirements:
127
- - - ">="
128
- - !ruby/object:Gem::Version
129
- hash: 3
130
- segments:
131
- - 0
132
- version: "0"
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: with_model
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
133
119
  type: :development
134
- version_requirements: *id008
135
- - !ruby/object:Gem::Dependency
136
- name: will_paginate
137
120
  prerelease: false
138
- requirement: &id009 !ruby/object:Gem::Requirement
139
- none: false
140
- requirements:
141
- - - ">="
142
- - !ruby/object:Gem::Version
143
- hash: 3
144
- segments:
145
- - 0
146
- version: "0"
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: will_paginate
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
147
133
  type: :development
148
- version_requirements: *id009
149
- description: PgSearch builds Active Record named scopes that take advantage of PostgreSQL's full text search
150
- email:
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ description: PgSearch builds Active Record named scopes that take advantage of PostgreSQL's
141
+ full text search
142
+ email:
151
143
  - gems@nertzy.com
152
144
  - casecommons-dev@googlegroups.com
153
145
  executables: []
154
-
155
146
  extensions: []
156
-
157
147
  extra_rdoc_files: []
158
-
159
- files:
148
+ files:
160
149
  - .autotest
161
150
  - .gitignore
162
151
  - .rspec
@@ -214,39 +203,31 @@ files:
214
203
  - sql/uninstall_unnest.sql
215
204
  - sql/unnest.sql
216
205
  homepage: https://github.com/Casecommons/pg_search
217
- licenses:
206
+ licenses:
218
207
  - MIT
208
+ metadata: {}
219
209
  post_install_message:
220
210
  rdoc_options: []
221
-
222
- require_paths:
211
+ require_paths:
223
212
  - lib
224
- required_ruby_version: !ruby/object:Gem::Requirement
225
- none: false
226
- requirements:
227
- - - ">="
228
- - !ruby/object:Gem::Version
229
- hash: 3
230
- segments:
231
- - 0
232
- version: "0"
233
- required_rubygems_version: !ruby/object:Gem::Requirement
234
- none: false
235
- requirements:
236
- - - ">="
237
- - !ruby/object:Gem::Version
238
- hash: 3
239
- segments:
240
- - 0
241
- version: "0"
213
+ required_ruby_version: !ruby/object:Gem::Requirement
214
+ requirements:
215
+ - - '>='
216
+ - !ruby/object:Gem::Version
217
+ version: 1.9.2
218
+ required_rubygems_version: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - '>='
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
242
223
  requirements: []
243
-
244
224
  rubyforge_project:
245
- rubygems_version: 1.8.24
225
+ rubygems_version: 2.0.3
246
226
  signing_key:
247
- specification_version: 3
248
- summary: PgSearch builds Active Record named scopes that take advantage of PostgreSQL's full text search
249
- test_files:
227
+ specification_version: 4
228
+ summary: PgSearch builds Active Record named scopes that take advantage of PostgreSQL's
229
+ full text search
230
+ test_files:
250
231
  - spec/integration/associations_spec.rb
251
232
  - spec/integration/pagination_spec.rb
252
233
  - spec/integration/pg_search_spec.rb