pg_search 0.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1 +1,81 @@
1
- rvm use ree@pg_search
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ree-1.8.7-2011.12@pg_search"
8
+
9
+ #
10
+ # Uncomment the following lines if you want to verify rvm version per project
11
+ #
12
+ # rvmrc_rvm_version="1.10.2" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+ #
18
+
19
+ #
20
+ # Uncomment following line if you want options to be set only for given project.
21
+ #
22
+ # PROJECT_JRUBY_OPTS=( --1.9 )
23
+ #
24
+ # The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
25
+ #
26
+ # chmod +x ${rvm_path}/hooks/after_use_jruby_opts
27
+ #
28
+
29
+ #
30
+ # First we attempt to load the desired environment directly from the environment
31
+ # file. This is very fast and efficient compared to running through the entire
32
+ # CLI and selector. If you want feedback on which environment was used then
33
+ # insert the word 'use' after --create as this triggers verbose mode.
34
+ #
35
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
36
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
37
+ then
38
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
39
+
40
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
41
+ then
42
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
43
+ fi
44
+ else
45
+ # If the environment file has not yet been created, use the RVM CLI to select.
46
+ if ! rvm --create use "$environment_id"
47
+ then
48
+ echo "Failed to create RVM environment '${environment_id}'."
49
+ return 1
50
+ fi
51
+ fi
52
+
53
+ #
54
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
55
+ # it be automatically loaded. Uncomment the following and adjust the filename if
56
+ # necessary.
57
+ #
58
+ # filename=".gems"
59
+ # if [[ -s "$filename" ]]
60
+ # then
61
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
62
+ # fi
63
+
64
+ # If you use bundler, this might be useful to you:
65
+ # if [[ -s Gemfile ]] && ! command -v bundle >/dev/null
66
+ # then
67
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
68
+ # gem install bundler
69
+ # fi
70
+ # if [[ -s Gemfile ]] && command -v bundle
71
+ # then
72
+ # bundle install
73
+ # fi
74
+
75
+ if [[ $- == *i* ]] # check for interactive shells
76
+ then
77
+ echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
78
+ else
79
+ echo "Using: $GEM_HOME" # don't use colors in interactive shells
80
+ fi
81
+
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,11 @@
1
1
  = PgSearch
2
2
 
3
+ == 0.4.1
4
+
5
+ * Fix Active Record 3.2 deprecation warnings. (Steven Harman)
6
+
7
+ * Fix issue with undefined logger when PgSearch::Document.search is already defined.
8
+
3
9
  == 0.4
4
10
 
5
11
  * Add ability to search again tsvector columns. (Kris Hicks)
@@ -42,6 +48,10 @@
42
48
 
43
49
  * Add :any_word option to :tsearch which uses OR between query terms instead of AND. (Fernando Espinosa)
44
50
 
51
+ == 0.2.1
52
+
53
+ * Backport support for searching against tsvector columns (Kris Hicks)
54
+
45
55
  == 0.2
46
56
 
47
57
  * Set dictionary to :simple by default for :tsearch. Before it was unset,
data/Gemfile CHANGED
@@ -8,3 +8,5 @@ gem "pg"
8
8
  gem "rspec", ">=2.4"
9
9
  gem "autotest"
10
10
  gem "with_model"
11
+
12
+ gem "activerecord", "~> #{ENV["ACTIVE_RECORD_VERSION"]}.0" if ENV["ACTIVE_RECORD_VERSION"]
data/README.rdoc CHANGED
@@ -18,6 +18,12 @@ In Gemfile
18
18
 
19
19
  gem 'pg_search'
20
20
 
21
+ === Rails 2
22
+
23
+ The newest versions of PgSearch no longer support Rails 2. However, the 0.2 series still works. It's not actively maintained, but submissions are welcome for backports and bugfixes.
24
+
25
+ The 0.2 branch lives at https://github.com/Casecommons/pg_search/tree/0.2-stable
26
+
21
27
  === Other ActiveRecord-based projects
22
28
 
23
29
  In addition to installing and requiring the gem, you may want to include the PgSearch rake tasks in your Rakefile:
@@ -95,9 +101,9 @@ PgSearch.multisearch returns an ActiveRecord::Relation, just like scopes do, so
95
101
 
96
102
  ==== Configuring multi-search
97
103
 
98
- PgSearch.multisearch can be configured using the same options as `pg_search_scope` (explained in more detail below). Just set the PgSearch.multisearchable_options in an initializer:
104
+ PgSearch.multisearch can be configured using the same options as `pg_search_scope` (explained in more detail below). Just set the PgSearch.multisearch_options in an initializer:
99
105
 
