代码之家  ›  专栏  ›  技术社区  ›  Jeremy Thomas

PG搜索未返回预期记录

  •  0
  • Jeremy Thomas  · 技术社区  · 5 年前

    我有一个 Call

    class Call < ActiveRecord::Base
        has_one :employee
        include PgSearch::Model
    
        pg_search_scope :call_search, 
            against: [:raw_digits, :referrer, :url, :direction],
            associated_against: {
                employee: [:name]
            },
            using: {
                tsearch: {
                    prefix: true
                }
            }
    

    记录中的电话号码存储在字段中 raw_digits 格式 +1 XXX-XXX-XXXX .

    我和你有一个记录 raw_digits: +1 234-567-8910 但当我调用时,结果是空的:

    > Call.call_search("567")
      Call Exists (2.3ms)  SELECT  1 AS one FROM "calls" INNER JOIN (SELECT "calls"."id" AS pg_search_id, (ts_rank((to_tsvector('simple', coalesce("calls"."raw_digits"::text, '')) || to_tsvector('simple', coalesce("calls"."referrer"::text, '')) || to_tsvector('simple', coalesce("calls"."url"::text, '')) || to_tsvector('simple', coalesce("calls"."direction"::text, '')) || to_tsvector('simple', coalesce(pg_search_5cd951feb4454dbf4e1632.pg_search_f6609a5466395faa400ca5::text, ''))), (to_tsquery('simple', ''' ' || '567' || ' ''' || ':*')), 0)) AS rank FROM "calls" LEFT OUTER JOIN (SELECT "calls"."id" AS id, "employees"."name"::text AS pg_search_f6609a5466395faa400ca5 FROM "calls" INNER JOIN "foreign_ids" ON "foreign_ids"."external_id" = "calls"."aircall_user_id" AND "foreign_ids"."referenceable_type" = 'Employee' INNER JOIN "employees" ON "employees"."id" = "foreign_ids"."referenceable_id") pg_search_5cd951feb4454dbf4e1632 ON pg_search_5cd951feb4454dbf4e1632.id = "calls"."id" WHERE ((to_tsvector('simple', coalesce("calls"."raw_digits"::text, '')) || to_tsvector('simple', coalesce("calls"."referrer"::text, '')) || to_tsvector('simple', coalesce("calls"."url"::text, '')) || to_tsvector('simple', coalesce("calls"."direction"::text, '')) || to_tsvector('simple', coalesce(pg_search_5cd951feb4454dbf4e1632.pg_search_f6609a5466395faa400ca5::text, ''))) @@ (to_tsquery('simple', ''' ' || '567' || ' ''' || ':*')))) AS pg_search_f46f5990ebfadcab199107 ON "calls"."id" = pg_search_f46f5990ebfadcab199107.pg_search_id LIMIT $1  [["LIMIT", 1]]
    []
    

    我错过什么了吗?即使在我设置的属性的中间,记录也不应该被搜索返回吗? prefix: true ? 顺便说一句,我正在运行PostgreSQL 12.1。

    0 回复  |  直到 5 年前