Commit 7ca3f1a7fd9ba97aa5f20da54efd717f7f4deaff
1 parent
03b3e7b1
Exists in
master
and in
28 other branches
Fixed pg_search index
Showing
3 changed files
with
17 additions
and
17 deletions
Show diff stats
plugins/pg_search/db/migrate/20130320010062_create_indexes_for_search.rb
@@ -1,16 +0,0 @@ | @@ -1,16 +0,0 @@ | ||
1 | -class CreateIndexesForSearch < ActiveRecord::Migration | ||
2 | - def self.up | ||
3 | - searchables = %w[ article comment qualifier national_region certifier profile license scrap category ] | ||
4 | - klasses = searchables.map {|searchable| searchable.camelize.constantize } | ||
5 | - klasses.each do |klass| | ||
6 | - fields = klass.pg_search_plugin_fields | ||
7 | - execute "create index pg_search_plugin_#{klass.name.singularize.downcase} on #{klass.table_name} using gin(to_tsvector('simple', #{fields}))" | ||
8 | - end | ||
9 | - end | ||
10 | - | ||
11 | - def self.down | ||
12 | - klasses.each do |klass| | ||
13 | - execute "drop index pg_search_plugin_#{klass.name.singularize.downcase}" | ||
14 | - end | ||
15 | - end | ||
16 | -end |
plugins/pg_search/db/migrate/20130320010063_create_indexes_for_search.rb
0 → 100644
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | +class CreateIndexesForSearch < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + searchables = %w[ article comment qualifier national_region certifier profile license scrap category ] | ||
4 | + klasses = searchables.map {|searchable| searchable.camelize.constantize } | ||
5 | + klasses.each do |klass| | ||
6 | + fields = klass.pg_search_plugin_fields | ||
7 | + execute "create index pg_search_plugin_#{klass.name.singularize.downcase} on #{klass.table_name} using gin(to_tsvector('simple', #{fields}))" | ||
8 | + end | ||
9 | + end | ||
10 | + | ||
11 | + def self.down | ||
12 | + klasses.each do |klass| | ||
13 | + execute "drop index pg_search_plugin_#{klass.name.singularize.downcase}" | ||
14 | + end | ||
15 | + end | ||
16 | +end |
plugins/pg_search/lib/ext/active_record.rb
@@ -10,6 +10,6 @@ class ActiveRecord::Base | @@ -10,6 +10,6 @@ class ActiveRecord::Base | ||
10 | end | 10 | end |
11 | 11 | ||
12 | def self.pg_search_plugin_fields | 12 | def self.pg_search_plugin_fields |
13 | - self::SEARCHABLE_FIELDS.keys.map(&:to_s).sort.map {|f| "coalesce(\"#{table_name}\".#{f}, '')"}.join(" || ' ' || ") | 13 | + self::SEARCHABLE_FIELDS.keys.map(&:to_s).sort.map {|f| "coalesce(#{table_name}.#{f}, '')"}.join(" || ' ' || ") |
14 | end | 14 | end |
15 | end | 15 | end |