Thinking Sphinx 中搜索条件的索引计算字段
我设置了一个产品模型,正在尝试使用 Thinking Sphinx 进行搜索。 该模型有一个名为“状态”的属性,该属性可以是“活动”、“不活动”或在指定日期期间“活动”。
我希望能够将我的搜索结果限制为活跃的产品。 即具有活动状态或在日期期间具有活动状态并且当前时间在这些日期之间。
我是 Rails 的初学者,所以我正在寻找有关如何实现这一点的建议。 我考虑过在我的模型中放置一个布尔方法来计算这个逻辑,但我不认为这可以被 Sphinx 索引。
我使用 MySQL 作为数据库服务器。
有人有什么好主意吗?
I have a products model set up that I am trying to search with Thinking Sphinx. The model has an attribute called status which can be Active, Not active or Active during specified dates.
I would like to be able to restrict my search results to products that are active. I.e. has status of active or has status of active during dates and the current time is between those dates.
I'm a beginner to Rails so I'm looking for suggestions as to how I could implement this. I thought about putting a boolean method in my model that calculates this logic, but I don't think that this is indexable by Sphinx.
I am using MySQL as the database server.
Does anyone have any bright ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你是对的,你的模型上的 ruby 方法不能被 sphinx 访问。 但是,您可以将该方法重新创建为 sphinx 属性。 这些可以很容易地使用 SQL 片段来实现,如下所示:
使用字符串来指定字段或属性,就像在构建 SQL 查询时指定自定义列一样。
You're right, ruby methods on your model are not accesible to sphinx. However you can re-create the method as a sphinx attribute. These can easily be made using SQL fragments like so:
Using a string to specify a field or attribute like this is the same as specifying a custom column when building an SQL query.
尝试#indexes方法(我自己没有尝试过,只是在谷歌搜索中注意到)
http://www.slideshare.net/sazwqa/using-thinking-sphinx-with-rails-presentation
幻灯片 11
http://rdoc.info/rdoc/freelancing-god/thinking-sphinx/blob/04320b610b 3a665ca1885cc2e6f29354d029e49a /ThinkingSphinx/Index/Builder.html#indexes-instance_method
另:
http://www.mail-archive.com/[电子邮件& nbsp;受保护]/msg02046.html
try the #indexes method (haven't tried myself, just noticed in googling around)
http://www.slideshare.net/sazwqa/using-thinking-sphinx-with-rails-presentation
slide 11
http://rdoc.info/rdoc/freelancing-god/thinking-sphinx/blob/04320b610b3a665ca1885cc2e6f29354d029e49a/ThinkingSphinx/Index/Builder.html#indexes-instance_method
Also:
http://www.mail-archive.com/[email protected]/msg02046.html