搜索逻辑“或”相关记录的条件
铁路2.3.5 Searchlogic 2.3.27
我有以下型号;
class Outbreak < ActiveRecord::Base
has_many :bacterial_agents, :dependent => :destroy
has_many :bacteria, :through => :bacterial_agents
has_many :viral_agents, :dependent => :destroy
has_many :viruses, :through => :viral_agents
end
class BacterialAgent < ActiveRecord::Base
belongs_to :outbreak
belongs_to :bacterium
end
class Bacterium < ActiveRecord::Base
has_many :bacterial_agents
has_many :outbreaks, :through => :bacterial_agents
end
class ViralAgent < ActiveRecord::Base
belongs_to :outbreak
belongs_to :virus
end
class Virus < ActiveRecord::Base
has_many :viral_agents
has_many :outbreaks, :through => :viral_agents
end
我目前正在尝试让 Searchlogic 接受“OR”条件,以便在模型病毒和细菌之间进行搜索,沿着这些思路;
params[:search] = {"bacterial_agents_bacterium_name_like_any" => "VTEC O157", "viral_agents_virus_name_like_any" => "NOROVIRUS"}
@search = Outbreak.search(params[:search])
尽管两个作用域都可以在没有“或”的情况下工作,但无法识别作用域“_or_viral_agents_virus_name_like”。返回的输出应显示细菌名称如“VTEC O157”或病毒名称如“NOROVIRUS”的所有记录(“any”子句允许每个记录有多个名称)。
有什么想法吗?
Rails 2.3.5
Searchlogic 2.3.27
I have the following models;
class Outbreak < ActiveRecord::Base
has_many :bacterial_agents, :dependent => :destroy
has_many :bacteria, :through => :bacterial_agents
has_many :viral_agents, :dependent => :destroy
has_many :viruses, :through => :viral_agents
end
class BacterialAgent < ActiveRecord::Base
belongs_to :outbreak
belongs_to :bacterium
end
class Bacterium < ActiveRecord::Base
has_many :bacterial_agents
has_many :outbreaks, :through => :bacterial_agents
end
class ViralAgent < ActiveRecord::Base
belongs_to :outbreak
belongs_to :virus
end
class Virus < ActiveRecord::Base
has_many :viral_agents
has_many :outbreaks, :through => :viral_agents
end
I'm currently trying to get Searchlogic to accept an "OR" condition for a search between the models Virus and Bacterium, along these lines;
params[:search] = {"bacterial_agents_bacterium_name_like_any" => "VTEC O157", "viral_agents_virus_name_like_any" => "NOROVIRUS"}
@search = Outbreak.search(params[:search])
The scope "_or_viral_agents_virus_name_like" isn't recognised although both scopes work without the "or". The returned output should show all records where the bacteria name is like "VTEC O157" or the virus name is like "NOROVIRUS" (the "any" clause is to allow multiple names for each).
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可能是错的,但我认为除非使用同一模型中的列并针对单个条件进行测试,否则这不起作用。请参阅 Github 问题页面进行讨论。
IMO 最好的选择是编写自己的范围。
I could be wrong, but I don't think this works except when using columns from the same model and testing against a single condition. See the Github issues page for a discussion.
Your best bet IMO is to write your own scope.