【发布时间】:2011-03-21 12:41:21
【问题描述】:
我在 Rails (2.3.11) 应用程序中有几个使用 STI 构建的模型,并按如下方式排列:
Gallery::Base < ActiveRecord::Base(为 SOLR 编制索引)
Gallery::Local < Gallery::Base(为 SOLR 编制索引)
Gallery::Remote < Gallery::Base(未编入索引)
我发现有关这些模型的索引的不同结果。在我当前的开发数据库中,我有 77 个 Gallery::Local 对象,但没有 Gallery::Remote 对象(这也意味着数据库中有 77 个 Gallery::Base 对象)
问题是Sunspot.search(Gallery::Base) 和Sunspot.search(Gallery::Local) 都返回一个命中。
现在对于陌生的部分:在同事的计算机上使用生产数据库(包含数百个 Gallery::Local 对象),Sunspot.search(Gallery::Base) 或 Sunspot.search(Gallery::Local) 均未返回任何命中!
顺便说一句,我尝试在Gallery::Base 和Gallery::Local 上设置索引,并分别在每个索引中设置索引并重新索引,结果相同。我还有许多其他索引模型,全文搜索可以按预期工作。
有人知道是什么原因造成的吗?
【问题讨论】:
-
你用的是thinkingsphinx之类的吗?如果没有,你能告诉我们
search方法吗? -
其实我才发现问题出在哪里。 rake 任务
sunspot:reindex仅重新索引直接在app/models下的模型。由于我们的Gallery模型是命名空间的(在app/models/gallery内),它们被简单地忽略了。调用Gallery::Base.reindex解决了问题:/ -
另外,忘了告诉我们使用的是 Sunspot / SOLR 而不是 ThinkingSphinx / Sphinx
标签: ruby-on-rails full-text-search solr sunspot-rails