如何在太阳黑子中索引一项的翻译
我正在使用 Sunspot/Solr 来索引我的 Rails 网站。我通过执行以下操作来索引城市名称:
class City < ActiveRecord::Base
searchable do
text :name
...
end
...
现在我正在使用 Globalize3 gem 对整个网站进行国际化。它将翻译保存在另一个表中,并使用普通访问器获取这些翻译。
从这里的示例(http://osdir.com/ml/rails- oceania/2011-11/msg00047.html)他们有:
searchable do
# sorting
string(:job_title) { title }
# keyword / fulltext searching
I18n.available_locales.each do |locale|
text(("title_" + locale.to_s).to_sym, :default_boost => 2)
{ eval("title_" + locale.to_s) }
end
end
所以基本上对于每个语言环境,Sunspot 中都有一个索引列,如 title_en 和 title_fr。我想知道是否有更好的方法? (太多的列对我来说听起来很糟糕)
我正在考虑的一种替代方案是将一个项目的翻译连接为单个字符串并将其放入另一个文本索引列中。
我也在想是否有类似的东西 integer :ids, :multiple => true
对于文本?
那么,对同一项目名称的多个翻译建立索引的更好方法是什么?
I am using Sunspot/Solr to index my Rails website. I index City name by doing the following:
class City < ActiveRecord::Base
searchable do
text :name
...
end
...
Now I am internationalizing the whole site, using the Globalize3 gem. It saves translations in another table, and get these translations out using the normal accessors.
From the example here (http://osdir.com/ml/rails-oceania/2011-11/msg00047.html) they have:
searchable do
# sorting
string(:job_title) { title }
# keyword / fulltext searching
I18n.available_locales.each do |locale|
text(("title_" + locale.to_s).to_sym, :default_boost => 2)
{ eval("title_" + locale.to_s) }
end
end
So essentially for each locale there is an indexing column in Sunspot, like title_en and title_fr. I am wondering if there is a better approach? (too many columns sounds bad to me)
One alternative I am thinking is to concatenate translations of one item as a single string and put it in another text index column.
Also I was thinking if there is something similar to integer :ids, :multiple => true
for texts?
So what's a better way to index multiple translations of the same item name?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我实现了单列语言索引:
这使用 Rails I18n 模块和 Globalize3。 “read_attribute”是 Globalize3 的一部分。
这避免了为每种语言创建列。
我不确定这是否更好还是多列方法。
I implemented single column language index:
This uses Rails I18n module and Globalize3. 'read_attribute' is part of Globalize3.
This avoids creating columns per language.
I am not sure whether this is better or the multi column approach.