views:

199

answers:

1

I am trying get acts_as_ferret working in my rails applications. I have installed the ferret gem. Installed the acts_as_ferret plugin.

This is what my model looks like now.

class User < ActiveRecord::Base
  acts_as_ferret :fields => {
    :first_name => {},
    :last_name => {}
  }

I have even tried

class User < ActiveRecord::Base
  acts_as_ferret :fields => [:first_name, :last_name]

Now I opened script/console

Here is the code I wrote and the response I got

 User.first 
 # => <Jobseeker id: 1, first_name: "Chirantan", last_name: "Rajhans"\>
 User.find(:first, :conditions => ["first_name like ?", '%chi%'])
 # => <Jobseeker id: 1, first_name: "Chirantan", last_name: "Rajhans"\>
 User.find_with_ferret 'chi'
 # => []
 User.find_with_ferret '%chi%'
 # => []
 User.find_with_ferret 'Chirantan'
 # => []

I even tried rebuilding the index. Did not work. The ferret log shows that everything is going well.

Here is the snapshot of the log.

    [user] rebuild index with models: [User(id: integer, login: string, email: string, crypted_password: string, salt: string, created_at: datetime, updated_at: datetime, remember_token: string, remember_token_expires_at: datetime, first_name: string, middle_name: string, last_name: string, url_id: string, active: boolean, feature_profile: boolean, type: string, company_id: string)]
    [user] reindexing model User
    [user] reindex model User : 100.00% complete : 0.01 secs to finish
    [user] reopening index at /home/chirantan/workspace/parnunu/index/development/user

    index_for [User(id: integer, login: string, email: string, crypted_password: string, salt: string, created_at: datetime, updated_at: datetime, remember_token: string, remember_token_expires_at: datetime, first_name: string, middle_name: string, last_name: string, url_id: string, active: boolean, feature_profile: boolean, type: string, company_id: string)]
    options: {:limit=>nil, :offset=>nil}
    ar_options: {}
    [user] stored_fields: nil
    [user] query: chi
    -->+(last_name:chi first_name:chi) +(class_name:User)
    [user] now retrieving records from AR with options: {}
    [user] 0 results from AR: []
    Query: chi
    total hits: 0, results delivered: 0

    index_for [User(id: integer, login: string, email: string, crypted_password: string, salt: string, created_at: datetime, updated_at: datetime, remember_token: string, remember_token_expires_at: datetime, first_name: string, middle_name: string, last_name: string, url_id: string, active: boolean, feature_profile: boolean, type: string, company_id: string)]
    options: {:limit=>nil, :offset=>nil}
    ar_options: {}
    [user] stored_fields: nil
    [user] query: %chi%
    -->+(last_name:chi first_name:chi) +(class_name:User)
    [user] now retrieving records from AR with options: {}
    [user] 0 results from AR: []
    Query: %chi%
    total hits: 0, results delivered: 0

    index_for [User(id: integer, login: string, email: string, crypted_password: string, salt: string, created_at: datetime, updated_at: datetime, remember_token: string, remember_token_expires_at: datetime, first_name: string, middle_name: string, last_name: string, url_id: string, active: boolean, feature_profile: boolean, type: string, company_id: string)]
    options: {:limit=>nil, :offset=>nil}
    ar_options: {}
    [user] stored_fields: nil
    [user] query: Chirantan
    -->+(last_name:chirantan first_name:chirantan) +(class_name:User)
    [user] now retrieving records from AR with options: {}
    [user] 0 results from AR: []
    Query: Chirantan
    total hits: 0, results delivered: 0

I was testing this in development mode in the console. Is there a step that I have missed or do I need some indexing process running (Like in ThinkingSphinx)? What am I doing wrong?

A: 

Try a query of

User.find_with_ferret 'first_name:Chirantan'

It sounds like you are not searching all fields. You need to use the default_field option if you want to specify fields.

MattMcKnight
Thanks. But since I did not get a response for a few hours, I switched to Sphinx and it worked very well. I would try out your suggestion though.
Chirantan