pg_search 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d88e1b1a697e2b7c60254e229f05ef8a7e7290fd
4
- data.tar.gz: 237578e6b7961e9662d513f246878ad07e27d52e
3
+ metadata.gz: 8d495a89c4bddfe4c4d367fb1cc8e4c5b1bea048
4
+ data.tar.gz: 611249f3cddce656579b5f4618a4d8a26ed77f8d
5
5
  SHA512:
6
- metadata.gz: 8a20e4bccc363bd4625b97d4533fedbb4a2fe22d0be7f28b4498456c7189a4ee34209e6e3f81109a2285680dc693a6cf17946ba301b3d67c7e7c6a4a4dac0e28
7
- data.tar.gz: 0e119a3b707bbb3b55272763893eacf8d2857f4171733e114797a68d8d1d506c7b491b6e27eccb9994276f0615911947748c4553dafd9f4a56df0f50c4c9e963
6
+ metadata.gz: b6bfca34ff32c71bc153173f6cd5ea293ab35bea8aa55cdabd53388b687e56b273402b2b822789994d378fed58e3591a1a91c724cfc91f1085edba9d988773f6
7
+ data.tar.gz: d03fc9fe66c02fb33744ec86ab12ec97d662c3eaff075da0c1b0f6f994e3c3f4c8da47045d4ce227bb6552e8890d95729d1cc679e80115378aabd9f7fd4b2324
@@ -0,0 +1,2 @@
1
+ languages:
2
+ Ruby: true
@@ -1,8 +1,29 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
+ AllCops:
4
+ Exclude:
5
+ - bin/**/*
6
+
3
7
  Style/StringLiterals:
4
8
  Enabled: false
5
9
 
6
10
  AllCops:
7
11
  Exclude:
8
12
  - bin/**/*
13
+
14
+ Metrics/LineLength:
15
+ Max: 120
16
+
17
+ Metrics/MethodLength:
18
+ Max: 21
19
+
20
+ Style/AlignParameters:
21
+ EnforcedStyle: with_fixed_indentation
22
+
23
+ Style/HashSyntax:
24
+ Enabled: false
25
+
26
+ Style/PercentLiteralDelimiters:
27
+ PreferredDelimiters:
28
+ '%w': '[]'
29
+ '%W': '[]'
@@ -5,168 +5,15 @@
5
5
  # Note that changes in the inspected code, or installation of new
6
6
  # versions of RuboCop, may require this file to be generated again.
7
7
 
8
- # Offense count: 11
9
- # Cop supports --auto-correct.
10
- Lint/UnusedBlockArgument:
11
- Enabled: false
12
-
13
- # Offense count: 12
14
- Lint/UselessAssignment:
15
- Enabled: false
16
-
17
- # Offense count: 6
18
- Metrics/AbcSize:
19
- Max: 27
20
-
21
- # Offense count: 347
22
- # Configuration parameters: AllowURI, URISchemes.
23
- Metrics/LineLength:
24
- Max: 304
25
-
26
- # Offense count: 9
27
- # Configuration parameters: CountComments.
28
- Metrics/MethodLength:
29
- Max: 21
30
-
31
- # Offense count: 1
32
- # Cop supports --auto-correct.
33
- Style/Alias:
34
- Enabled: false
35
-
36
- # Offense count: 3
37
- # Cop supports --auto-correct.
38
- # Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
39
- Style/AlignHash:
40
- Enabled: false
41
-
42
- # Offense count: 42
43
- # Cop supports --auto-correct.
44
- # Configuration parameters: EnforcedStyle, SupportedStyles.
45
- Style/AlignParameters:
46
- Enabled: false
47
-
48
- # Offense count: 14
49
- # Cop supports --auto-correct.
50
- # Configuration parameters: EnforcedStyle, SupportedStyles.
51
- Style/BarePercentLiterals:
52
- Enabled: false
53
-
54
- # Offense count: 1
55
- # Cop supports --auto-correct.
56
- Style/BlockEndNewline:
57
- Enabled: false
58
-
59
- # Offense count: 14
60
- # Cop supports --auto-correct.
61
- Style/BlockDelimiters:
62
- Enabled: false
63
-
64
- # Offense count: 1
65
- # Cop supports --auto-correct.
66
- # Configuration parameters: EnforcedStyle, SupportedStyles.
67
- Style/BracesAroundHashParameters:
68
- Enabled: false
69
-
70
8
  # Offense count: 27
