使用Thinking Sphinx搜索索引模型对象的集合(Searching through a collection of indexed model objects using Thinking Sphinx)
我有一个属于用户的技术模型,由Thinking Sphinx索引。
我的模型中还有一个方法返回一个Technique对象数组:
def possible_children(user) user.techniques - (self.children + [self]) end
这只是采用用户拥有的技术,减去已经是'self'技术对象的子项的技术,以及'self'本身,并返回剩余的技术对象。
然后在控制器中我实例化一组可能的孩子,如下所示:
@possible_children = @technique.possible_children(current_user).search params[:search]
这将返回“未定义的方法'搜索'#”
不确定这是否相关,但发生的控制器不是TechniquesController。
我想要做的是搜索由Model方法返回的任意集合。
有任何想法吗?
如果我需要提供更多信息,请告诉我。 谢谢。
I have a Technique model which belongs_to User and is indexed by Thinking Sphinx.
I also have a method in my model that returns an array of Technique objects:
def possible_children(user) user.techniques - (self.children + [self]) end
This just takes the techniques that a user has, subtracts out those of the techniques that are already the children of the 'self' technique object, along with 'self' itself, and returns the remaining technique objects.
Then in a controller I instantiate a collection of possible children like so:
@possible_children = @technique.possible_children(current_user).search params[:search]
This returns an "undefined method 'search' for #"
Not sure if this is relevant but the controller this takes place in is not the TechniquesController.
What I am trying to do is search an arbitrary collection returned by a Model method.
Any ideas?
Let me know if I need to provide more information. Thank you.
原文:https://stackoverflow.com/questions/6591054
最满意答案
我认为你应该绘制箭头作为依赖箭头走向另一个方向。 这有助于以这种方式思考,因为执行路径是由require方法确定的。 在你的场景中,它非常简单,因为你只有一个具有条件依赖性的TaskA。
您只需要在开始时添加一个任务,这取决于两个TaskB和一个指示任务b是否在样本上运行的指示器
伪代码:
ParentTask def requires(): return [TaskB(sample_type=True), TaskB(sample_type=False)] TaskB def requires(): return TaskA(sample_type) TaskA def requires(): if sample_type: return SampleTask() else: return CleanTask() SampleTask def requires(): return CleanTask() CleanTask def requires() return CollectData()
I think you should draw the arrows as dependency arrows going the other way. It helps to think about it this way since the execution path is determined by the requires methods. In your scenario, it is very simple because you just have a TaskA that has a conditional dependency.
You just need to add one more task at the start that depends on two TaskBs and an indicator of whether the taskb is to be run on the sample
Pseudocode:
ParentTask def requires(): return [TaskB(sample_type=True), TaskB(sample_type=False)] TaskB def requires(): return TaskA(sample_type) TaskA def requires(): if sample_type: return SampleTask() else: return CleanTask() SampleTask def requires(): return CleanTask() CleanTask def requires() return CollectData()
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
Luigi可以在任务依赖关系过期时重新运行任务吗?(Can luigi rerun tasks when the task dependencies become out of date?)[2023-01-21]
您可以通过覆盖complete(...)方法来实现您的目标。 complete的文档很简单 。 只需实现一个检查约束的函数,并且如果要重新计算任务,则返回False 。 例如,要在依赖项更新时强制重新计算,可以这样做: def complete(self): """Flag this task as incomplete if any requirement is incomplete or has been updated more recently than this task""" i ... -
如果这是正确的,我不是100%肯定的,但这是我首先尝试的。 当你打电话给luigi.run ,通过它--scheduler-remove-delay 。 我猜这是在调度器完成之后忘记任务之前等待的时间。 如果你仔细观察luigi的来源 ,默认值是600秒。 例如: luigi.run(["--workers", "8", "--scheduler-remove-delay","86400")], main_task_cls=task_name) I'm not 100% positive if this ...
-
您可以对调度程序使用remove_delay设置。 在您的配置文件中: [scheduler] remove_delay = 10 这适用于调度程序,因此您需要重新启动luigid才能启用它。 从文档: 在删除没有利益相关者的任务之前等待的秒数。 默认为600(10分钟)。 根据经验,该案例中的利益相关者似乎意味着工人和上游/下游依赖关系。 You can use the remove_delay setting for the scheduler. In your config file: [sched ...
-
如何运行Luigi管道的并行实例:Pid设置已经运行(How to run parallel instances of a Luigi Pipeline : Pid set already running)[2022-07-11]
看起来这可能是因为您没有连接到调度程序服务器,因此它尝试启动调度程序进程两次。 你在运行luigid吗? 我能够让您的代码在命令行运行,如下所示。 首先,我创建了一个目录,并将您的代码放在名为luigitest.py的文件中(减去luigi.run()命令)。 我将目录更改为我创建的目录。 然后我跑了: luigid --background --pidfile ./luigid.pid --logdir . --state-path . 然后我在同一目录中打开了第二个终端。 在第一个我跑: PYTHON ... -
是否有可能在路易吉管道的两个不同点重复使用任务?(Is it possible to reuse a task in two different spots in a Luigi pipeline?)[2023-04-06]
我认为你应该绘制箭头作为依赖箭头走向另一个方向。 这有助于以这种方式思考,因为执行路径是由require方法确定的。 在你的场景中,它非常简单,因为你只有一个具有条件依赖性的TaskA。 您只需要在开始时添加一个任务,这取决于两个TaskB和一个指示任务b是否在样本上运行的指示器 伪代码: ParentTask def requires(): return [TaskB(sample_type=True), TaskB(sample_type=False)] Ta ... -
requires()应该返回一个或多个任务,而不是参数。 例如, class Runner(luigi.Task): notebooks = luigi.ListParameter() def requires(self): required_tasks = [] for notebook in self.notebooks: required_tasks.append(Transform(notebook)) return required_tasks ...
-
Luigi直接将文件写入S3(Luigi write file directly to S3)[2022-06-18]
问题解决了! 这是因为s3 buckt的格式。 正确的格式应为's3:// mybucket / myfile'405 ERROR是由boto无法识别存储桶名称引起的。 另外需要提一下的是,boto无法用'。'识别桶名。 在Python 2.7。*中,所以你必须使用有效的存储桶名称或在配置文件中更改它。 Problem solved! It's because of the format of the s3 buckt. The correct format should be 's3://mybucket ... -
问题在于LocalTarget的格式。 将其更改为: return luigi.LocalTarget('test.npz', format=luigi.format.Nop) 解决了这个问题。 但是文档中没有任何相关内容。 The problem was with the format of the LocalTarget. Changing it to: return luigi.LocalTarget('test.npz', format=luigi.format.Nop) solved the ...