简体   繁体   English

actions_as_ferret根本不搜索

[英]acts_as_ferret not searching at all

I am trying get acts_as_ferret working in my rails applications. 我正在尝试使acts_as_ferret在我的Rails应用程序中工作。 I have installed the ferret gem. 我已经安装了ferret宝石。 Installed the acts_as_ferret plugin. 安装了acts_as_ferret插件。

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 现在我打开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)? 是否有我遗漏的步骤,或者我是否需要运行一些索引编制过程(例如ThinkSphinx)? What am I doing wrong? 我究竟做错了什么?

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. 如果要指定字段,则需要使用default_field选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM