如何在太阳黑子中索引一项的翻译

发布于 2025-01-04 10:41:25 字数 934 浏览 2 评论 0原文

我正在使用 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 技术交流群。

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

发布评论

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

评论(1

極樂鬼 2025-01-11 10:41:25

我实现了单列语言索引:

LANGUAGES = {
  'en' => 'English',
  'fr' => 'Français'
}

#inside city model

text :name_alt do
  LANGUAGES.keys.reject{|l| l=='en'}.map do |locale|
    read_attribute(:name, locale:locale)
  end
end

这使用 Rails I18n 模块和 Globalize3。 “read_attribute”是 Globalize3 的一部分。

这避免了为每种语言创建列。

我不确定这是否更好还是多列方法。

I implemented single column language index:

LANGUAGES = {
  'en' => 'English',
  'fr' => 'Français'
}

#inside city model

text :name_alt do
  LANGUAGES.keys.reject{|l| l=='en'}.map do |locale|
    read_attribute(:name, locale:locale)
  end
end

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.

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