1

私は自分の Rails アプリケーションで act_as_ferret を動作させようとしています。ferretジェムをインストールしました。acts_as_ferretプラグインをインストールしました。

これが私のモデルの現在の外観です。

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

私も試してみました

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

今、私は開いたscript/console

これが私が書いたコードと私が得た応答です

 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'
 # => []

インデックスの再構築も試みました。動作しませんでした。フェレットのログは、すべてがうまくいっていることを示しています。

これがログのスナップショットです。

    [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

これをコンソールの開発モードでテストしていました。見逃したステップはありますか、それとも (ThinkingSphinx のように) インデックス作成プロセスを実行する必要がありますか? 私は何を間違っていますか?

4

1 に答える 1

0

のクエリを試してください

User.find_with_ferret 'first_name:Chirantan'

すべてのフィールドを検索しているわけではないようです。フィールドを指定する場合は、default_fieldオプションを使用する必要があります。

于 2009-12-21T16:36:12.903 に答える