Sunspot/Solr 和 Rails 的单表继承
我在 Rails 应用程序中有以下类:
class Post
include Mongoid::Document
include Sunspot::Mongoid
belongs_to :user
searchable do
text :name
string :user_id
end
end
class Post::Image < Post
searchable do
text :location
time :taken_at
end
end
class Post::Link < Post
searchable do
text :href
end
end
据我所知,调用以下应该可以工作。
Post.search do
fulltext('something')
with(:user_id, user.id)
end
但事实并非如此。它返回一个空结果。调用 Post::Link.search
也不起作用:
# => Sunspot::UnrecognizedFieldError: No field configured for Post::Link with name 'user_id'
有什么建议吗?
I have following classes in a Rails app:
class Post
include Mongoid::Document
include Sunspot::Mongoid
belongs_to :user
searchable do
text :name
string :user_id
end
end
class Post::Image < Post
searchable do
text :location
time :taken_at
end
end
class Post::Link < Post
searchable do
text :href
end
end
As far as I know, calling following should just work.
Post.search do
fulltext('something')
with(:user_id, user.id)
end
But it does not. It returns an empty result. Calling Post::Link.search
does also not work:
# => Sunspot::UnrecognizedFieldError: No field configured for Post::Link with name 'user_id'
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论