搜索逻辑“或”相关记录的条件

发布于 2024-10-17 03:25:27 字数 1202 浏览 3 评论 0原文

铁路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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哀由 2024-10-24 03:25:27

我可能是错的,但我认为除非使用同一模型中的列并针对单个条件进行测试,否则这不起作用。请参阅 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文