phat_pgsearch 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -2
- data/VERSION +1 -1
- data/lib/phat_pgsearch.rb +1 -0
- data/lib/phat_pgsearch/active_record.rb +11 -0
- data/lib/phat_pgsearch/index_builder.rb +2 -2
- data/lib/phat_pgsearch/postgresql.rb +17 -0
- data/phat_pgsearch.gemspec +1 -1
- data/spec/support/active_record.rb +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -66,7 +66,7 @@ add to Gemfile
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def comment_texts
|
69
|
-
sample_comments.collect{ |comment| comment.comment }.join('')
|
69
|
+
sample_comments.collect{ |comment| comment.comment }.join(' ')
|
70
70
|
end
|
71
71
|
|
72
72
|
end
|
@@ -85,7 +85,7 @@ add to Gemfile
|
|
85
85
|
|
86
86
|
# disable auto sorting and use own select and sorting
|
87
87
|
SampleItem.pgsearch(:tsv_full, 'test test2', :rank => false).
|
88
|
-
select("sample_items.*, #{SampleItem.pgsearch_query(:tsv_full, 'test test2')} AS rank").
|
88
|
+
select("sample_items.*, ts_rank_cd('german', #{SampleItem.pgsearch_query(:tsv_full, 'test test2')}, 32) AS rank").
|
89
89
|
order(:rank)
|
90
90
|
|
91
91
|
== Requirements
|
@@ -93,6 +93,11 @@ add to Gemfile
|
|
93
93
|
* Rails 3 (http://github.com/rails/rails)
|
94
94
|
* PostgreSQL
|
95
95
|
|
96
|
+
|
97
|
+
= Todo / Problem
|
98
|
+
|
99
|
+
* Missing support for SchemaDumper (at the moment use config.active_record.schema_format = :sql)
|
100
|
+
|
96
101
|
== Test environments
|
97
102
|
|
98
103
|
* ruby-1.9.2 (work)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/phat_pgsearch.rb
CHANGED
@@ -21,6 +21,7 @@ module PhatPgsearch
|
|
21
21
|
::ActiveRecord::ConnectionAdapters::TableDefinition.send(:include, PostgreSQL::TableDefinition)
|
22
22
|
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:include, PostgreSQL::SchemaStatements)
|
23
23
|
::ActiveRecord::ConnectionAdapters::PostgreSQLColumn.send(:include, PostgreSQL::PostgreSQLColumn)
|
24
|
+
::ActiveRecord::SchemaDumper.send(:include, PostgreSQL::SchemaDumper)
|
24
25
|
::ActiveRecord::Base.send(:include, ActiveRecord)
|
25
26
|
end
|
26
27
|
end
|
@@ -83,6 +83,17 @@ module PhatPgsearch
|
|
83
83
|
|
84
84
|
module InstanceMethods #:nodoc:
|
85
85
|
|
86
|
+
|
87
|
+
def rebuild_pgindex!
|
88
|
+
last_state = self.class.record_timestamps
|
89
|
+
self.class.record_timestamps = false
|
90
|
+
self.build_pgsearch_index
|
91
|
+
self.save!
|
92
|
+
self.class.record_timestamps = last_state
|
93
|
+
end
|
94
|
+
|
95
|
+
protected
|
96
|
+
|
86
97
|
def build_pgsearch_index
|
87
98
|
self.class.pgsearch_definitions.each_pair do |index_field, index_definition|
|
88
99
|
IndexBuilder.new(self, index_definition)
|
@@ -18,9 +18,9 @@ module PhatPgsearch
|
|
18
18
|
field_options = field_definition.extract_options!
|
19
19
|
field_content = base.respond_to?(field) ? base.send(field.to_s) : ''
|
20
20
|
if not field_options[:weight].nil? and [:a, :b, :c, :d].include? field_options[:weight].to_sym
|
21
|
-
partial = "setweight(to_tsvector(#{base.class.sanitize(definition.catalog)}, #{base.class.sanitize(field_content)}), '#{field_options[:weight].to_s.upcase}')"
|
21
|
+
partial = "setweight(to_tsvector(#{base.class.sanitize(definition.catalog)}, #{base.class.sanitize(field_content.to_s)}), '#{field_options[:weight].to_s.upcase}')"
|
22
22
|
else
|
23
|
-
partial = "to_tsvector(#{base.class.sanitize(definition.catalog)}, #{base.class.sanitize(field_content)})"
|
23
|
+
partial = "to_tsvector(#{base.class.sanitize(definition.catalog)}, #{base.class.sanitize(field_content.to_s)})"
|
24
24
|
end
|
25
25
|
partials << partial
|
26
26
|
end
|
@@ -1,5 +1,18 @@
|
|
1
1
|
module PhatPgsearch
|
2
2
|
module PostgreSQL
|
3
|
+
class IndexDefinition < Struct.new(:table, :name, :type, :column) #:nodoc:
|
4
|
+
end
|
5
|
+
|
6
|
+
module SchemaDumper
|
7
|
+
def self.included(base)
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
def indexes
|
12
|
+
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
3
16
|
|
4
17
|
module SchemaStatements
|
5
18
|
|
@@ -17,6 +30,10 @@ module PhatPgsearch
|
|
17
30
|
end
|
18
31
|
|
19
32
|
module PostgreSQLColumn
|
33
|
+
def pgsearch_index(table)
|
34
|
+
|
35
|
+
end
|
36
|
+
|
20
37
|
def simplified_type(field_type)
|
21
38
|
if field_type == 'tsvector'
|
22
39
|
:string
|
data/phat_pgsearch.gemspec
CHANGED
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.4
|
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: -884935242917167268
|
136
136
|
segments:
|
137
137
|
- 0
|
138
138
|
version: "0"
|