2

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?

malev
  • 235
  • 2
  • 5

1 Answers1

0

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
Jeppe Liisberg
  • 3,734
  • 3
  • 25
  • 24