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 +7 -0
- data/.travis.yml +1 -22
- data/CHANGELOG.rdoc +4 -0
- data/Gemfile +3 -1
- data/README.rdoc +55 -1
- data/lib/pg_search/version.rb +1 -1
- data/pg_search.gemspec +2 -0
- data/spec/spec_helper.rb +6 -4
- metadata +136 -155
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
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
|
-
|
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
|
data/lib/pg_search/version.rb
CHANGED
data/pg_search.gemspec
CHANGED
data/spec/spec_helper.rb
CHANGED
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
|
-
|
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
|
-
|
20
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
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
|
-
|
149
|
-
|
150
|
-
|
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
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
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:
|
225
|
+
rubygems_version: 2.0.3
|
246
226
|
signing_key:
|
247
|
-
specification_version:
|
248
|
-
summary: PgSearch builds Active Record named scopes that take advantage of PostgreSQL's
|
249
|
-
|
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
|