diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 07926e6..47855ec 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -1,6 +1,7 @@ class PProductRef < ApplicationRecord - belongs_to :p_product + belongs_to :p_product + has_one :s_brand, through: :p_product has_many :p_customer_cats, :through => :p_product has_many :p_product_features @@ -48,6 +49,17 @@ class PProductRef < ApplicationRecord :actions => {:name => "Actions", :reorder => false} } + include PgSearch::Model + pg_search_scope :global_search, + against: :cc_name, + associated_against: { + s_brand: [ :code, :name ], + p_product: [:code], + p_product_color: [:name, :color] + }, + using: { + tsearch: { prefix: true } + } def not_imported? if !self.p_product or !self.p_product.imported diff --git a/db/migrate/20210928122901_create_pg_search_documents.rb b/db/migrate/20210928122901_create_pg_search_documents.rb deleted file mode 100644 index a234851..0000000 --- a/db/migrate/20210928122901_create_pg_search_documents.rb +++ /dev/null @@ -1,17 +0,0 @@ -class CreatePgSearchDocuments < ActiveRecord::Migration[6.0] - def up - say_with_time("Creating table for pg_search multisearch") do - create_table :pg_search_documents do |t| - t.text :content - t.belongs_to :searchable, polymorphic: true, index: true - t.timestamps null: false - end - end - end - - def down - say_with_time("Dropping table for pg_search multisearch") do - drop_table :pg_search_documents - end - end -end diff --git a/db/schema.rb b/db/schema.rb index 8412ef2..33a7cb9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_09_28_122901) do +ActiveRecord::Schema.define(version: 2021_09_07_083709) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -2125,15 +2125,6 @@ ActiveRecord::Schema.define(version: 2021_09_28_122901) do t.index ["admin_id"], name: "idx_54659_index_partitions_on_admin_id" end - create_table "pg_search_documents", force: :cascade do |t| - t.text "content" - t.string "searchable_type" - t.bigint "searchable_id" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false - t.index ["searchable_type", "searchable_id"], name: "index_pg_search_documents_on_searchable_type_and_searchable_id" - end - create_table "portlets", force: :cascade do |t| t.bigint "block_id" t.bigint "content_id"