71
9
  Style/Documentation:
72
10
  Enabled: false
73
11
 
74
- # Offense count: 5
75
- # Cop supports --auto-correct.
76
- # Configuration parameters: EnforcedStyle, SupportedStyles.
77
- Style/DotPosition:
78
- Enabled: false
79
-
80
- # Offense count: 1
81
- # Cop supports --auto-correct.
82
- Style/ElseAlignment:
83
- Enabled: false
84
-
85
- # Offense count: 1
86
- # Cop supports --auto-correct.
87
- Style/EmptyLines:
88
- Enabled: false
89
-
90
- # Offense count: 6
91
- # Cop supports --auto-correct.
92
- # Configuration parameters: EnforcedStyle, SupportedStyles.
93
- Style/EmptyLinesAroundBlockBody:
94
- Enabled: false
95
-
96
- # Offense count: 2
97
- # Cop supports --auto-correct.
98
- # Configuration parameters: EnforcedStyle, SupportedStyles.
99
- Style/EmptyLinesAroundClassBody:
100
- Enabled: false
101
-
102
- # Offense count: 1
103
- # Cop supports --auto-correct.
104
- # Configuration parameters: EnforcedStyle, SupportedStyles.
105
- Style/EmptyLinesAroundModuleBody:
106
- Enabled: false
107
-
108
- # Offense count: 2
109
- # Configuration parameters: MinBodyLength.
110
- Style/GuardClause:
111
- Enabled: false
112
-
113
- # Offense count: 521
114
- # Cop supports --auto-correct.
115
- # Configuration parameters: EnforcedStyle, SupportedStyles.
116
- Style/HashSyntax:
117
- Enabled: false
118
-
119
- # Offense count: 1
120
- # Configuration parameters: MaxLineLength.
121
- Style/IfUnlessModifier:
122
- Enabled: false
123
-
124
- # Offense count: 23
125
- # Cop supports --auto-correct.
126
- Style/IndentArray:
127
- Enabled: false
128
-
129
- # Offense count: 1
130
- # Cop supports --auto-correct.
131
- Style/IndentationConsistency:
132
- Enabled: false
133
-
134
- # Offense count: 3
135
- # Cop supports --auto-correct.
136
- # Configuration parameters: Width.
137
- Style/IndentationWidth:
138
- Enabled: false
139
-
140
- # Offense count: 10
141
- Style/Lambda:
142
- Enabled: false
143
-
144
- # Offense count: 1
145
- # Cop supports --auto-correct.
146
- # Configuration parameters: EnforcedStyle, SupportedStyles.
147
- Style/MethodDefParentheses:
148
- Enabled: false
149
-
150
- # Offense count: 2
151
- Style/MultilineBlockChain:
152
- Enabled: false
153
-
154
- # Offense count: 1
155
- # Cop supports --auto-correct.
156
- Style/MultilineBlockLayout:
157
- Enabled: false
158
-
159
12
  # Offense count: 16
160
13
  # Cop supports --auto-correct.
161
14
  Style/NumericLiterals:
162
15
  MinDigits: 6
163
16
 
164
- # Offense count: 12
165
- # Cop supports --auto-correct.
166
- # Configuration parameters: PreferredDelimiters.
167
- Style/PercentLiteralDelimiters:
168
- Enabled: false
169
-
170
17
  # Offense count: 2
171
18
  # Cop supports --auto-correct.
172
19
  # Configuration parameters: EnforcedStyle, SupportedStyles.
@@ -7,6 +7,7 @@ rvm:
7
7
  - "2.1"
