pg_search 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +5 -0
- data/.gitignore +7 -0
- data/.rvmrc +1 -0
- data/CHANGELOG +7 -0
- data/Gemfile +5 -0
- data/LICENSE +19 -0
- data/README.rdoc +290 -0
- data/Rakefile +35 -0
- data/TODO +12 -0
- data/gemfiles/Gemfile.common +9 -0
- data/gemfiles/rails2/Gemfile +4 -0
- data/gemfiles/rails3/Gemfile +4 -0
- data/lib/pg_search.rb +32 -0
- data/lib/pg_search/configuration.rb +73 -0
- data/lib/pg_search/configuration/column.rb +43 -0
- data/lib/pg_search/features.rb +7 -0
- data/lib/pg_search/features/dmetaphone.rb +28 -0
- data/lib/pg_search/features/trigram.rb +29 -0
- data/lib/pg_search/features/tsearch.rb +64 -0
- data/lib/pg_search/normalizer.rb +13 -0
- data/lib/pg_search/railtie.rb +11 -0
- data/lib/pg_search/scope.rb +31 -0
- data/lib/pg_search/scope_options.rb +75 -0
- data/lib/pg_search/tasks.rb +37 -0
- data/lib/pg_search/version.rb +3 -0
- data/pg_search.gemspec +19 -0
- data/script/setup-contrib +12 -0
- data/spec/associations_spec.rb +225 -0
- data/spec/pg_search_spec.rb +596 -0
- data/spec/spec_helper.rb +92 -0
- data/sql/dmetaphone.sql +4 -0
- data/sql/uninstall_dmetaphone.sql +1 -0
- metadata +103 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "pg_search"
|
3
|
+
|
4
|
+
begin
|
5
|
+
ActiveRecord::Base.establish_connection(:adapter => 'postgresql',
|
6
|
+
:database => 'pg_search_test',
|
7
|
+
:min_messages => 'warning')
|
8
|
+
connection = ActiveRecord::Base.connection
|
9
|
+
connection.execute("SELECT 1")
|
10
|
+
rescue PGError => e
|
11
|
+
puts "-" * 80
|
12
|
+
puts "Unable to connect to database. Please run:"
|
13
|
+
puts
|
14
|
+
puts " createdb pg_search_test"
|
15
|
+
puts "-" * 80
|
16
|
+
raise e
|
17
|
+
end
|
18
|
+
|
19
|
+
def install_contrib_module_if_missing(name, query, expected_result)
|
20
|
+
connection = ActiveRecord::Base.connection
|
21
|
+
result = connection.select_value(query)
|
22
|
+
raise "Unexpected output for #{query}: #{result.inspect}" unless result.downcase == expected_result.downcase
|
23
|
+
rescue => e
|
24
|
+
begin
|
25
|
+
share_path = `pg_config --sharedir`.strip
|
26
|
+
ActiveRecord::Base.connection.execute File.read(File.join(share_path, 'contrib', "#{name}.sql"))
|
27
|
+
puts $!.message
|
28
|
+
rescue
|
29
|
+
puts "-" * 80
|
30
|
+
puts "Please install the #{name} contrib module"
|
31
|
+
puts "-" * 80
|
32
|
+
raise e
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
install_contrib_module_if_missing("pg_trgm", "SELECT 'abcdef' % 'cdef'", "t")
|
37
|
+
install_contrib_module_if_missing("unaccent", "SELECT unaccent('foo')", "foo")
|
38
|
+
install_contrib_module_if_missing("fuzzystrmatch", "SELECT dmetaphone('foo')", "f")
|
39
|
+
|
40
|
+
ActiveRecord::Base.connection.execute(File.read(File.join(File.dirname(__FILE__), '..', 'sql', 'dmetaphone.sql')))
|
41
|
+
|
42
|
+
require "with_model"
|
43
|
+
|
44
|
+
RSpec.configure do |config|
|
45
|
+
config.extend WithModel
|
46
|
+
end
|
47
|
+
|
48
|
+
if defined?(ActiveRecord::Relation)
|
49
|
+
RSpec::Matchers::OperatorMatcher.register(ActiveRecord::Relation, '=~', RSpec::Matchers::MatchArray)
|
50
|
+
end
|
51
|
+
|
52
|
+
require 'irb'
|
53
|
+
|
54
|
+
class IRB::Irb
|
55
|
+
alias initialize_orig initialize
|
56
|
+
def initialize(workspace = nil, *args)
|
57
|
+
default = IRB.conf[:DEFAULT_OBJECT]
|
58
|
+
workspace ||= IRB::WorkSpace.new default if default
|
59
|
+
initialize_orig(workspace, *args)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Drop into an IRB session for whatever object you pass in:
|
64
|
+
#
|
65
|
+
# class Dude
|
66
|
+
# def abides
|
67
|
+
# true
|
68
|
+
# end
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# console_for(Dude.new)
|
72
|
+
#
|
73
|
+
# Then type "quit" or "exit" to get out. In a step definition, it should look like:
|
74
|
+
#
|
75
|
+
# When /^I console/ do
|
76
|
+
# console_for(self)
|
77
|
+
# end
|
78
|
+
#
|
79
|
+
# Also, I definitely stole this hack from some mailing list post somewhere. I wish I
|
80
|
+
# could remember who did it, but I can't. Sorry!
|
81
|
+
def console_for(target)
|
82
|
+
puts "== ENTERING CONSOLE MODE. ==\nType 'exit' to move on.\nContext: #{target.inspect}"
|
83
|
+
|
84
|
+
begin
|
85
|
+
oldargs = ARGV.dup
|
86
|
+
ARGV.clear
|
87
|
+
IRB.conf[:DEFAULT_OBJECT] = target
|
88
|
+
IRB.start
|
89
|
+
ensure
|
90
|
+
ARGV.replace(oldargs)
|
91
|
+
end
|
92
|
+
end
|
data/sql/dmetaphone.sql
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
DROP FUNCTION pg_search_dmetaphone(text);
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pg_search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Case Commons, LLC
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-14 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: PgSearch builds ActiveRecord named scopes that take advantage of PostgreSQL's full text search
|
23
|
+
email:
|
24
|
+
- casecommons-dev@googlegroups.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .autotest
|
33
|
+
- .gitignore
|
34
|
+
- .rvmrc
|
35
|
+
- CHANGELOG
|
36
|
+
- Gemfile
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- TODO
|
41
|
+
- gemfiles/Gemfile.common
|
42
|
+
- gemfiles/rails2/Gemfile
|
43
|
+
- gemfiles/rails2/Gemfile.lock
|
44
|
+
- gemfiles/rails3/Gemfile
|
45
|
+
- gemfiles/rails3/Gemfile.lock
|
46
|
+
- lib/pg_search.rb
|
47
|
+
- lib/pg_search/configuration.rb
|
48
|
+
- lib/pg_search/configuration/column.rb
|
49
|
+
- lib/pg_search/features.rb
|
50
|
+
- lib/pg_search/features/dmetaphone.rb
|
51
|
+
- lib/pg_search/features/trigram.rb
|
52
|
+
- lib/pg_search/features/tsearch.rb
|
53
|
+
- lib/pg_search/normalizer.rb
|
54
|
+
- lib/pg_search/railtie.rb
|
55
|
+
- lib/pg_search/scope.rb
|
56
|
+
- lib/pg_search/scope_options.rb
|
57
|
+
- lib/pg_search/tasks.rb
|
58
|
+
- lib/pg_search/version.rb
|
59
|
+
- pg_search.gemspec
|
60
|
+
- script/setup-contrib
|
61
|
+
- spec/associations_spec.rb
|
62
|
+
- spec/pg_search_spec.rb
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
- sql/dmetaphone.sql
|
65
|
+
- sql/uninstall_dmetaphone.sql
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: https://github.com/Casecommons/pg_search
|
68
|
+
licenses: []
|
69
|
+
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
hash: 3
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 3
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
requirements: []
|
94
|
+
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 1.3.7
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: PgSearch builds ActiveRecord named scopes that take advantage of PostgreSQL's full text search
|
100
|
+
test_files:
|
101
|
+
- spec/associations_spec.rb
|
102
|
+
- spec/pg_search_spec.rb
|
103
|
+
- spec/spec_helper.rb
|