我已经能够成功地实现基本的全文搜索,但是当我尝试使用范围(“with statements”)时,任何涉及多对多关系模型的查询似乎都不适合我。我知道相关行位于数据库中,因为我的 sql 语句确实返回了数据。然而,太阳黑子查询不会返回任何结果……我确信这可能是我的新手搞砸了……任何帮助将不胜感激……所以我们开始……。
我的模特
class User
has_one :registration
searchable do
text :first_name
text :last_name
text :email
end
end
class Registration
belongs_to :user
has_many :registration_programs
has_many :programs, :through => :registration_programs
searchable do
integer :user_id
integer :registration_status_id
end
end
class RegistrationProgram
belongs_to :registration
belongs :program
searchable do
integer :registration_id
integer :program_id
end
end
我在控制器中的查询
@search = Sunspot.search(User, Registration, RegistrationPrograms)do
# this works fine with the frame, lame, email fields "on its own"
fulltext params["instructor-search"]
any_of
all_of
with(:class => Registraion)
with(:registration_status_id, 3)
end
all_of
with(:class => RegistraionProgram)
with(:program_id, 1)
end
end
end
数据库中有一些记录,其 f_name 为 foo,其 reg 状态和程序字段为 3 和 1 id。但是我无法让 Sunspot/websolr 获取它们......我唯一一次让上述查询工作是当我“单独”运行所有三个条件时......!每当我将它们组合起来时,我似乎都没有返回任何行。
任何帮助/建议将不胜感激……。
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)