8
8
  - "2.2"
9
9
  - jruby-19mode
10
+ - jruby-9.0.0.0
10
11
 
11
12
  env:
12
13
  - ACTIVE_RECORD_BRANCH="master"
@@ -21,7 +22,6 @@ env:
21
22
 
22
23
  matrix:
23
24
  allow_failures:
24
- - rvm: jruby-19mode
25
25
  - env: ACTIVE_RECORD_BRANCH="master"
26
26
  - env: ACTIVE_RECORD_BRANCH="4-2-stable"
27
27
  - env: ACTIVE_RECORD_BRANCH="4-1-stable"
@@ -35,8 +35,14 @@ matrix:
35
35
  env: ACTIVE_RECORD_BRANCH="master"
36
36
  - rvm: jruby-19mode
37
37
  env: ACTIVE_RECORD_BRANCH="master"
38
+ - rvm: jruby-9.0.0.0
39
+ env: ACTIVE_RECORD_BRANCH="master"
38
40
 
39
41
  before_script:
40
42
  - "psql -c 'create database pg_search_test;' -U postgres >/dev/null"
41
43
 
42
44
  script: "bin/rake"
45
+
46
+ addons:
47
+ code_climate:
48
+ repo_token: 0a0e3e45118bc447e677d52c21d056a5471c4921d54f96ed7b2550d9fc5043ea
@@ -1,5 +1,10 @@
1
1
  # pg_search changelog
2
2
 
3
+ ## 1.0.5
4
+
5
+ * Clean up rank table aliasing (Adam Milligan)
6
+ * Fix issue when using `#with_pg_search_rank` across a join (Reid Lynch)
7
+
3
8
  ## 1.0.4
4
9
 
5
10
  * Assert valid options for features. (Janko Marohnić)
data/Gemfile CHANGED
@@ -10,9 +10,7 @@ if ENV['ACTIVE_RECORD_BRANCH']
10
10
  gem 'arel', :git => 'https://github.com/rails/arel.git' if ENV['ACTIVE_RECORD_BRANCH'] == 'master'
11
11
  end
12
12
 
13
- if ENV['ACTIVE_RECORD_VERSION']
14
- gem 'activerecord', ENV['ACTIVE_RECORD_VERSION']
15
- end
13
+ gem 'activerecord', ENV['ACTIVE_RECORD_VERSION'] if ENV['ACTIVE_RECORD_VERSION']
16
14
 
17
15
  group :development do
18
16
  gem 'guard-rspec', :require => false
@@ -20,3 +18,7 @@ group :development do
20
18
  gem 'rb-fsevent', :require => false
21
19
  gem 'rb-fchange', :require => false
22
20
  end
21
+
22
+ group :test do
23
+ gem "codeclimate-test-reporter", require: nil
24
+ end
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # [pg_search](http://github.com/Casecommons/pg_search/)
2
2
 
