acts_as_ferret 根本不搜索

发布于 2024-08-15 02:49:52 字数 3718 浏览 4 评论 0原文

我正在尝试让acts_as_ferret 在我的rails 应用程序中工作。我已经安装了 ferret gem。安装了 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 中)?我做错了什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安稳善良 2024-08-22 02:49:52

尝试查询

User.find_with_ferret 'first_name:Chirantan'

听起来您没有搜索所有字段。如果要指定字段,则需要使用default_field选项。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文