100
- PgSearch.multisearchable_options = {
106
+ PgSearch.multisearch_options = {
101
107
  :using => [:tsearch, :trigram],
102
108
  :ignoring => :accents
103
109
  }
data/lib/pg_search.rb CHANGED
@@ -23,10 +23,8 @@ module PgSearch
23
23
  end
24
24
  end
25
25
 
26
- module InstanceMethods
27
- def rank
28
- attributes['pg_search_rank'].to_f
29
- end
26
+ def rank
27
+ attributes['pg_search_rank'].to_f
30
28
  end
31
29
 
32
30
  class << self
@@ -1,18 +1,25 @@
1
+ require "logger"
1
2
  require "pg_search/scope"
2
3
 
3
4
  module PgSearch
4
5
  class Document < ActiveRecord::Base
5
6
  include PgSearch
6
- set_table_name :pg_search_documents
7
+ self.table_name = 'pg_search_documents'
7
8
  belongs_to :searchable, :polymorphic => true
8
9
 
9
10
  before_validation :update_content
10
11
 
12
+ # The logger might not have loaded yet.
13
+ # https://github.com/Casecommons/pg_search/issues/26
14
+ def self.logger
15
+ super || Logger.new(STDERR)
16
+ end
17
+
11
18
  pg_search_scope :search, lambda { |*args|
12
- if PgSearch.multisearch_options.respond_to?(:call)
13
- options = PgSearch.multisearch_options.call(*args)
19
+ options = if PgSearch.multisearch_options.respond_to?(:call)
20
+ PgSearch.multisearch_options.call(*args)
14
21
  else
15
- options = PgSearch.multisearch_options.reverse_merge(:query => args.first)
22
+ PgSearch.multisearch_options.reverse_merge(:query => args.first)
16
23
  end
17
24
  options.reverse_merge(:against => :content)
18
25
  }
@@ -18,11 +18,9 @@ module PgSearch
18
18
  :if => lambda { PgSearch.multisearch_enabled? }
19
19
  end
20
20
 
21
- module InstanceMethods
22
- def update_pg_search_document
23
- create_pg_search_document unless self.pg_search_document
24
- self.pg_search_document.save
25
- end
21
+ def update_pg_search_document
22
+ create_pg_search_document unless self.pg_search_document
23
+ self.pg_search_document.save
26
24
  end
27
25
  end
28
26
  end
@@ -1,3 +1,3 @@
1
1
  module PgSearch
2
- VERSION = "0.4"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -292,4 +292,50 @@ describe PgSearch do
292
292
  end
293
293
  end
294
294
  end
295
+
296
+ context "merging a pg_search_scope into another model's scope" do
297
+ with_model :ModelWithAssociation do
298
+ model do
299
+ has_many :associated_models
300
+ end
301
+ end
302
+
303
+ with_model :AssociatedModel do
304
+ table do |t|
305
+ t.string :content
306
+ t.belongs_to :model_with_association
307
+ end
308
+
309
+ model do
310
+ include PgSearch
311
+ belongs_to :model_with_association
312
+
313
+ pg_search_scope :search_content, :against => :content
314
+ end
315
+ end
316
+
317
+ it "should find records of the other model" do
318
+ included_associated_1 = AssociatedModel.create(:content => "foo bar")
319
+ included_associated_2 = AssociatedModel.create(:content => "foo baz")
320
+ excluded_associated_1 = AssociatedModel.create(:content => "baz quux")
321
+ excluded_associated_2 = AssociatedModel.create(:content => "baz bar")
322
+
323
+ included = [
324
+ ModelWithAssociation.create(:associated_models => [included_associated_1]),
325
+ ModelWithAssociation.create(:associated_models => [included_associated_2, excluded_associated_1])
326
+ ]
327
+
328
+ excluded = [
329
+ ModelWithAssociation.create(:associated_models => [excluded_associated_2]),
330
+ ModelWithAssociation.create(:associated_models => [])
331
+ ]
332
+
333
+ relation = AssociatedModel.search_content("foo")
334
+
335
+ results = ModelWithAssociation.joins(:associated_models).merge(relation)
336
+
337
+ results.should include(*included)
338
+ results.should_not include(*excluded)
339
+ end
340
+ end
295
341
  end
data/spec/spec_helper.rb CHANGED
@@ -26,6 +26,7 @@ end
26
26
 
27
27
  def install_extension_if_missing(name, query, expected_result)
28
28
  connection = ActiveRecord::Base.connection
29
+ postgresql_version = connection.send(:postgresql_version)
29
30
  result = connection.select_value(query)
30
31
  raise "Unexpected output for #{query}: #{result.inspect}" unless result.downcase == expected_result.downcase
31
32
  rescue => e
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_search
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-15 00:00:00.000000000 Z
12
+ date: 2012-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &70335492023760 !ruby/object:Gem::Requirement
16
+ requirement: &70164267785940 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70335492023760
24
+ version_requirements: *70164267785940
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &70335492023220 !ruby/object:Gem::Requirement
27
+ requirement: &70164267784280 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '3'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70335492023220
35
+ version_requirements: *70164267784280
36
36
  description: PgSearch builds ActiveRecord named scopes that take advantage of PostgreSQL's
37
37
  full text search
38
38
  email: