认为sphinx在生产中没有正确索引belongs_to关系,但在开发中工作正常

发布于 2024-12-13 18:11:23 字数 1493 浏览 1 评论 0原文

我想显示与给定作者相关的电影。在作者页面上,我希望用户能够按关键字分页、排序和过滤。

在我的本地机器上一切正常。但是,在制作过程中,作者页面上的电影列表是空的,我不明白为什么。在生产中,在控制台中,我测试了以下表达式,但没有运气(总是返回 0,而在开发中返回值 > 0):

ruby-1.9.2-p290 :042 > Movie.search(:with => {:author_ids => [6]}).count
 => 0
 ruby-1.9.2-p290 :043 > Movie.search(:with => {:author_ids => 6}).count
 => 0 

奇怪的是,我使用非常相似的代码来显示关联的电影到主题页面上的主题,它在开发和生产中都非常有效。例如:

ruby-1.9.2-p290 :051 > Movie.search(:with => {:topic_ids => 2}, :per_page   => 1000).count
 => 295 

这是我定义电影类的方式:

class Movie < ActiveRecord::Base

  belongs_to :author
  has_many :topics
  ...

  define_index('movie') do
    ...
    has       author(:id),                :as         => :author_ids,
                                          :facet      => true

    has       topics(:id),                :as         => :topic_ids,
                                          :facet      => true

    ...
  end

  ...
end

这是我的作者显示控制器的样子:

def show
    @author = Author.find(params[:id])
    keywords = params[:what] || ""
    with_params[:author_ids] = [@author.id]

    @movies = Movie.search(
            keywords,
        :with => with_params
    )

end

这让我相信生产中的 Sphinx 索引有问题,但我不确定如何进一步调查找到问题的根源...

更新:按照Pat的建议,我更新了Sphinx,一切都解决了(我从0.9.8升级到0.9.10)!我很困惑,因为 Sphinx 不是 Gem(即使 Sphinx gem 存在)...所以我必须经历常规的下载、制作、安装过程。

I want to display the movies associated to a given author. On the author's page, I want users to be able to paginate, sort, and filter by keyword.

Everything works fine on my local machine. But, in production, the list of movies on the author's page is empty, and I can't figure out why. In production, in the console, I tested the following expressions, but no luck (always returns 0, while it returns values > 0 in dev):

ruby-1.9.2-p290 :042 > Movie.search(:with => {:author_ids => [6]}).count
 => 0
 ruby-1.9.2-p290 :043 > Movie.search(:with => {:author_ids => 6}).count
 => 0 

The weird thing is that I'm using a very similar code to display the movies associated to a topic on a topic's page, and it works great in development AND in production. For instance:

ruby-1.9.2-p290 :051 > Movie.search(:with => {:topic_ids => 2}, :per_page   => 1000).count
 => 295 

Here is how I define my Movie class:

class Movie < ActiveRecord::Base

  belongs_to :author
  has_many :topics
  ...

  define_index('movie') do
    ...
    has       author(:id),                :as         => :author_ids,
                                          :facet      => true

    has       topics(:id),                :as         => :topic_ids,
                                          :facet      => true

    ...
  end

  ...
end

And here is what my Author show controller looks like:

def show
    @author = Author.find(params[:id])
    keywords = params[:what] || ""
    with_params[:author_ids] = [@author.id]

    @movies = Movie.search(
            keywords,
        :with => with_params
    )

end

This leads me to believe there is something wrong with the Sphinx index in production, but I'm not sure how to investigate further to find the root of the problem...

UPDATE: Following Pat's suggestion, I updated Sphinx and everything was solved (I upgraded from 0.9.8 to 0.9.10)! I was confused because Sphinx is NOT a Gem (even though a Sphinx gem exists)... So I had to go through the regular download, make, make install process.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

π浅易 2024-12-20 18:11:23

我将从显而易见的事情开始,但也许这已经被尝试过了——author_ids 属性是相对较新的东西吗?自从添加该属性后,您是否重建了(索引重新启动)Sphinx? rake ts:rebuild 是实现此目的的简单方法。

更新:事实证明,更新 Sphinx 是此处的修复方法 - Alex 可以确认哪个版本,但我猜 0.9.9 或更好的版本应该可以解决问题。

I'll start with the obvious, but maybe this has already been tried - is the author_ids attribute something relatively new? Have you rebuilt (indexed and restarted) Sphinx since adding that attribute? rake ts:rebuild is the easy way to do that.

Update: It turns out updating Sphinx was the fix here - Alex can confirm which version, but I'm guessing 0.9.9 or better should do the trick.

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