3
+ [![Gem Version](https://img.shields.io/gem/v/pg_search.svg?style=flat)](https://rubygems.org/gems/pg_search)
3
4
  [![Build Status](https://secure.travis-ci.org/Casecommons/pg_search.svg?branch=master)](https://travis-ci.org/Casecommons/pg_search)
4
5
  [![Code Climate](https://img.shields.io/codeclimate/github/Casecommons/pg_search.svg?style=flat)](https://codeclimate.com/github/Casecommons/pg_search)
5
- [![Gem Version](https://img.shields.io/gem/v/pg_search.svg?style=flat)](https://rubygems.org/gems/pg_search)
6
+ [![Test Coverage](https://codeclimate.com/github/Casecommons/pg_search/badges/coverage.svg)](https://codeclimate.com/github/Casecommons/pg_search/coverage)
6
7
  [![Dependency Status](https://img.shields.io/gemnasium/Casecommons/pg_search.svg?style=flat)](https://gemnasium.com/Casecommons/pg_search)
7
8
  [![Inline docs](http://inch-ci.org/github/Casecommons/pg_search.svg?branch=master&style=flat)](http://inch-ci.org/github/Casecommons/pg_search)
8
9
  [![Join the chat at https://gitter.im/Casecommons/pg_search](https://img.shields.io/badge/gitter-join%20chat-blue.svg)](https://gitter.im/Casecommons/pg_search?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
@@ -12,7 +13,7 @@
12
13
  PgSearch builds named scopes that take advantage of PostgreSQL's full text
13
14
  search.
14
15
 
15
- Read the blog post introducing PgSearch at http://pivotallabs.com/pg-search/
16
+ Read the blog post introducing PgSearch at http://blog.pivotal.io/labs/labs/pg-search
16
17
 
17
18
  ## REQUIREMENTS
18
19
 
@@ -1038,21 +1039,38 @@ descending by updated_at, to rank the most recently updated records first.
1038
1039
  pg_search_scope :search_and_break_ties_by_latest_update,
1039
1040
  :against => [:title, :content],
1040
1041
  :order_within_rank => "blog_posts.updated_at DESC"
1041
- ````
1042
+ ```
1042
1043
 
1043
1044
  #### PgSearch#pg_search_rank (Reading a record's rank as a Float)
1044
1045
 
1045
1046
  It may be useful or interesting to see the rank of a particular record. This
1046
1047
  can be helpful for debugging why one record outranks another. You could also
1047
1048
  use it to show some sort of relevancy value to end users of an application.
1048
- Just call .pg_search_rank on a record returned by a pg_search_scope.
1049
+
1050
+ To retrieve the rank, call `.with_pg_search_rank` on a scope, and then call
1051
+ `.pg_search_rank` on a returned record.
1049
1052
 
1050
1053
  ```ruby
1051
- shirt_brands = ShirtBrand.search_by_name("Penguin")
1054
+ shirt_brands = ShirtBrand.search_by_name("Penguin").with_pg_search_rank
1052
1055
  shirt_brands[0].pg_search_rank #=> 0.0759909
1053
1056
  shirt_brands[1].pg_search_rank #=> 0.0607927
1054
1057
  ```
1055
1058
 
1059
+ #### Search rank and chained scopes
1060
+
1061
+ Each PgSearch scope generates a named subquery for the search rank. If you
1062
+ chain multiple scopes then PgSearch will generate a ranking query for each
1063
+ scope, so the ranking queries must have unique names. If you need to reference
1064
+ the ranking query (e.g. in a GROUP BY clause) you can regenerate the subquery
1065
+ name with the `PgScope::Configuration.alias` method by passing the name of the
1066
+ queried table.
1067
+
1068
+ ```ruby
1069
+ shirt_brands = ShirtBrand.search_by_name("Penguin")
1070
+ .joins(:shirt_sizes)
1071
+ .group_by('shirt_brands.id, #{PgSearch::Configuration.alias('shirt_brands')}.rank')
1072
+ ```
1073
+
1056
1074
  ## ATTRIBUTIONS
1057
1075
 
1058
1076
  PgSearch would not have been possible without inspiration from texticle (now renamed
@@ -30,20 +30,14 @@ module PgSearch
30
30
  unless options.respond_to?(:merge)
31
31
  raise ArgumentError, "pg_search_scope expects a Hash or Proc"
32
32
  end
33
- lambda { |query| {:query => query}.merge(options) }
33
+ ->(query) { {:query => query}.merge(options) }
34
34
  end
35
35
 
36
- method_proc = lambda do |*args|
36
+ define_singleton_method(name) do |*args|
37
37
  config = Configuration.new(options_proc.call(*args), self)
38
38
  scope_options = ScopeOptions.new(config)
39
39
  scope_options.apply(self)
40
40
  end
41
-
42
- if respond_to?(:define_singleton_method)
43
- define_singleton_method name, &method_proc
44
- else
45
- (class << self; self; end).send :define_method, name, &method_proc
46
- end
47
41
  end
48
42
 
49
43
  def multisearchable(options = {})
@@ -93,10 +87,10 @@ module PgSearch
93
87
  end
94
88
  end
95
89
 
96
-
97
90
  class NotSupportedForPostgresqlVersion < StandardError; end
98
91
 
99
92
  class PgSearchRankNotSelected < StandardError
93
+ # rubocop:disable Metrics/LineLength
100
94
  def message
101
95
  "You must chain .with_pg_search_rank after the pg_search_scope to access the pg_search_rank attribute on returned records"
102
96
  end
@@ -4,7 +4,6 @@ require "pg_search/configuration/foreign_column"
4
4
 
5
5
  module PgSearch
6
6
  class Configuration
7
-
8
7
  attr_reader :model
9
8
 
10
9
  def initialize(options, model)
@@ -8,7 +8,7 @@ module PgSearch
8
8
  belongs_to :searchable, :polymorphic => true
9
9
 
10
10
  before_validation :update_content,
11
- :unless => Proc.new { |doc| doc.searchable.nil? }
11
+ :unless => Proc.new { |doc| doc.searchable.nil? }
12
12
 
13
13
  # The logger might not have loaded yet.
14
14
  # https://github.com/Casecommons/pg_search/issues/26
@@ -4,7 +4,7 @@ require "arel/visitors/depth_first"
4
4
  # Based on the solution from https://github.com/ernie/squeel/issues/122
5
5
  Arel::Visitors::DepthFirst.class_eval do
6
6
  unless method_defined?(:visit_Arel_Nodes_InfixOperation)
7
- alias :visit_Arel_Nodes_InfixOperation :binary
7
+ alias_method :visit_Arel_Nodes_InfixOperation, :binary
8
8
  end
9
9
  end
10
10
 
@@ -11,7 +11,7 @@ module PgSearch
11
11
  def initialize(*args)
12
12
  super
13
13
 
14
- if options[:prefix] && model.connection.send(:postgresql_version) < 80400
14
+ if options[:prefix] && model.connection.send(:postgresql_version) < 80400 # rubocop:disable Style/GuardClause
15
15
  raise PgSearch::NotSupportedForPostgresqlVersion.new(<<-MESSAGE.strip_heredoc)
16
16
  Sorry, {:using => {:tsearch => {:prefix => true}}} only works in PostgreSQL 8.4 and above.")
17
17
  MESSAGE
@@ -32,7 +32,7 @@ module PgSearch
32
32
 
33
33
  DISALLOWED_TSQUERY_CHARACTERS = /['?\\:]/
34
34
 
35
- def tsquery_for_term(unsanitized_term)
35
+ def tsquery_for_term(unsanitized_term) # rubocop:disable Metrics/AbcSize
36
36
  if options[:negation] && unsanitized_term.start_with?("!")
37
37
  unsanitized_term[0] = ''
38
38
  negated = true
@@ -2,7 +2,6 @@ require "pg_search/multisearch/rebuilder"
2
2
 
3
3
  module PgSearch
4
4
  module Multisearch
5
-
6
5
  class << self
7
6
  def rebuild(model, clean_up=true)
8
7
  model.transaction do
@@ -42,7 +42,7 @@ module PgSearch
42
42
  end
43
43
 
44
44
  def rebuild_sql_template
45
- <<-SQL.strip_heredoc
45
+ <<-SQL.strip_heredoc
46
46
  INSERT INTO :documents_table (searchable_type, searchable_id, content, created_at, updated_at)
47
47
  SELECT :base_model_name AS searchable_type,
48
48
  :model_table.#{primary_key} AS searchable_id,
@@ -78,9 +78,7 @@ module PgSearch
78
78
  end
79
79
 
80
80
  def content_expressions
81
- columns.map { |column|
82
- %Q{coalesce(:model_table.#{column}::text, '')}
83
- }.join(" || ' ' || ")
81
+ columns.map { |column| %{coalesce(:model_table.#{column}::text, '')} }.join(" || ' ' || ")
84
82
  end
85
83
 
86
84
  def columns