在 Rails 中查找带有 ferret 的 á、à 等字符

发布于 2024-10-06 08:05:06 字数 535 浏览 1 评论 0原文

我有一个 Rails 项目,有 ferret 正在处理它。我还有一些带有法国和西班牙名字的桌子。其中包含以下字符:á、à。 ü 等 当我进行搜索时,我只使用常见字符,这使得我无法使用“berche”等关键字在数据库中找到“bèrché”之类的内容。 我尝试用“?”之类的通配符替换人声。或“*”,但它似乎不起作用。

这是代码:

# controller
default_options = {:limit => :all}
@results_ferret = Model.find_with_ferret(params["search_words"], default_options)

# model
class Model < ActiveRecord::Base
  require 'acts_as_ferret'
  acts_as_ferret({:fields => [:region, :origin, :something, :name, :content], :remote => true})
end

有什么想法如何继续吗?

I have a rails project with ferret working on it. Also I have some tables with french and spanish names in there. That contains characters like: á, à. ü, etc.
When I made a search I only use common characters and that makes me impossible to find in the database something like "bèrché" using a keyword like "berche".
I tried to replace the vocals with a wildcard like "?" or "*", but it doesn't seems to work.

Here is the code:

# controller
default_options = {:limit => :all}
@results_ferret = Model.find_with_ferret(params["search_words"], default_options)

# model
class Model < ActiveRecord::Base
  require 'acts_as_ferret'
  acts_as_ferret({:fields => [:region, :origin, :something, :name, :content], :remote => true})
end

Any ideas how to proceed?

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

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

发布评论

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

评论(1

蓝色星空 2024-10-13 08:05:06

Ferret 在构建索引时需要了解区域设置。它通过查看环境变量“LANG”来实现这一点。我们有一个名为 ferret:rebuild 的 rake 任务,所以对我们来说它看起来像这样:

RAILS_ENV=development LANG=da_DK.UTF-8 INDEXES='Model' rake ferret:rebuild

如果这不起作用,请检查您的数据库排序规则。

供您参考

我们的 rake 任务如下所示:

namespace :ferret do

  # Rebuild index task. Declare the indexes to be rebuilt with the INDEXES
  # environment variable:
  #
  # INDEXES="my_model shared" rake ferret:rebuild
  desc "Rebuild a Ferret index. Specify what model to rebuild with the INDEXES environment variable."
  task :rebuild => :environment do

    models = ENV['INDEXES'].split.map(&:constantize)

    start = 1.minute.ago
    models.each { |m| m.rebuild_index }

    # update records that have changed since the rebuild started
    models.each do |m|
      m.records_modified_since(start).each do |object|
        object.ferret_update
      end
    end
  end
end

Ferret needs to know about the locale when building the index. It does so by looking at environment variable 'LANG'. We have a rake task called ferret:rebuild so for us it looks like this:

RAILS_ENV=development LANG=da_DK.UTF-8 INDEXES='Model' rake ferret:rebuild

If this does not work, check out your database collation.

For your reference

Our rake task looks like this:

namespace :ferret do

  # Rebuild index task. Declare the indexes to be rebuilt with the INDEXES
  # environment variable:
  #
  # INDEXES="my_model shared" rake ferret:rebuild
  desc "Rebuild a Ferret index. Specify what model to rebuild with the INDEXES environment variable."
  task :rebuild => :environment do

    models = ENV['INDEXES'].split.map(&:constantize)

    start = 1.minute.ago
    models.each { |m| m.rebuild_index }

    # update records that have changed since the rebuild started
    models.each do |m|
      m.records_modified_since(start).each do |object|
        object.ferret_update
      end
    end
  end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文