我想执行以下代码在我的控制器中执行搜索:
专家控制器.erb
@users = User.text_search(params[:query]).has_skill_categories(params[:skills]).has_marketing_assets(params[:marketing_platforms])
当我运行应用程序时,我收到以下错误:
PG::SyntaxError: ERROR: subquery has too many columns
LINE 1: ...S pg_search_rank FROM "users" WHERE "users"."id" IN (SELECT...
当我删除使用 pg_search 的 text_search 方法时,我得到它按计划工作:
@users = User.has_skill_categories(params[:skills]).has_marketing_assets(params[:marketing_platforms])
你能告诉我为什么我会收到错误以及如何解决它吗?
这是我的代码。
用户模型 - user.erb
include PgSearch
pg_search_scope :search, against: [:first_name, :last_name, :company, :description, :job_title, :website, :email, :country, :city, :state],
using: {tsearch: {dictionary: 'english'}}
def self.text_search(query)
if query.present?
search(query)
else
User.all
end
end
def self.has_marketing_assets(platforms)
if platforms.present?
where{users.id.in(User.joins{marketing_assets}.where((['marketing_assets.marketing_platform_id = ?' ] * platforms.count).join(' OR '), *platforms).group{users.id}.having{{marketing_assets => {COUNT(DISTINCT(marketing_assets.marketing_platform_id)) => platforms.count }}})}
else
User.all
end
end
def self.has_skill_categories(skills)
if skills.present?
where{users.id.in(User.joins{my_skills}.where((['my_skills.skill_id = ?' ] * skills.count).join(' OR '), *skills).group{users.id}.having{{my_skills => {COUNT(DISTINCT(my_skills.skill_id)) => skills.count }}})}
else
User.all
end
end