gem PgSearch 按名称查找错误的客户端



我有一个奇怪的异常错误。我不知道为什么会这样。你能帮我描述一下我做错了什么吗?

我有一个简单的pgsearch。

客户端.rb

pg_search_scope :search,
   against: %i[name phone_number],
   associated_against: {
    month_payments: [:payment_note],
      addresses: %i[address_1 town state zip_code]
      },
    using: { tsearch: { prefix: true, any_word: true } }

这是我的控制台输出:

c = Company.find(172)
c.clients.search(name: "Vasja B")
=> [#<Client id: 2210, company_id: 172, name: "Client 2", email: "", variety: "residential", created_at: "2019-07-23 13:19:36", updated_at: "2019-07-24 11:48:19", phone_number: "", organisation: "", office_note: "", special_note: "", status: "active", mowing: true, landscaping: false, fertilizing: false, leaf_removal: true>]>
2.5.3 :016 > c.clients.count
(1.2ms)  SELECT COUNT(*) FROM "clients" WHERE "clients"."company_id" = $1  [["company_id", 172]]
=> 2 
2.5.3 :017 > c.clients.last
Client Load (1.0ms)  SELECT  "clients".* FROM "clients" WHERE 
"clients"."company_id" = $1 ORDER BY "clients"."id" DESC LIMIT $2  [["company_id", 172], ["LIMIT", 1]]
=> #<Client id: 2210, company_id: 172, name: "Client 2", email: "", variety: "residential", created_at: "2019-07-23 13:19:36", updated_at: "2019-07-24 11:48:19", phone_number: "", organisation: "", office_note: "", special_note: "", status: "active", mowing: true, landscaping: false, fertilizing: false, leaf_removal: true> 
2.5.3 :018 > c.clients.first
Client Load (0.3ms)  SELECT  "clients".* FROM "clients" WHERE "clients"."company_id" = $1 ORDER BY "clients"."id" ASC LIMIT $2  [["company_id", 172], ["LIMIT", 1]]
=> #<Client id: 2209, company_id: 172, name: "Client 1", email: "", variety: "residential", created_at: "2019-07-23 13:19:11", updated_at: "2019-07-24 11:48:19", phone_number: "", organisation: "", office_note: "", special_note: "", status: "active", mowing: true, landscaping: false, fertilizing: false, leaf_removal: false> 

为什么 pgsearch 查找客户端 2 而不是现有记录? :)

可能需要重建索引

该文档列出了它们可能不同步的情况以及有关如何重新生成它们的命令。

$ rake pg_search:multisearch:rebuild[Client]

相关内容

最新更新