Pg_search迁移不添加列

时间:2017-07-22 10:37:54

标签: ruby-on-rails postgresql pg-search

我有两个型号

class Post < ApplicationRecord
  include PgSearch
  multisearchable :against => [:title, :content]

...

class Question < ApplicationRecord

  include PgSearch
  multisearchable :against => [:title, :content]

我运行命令

rails g pg_search:migration:multisearch

它生成此迁移

class CreatePgSearchDocuments < ActiveRecord::Migration
  def self.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 self.down
    say_with_time("Dropping table for pg_search multisearch") do
      drop_table :pg_search_documents
    end
  end
end

不添加列标题。为什么这样?

更新即可。 Pg_Search在一列中连接列标题和内容 - 内容。我不明白为什么。

Rails 5.0.2

Ruby ruby​​ 2.3.3p222(2016-11-21修订版56859)[x86_64-linux]

1 个答案:

答案 0 :(得分:1)

pg_search将不同的列连接成一个,以简化ts_vector的使用。

如果你有不同的列加权词,搜索会更复杂,因为你必须在流程结束时让所有内容同步并正确排序。

如果您对加权关键字感兴趣(建议在接近结束时提出解决方案)和https://github.com/Casecommons/pg_search/issues/86

,我建议您阅读以下Searching multiple models with pg_search