开发者

Finding á, à, etc characters with ferret in rails

开发者 https://www.devze.com 2023-01-28 18:21 出处:网络
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.

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(para开发者_C百科ms["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?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号