phat_pgsearch 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/phat_pgsearch/active_record.rb +33 -6
- data/phat_pgsearch.gemspec +2 -2
- data/spec/active_record_spec.rb +16 -0
- metadata +3 -3
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.3
|
|
@@ -34,20 +34,47 @@ module PhatPgsearch
|
|
|
34
34
|
|
|
35
35
|
search_query = pgsearch_query(args.first, args.second, options)
|
|
36
36
|
|
|
37
|
+
if args.first.is_a? Symbol or args.first.to_s.split('.', 2) == 1
|
|
38
|
+
vector_column = "#{self.connection.quote_table_name(self.table_name)}.#{self.connection.quote_column_name(args.first.to_s)}"
|
|
39
|
+
else
|
|
40
|
+
vector_column = args.first.split('.', 2).collect{ |f| self.connection.quote_column_name(f) }.join('.')
|
|
41
|
+
end
|
|
42
|
+
|
|
37
43
|
if rank.nil? or rank == true
|
|
38
|
-
scope = scope.select("#{self.connection.quote_table_name(self.table_name)}.*, ts_rank_cd(#{
|
|
44
|
+
scope = scope.select("#{self.connection.quote_table_name(self.table_name)}.*, ts_rank_cd(#{vector_column}, #{search_query}, #{normalization.to_i}) AS rank")
|
|
39
45
|
end
|
|
40
46
|
|
|
41
|
-
scope.where("#{
|
|
47
|
+
scope.where("#{vector_column} @@ #{search_query}")
|
|
42
48
|
end
|
|
43
49
|
|
|
44
50
|
def pgsearch_query(*args)
|
|
45
51
|
options = args.extract_options!
|
|
46
|
-
raise ArgumentError, "invalid field given"
|
|
47
|
-
raise ArgumentError, "invalid query" if
|
|
52
|
+
raise ArgumentError, "invalid field given" if args.first.nil? or not (args.first.is_a? String or args.first.is_a? Symbol)
|
|
53
|
+
raise ArgumentError, "invalid query given" if args.second.nil? or not (args.second.is_a? String)
|
|
54
|
+
|
|
55
|
+
field = args.first.to_s.split(".", 2)
|
|
48
56
|
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
table_class = self
|
|
58
|
+
|
|
59
|
+
if field.count == 2
|
|
60
|
+
begin
|
|
61
|
+
table_class = field.first.classify.constantize
|
|
62
|
+
rescue
|
|
63
|
+
p field.first.classify
|
|
64
|
+
raise ArgumentError, "unknown table in field given"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
raise ArgumentError, "table has no index defined" unless table_class.respond_to? :pgsearch_definitions
|
|
69
|
+
raise ArgumentError, "table has no index defined for '#{field.last.to_sym}'" if table_class.pgsearch_definitions[field.last.to_sym].nil?
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
definition = table_class.pgsearch_definitions[field.last.to_sym]
|
|
73
|
+
if definition
|
|
74
|
+
catalog = options[:catalog] || definition.catalog
|
|
75
|
+
else
|
|
76
|
+
catalog = options[:catalog] || definition.catalog
|
|
77
|
+
end
|
|
51
78
|
|
|
52
79
|
"plainto_tsquery(#{self.sanitize(catalog)}, #{self.sanitize(args.second)})"
|
|
53
80
|
end
|
data/phat_pgsearch.gemspec
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{phat_pgsearch}
|
|
8
|
-
s.version = "0.1.
|
|
8
|
+
s.version = "0.1.3"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Marco Scholl"]
|
|
@@ -39,7 +39,7 @@ Gem::Specification.new do |s|
|
|
|
39
39
|
s.homepage = %q{http://github.com/phatworx/phat_pgsearch}
|
|
40
40
|
s.licenses = ["MIT"]
|
|
41
41
|
s.require_paths = ["lib"]
|
|
42
|
-
s.rubygems_version = %q{1.5.
|
|
42
|
+
s.rubygems_version = %q{1.5.0}
|
|
43
43
|
s.summary = %q{a postgresql based search plugin}
|
|
44
44
|
s.test_files = [
|
|
45
45
|
"spec/active_record_spec.rb",
|
data/spec/active_record_spec.rb
CHANGED
|
@@ -45,6 +45,22 @@ describe PhatPgsearch::ActiveRecord do
|
|
|
45
45
|
@sample_header.save
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
+
describe "#pgsearch with table-field in string" do
|
|
49
|
+
before { @pgsearch = SampleItem.pgsearch("sample_items.tsv", 'kommentar') }
|
|
50
|
+
subject { @pgsearch }
|
|
51
|
+
it "should do something" do
|
|
52
|
+
subject.to_a
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe "#pgsearch with field in string" do
|
|
57
|
+
before { @pgsearch = SampleItem.pgsearch("tsv", 'kommentar') }
|
|
58
|
+
subject { @pgsearch }
|
|
59
|
+
it "should do something" do
|
|
60
|
+
subject.to_a
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
48
64
|
describe SampleItem do
|
|
49
65
|
describe "#pgsearch :tsv, 'kommentar'" do
|
|
50
66
|
before { @pgsearch = SampleItem.pgsearch(:tsv, 'kommentar') }
|
metadata
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: phat_pgsearch
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 0.1.
|
|
5
|
+
version: 0.1.3
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- Marco Scholl
|
|
@@ -132,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
132
132
|
requirements:
|
|
133
133
|
- - ">="
|
|
134
134
|
- !ruby/object:Gem::Version
|
|
135
|
-
hash:
|
|
135
|
+
hash: -2944819788268572641
|
|
136
136
|
segments:
|
|
137
137
|
- 0
|
|
138
138
|
version: "0"
|
|
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
145
145
|
requirements: []
|
|
146
146
|
|
|
147
147
|
rubyforge_project:
|
|
148
|
-
rubygems_version: 1.5.
|
|
148
|
+
rubygems_version: 1.5.0
|
|
149
149
|
signing_key:
|
|
150
150
|
specification_version: 3
|
|
151
151
|
summary: a postgresql based search plugin
|