这是我的pg_search方法:

  pg_search_scope :node_search, against: [:name, :user_id, :circa, :cached_tagged_user_names, :cached_user_tag_list],
    using: { tsearch: { any_word: true, dictionary: :english, prefix: true} },
    :associated_against => {
      comments: [:message],
      user: [:first_name, :last_name, :email],
      memberships: [:relation],
      user_tags: [:name]
    }

不是docs recommendprefix: truetsearch

但是,至少在一种特定情况下,它不能像我期望的那样工作。

我有一个Node对象,看起来像这样:
=> [#<Node id: 85, name: "House Fire 2", family_tree_id: 57, user_id: 57, media_id: 228, media_type: "Video", created_at: "2015-05-15 00:20:26", updated_at: "2015-06-08 22:25:49", circa: nil, is_comment: nil, cached_votes_total: 0, cached_votes_score: 0, cached_votes_up: 0, cached_votes_down: 0, cached_weighted_score: 0, cached_weighted_total: 0, cached_weighted_average: 0.0, cached_user_tag_list: "[email protected], [email protected]", cached_num_user_tags: 2, cached_tagged_user_names: ["Daniel Marty", "Marcamus Prime"]>]

请注意属性:cached_user_tag_list,其中包括电子邮件地址:[email protected]

但是,当我执行以下搜索时,这些是我得到的结果:
[185] pry(main)> Node.node_search("dann")
  Node Load (11.3ms)  SELECT "nodes".*, ((ts_rank((to_tsvector('english', coalesce("nodes"."name"::text, '')) || to_tsvector('english', coalesce("nodes"."user_id"::text, '')) || to_tsvector('english', coalesce("nodes"."circa"::text, '')) || to_tsvector('english', coalesce("nodes"."cached_tagged_user_names"::text, '')) || to_tsvector('english', coalesce("nodes"."cached_user_tag_list"::text, '')) || to_tsvector('english', coalesce(pg_search_121ea89914a721445aee70.pg_search_344e3c62d13849726da22e::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_acfcdbc0b3d3a65f40eab7::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_eeb842708b24d4f7fcf549::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_cb8eb1b84bf18ee1412ffd::text, '')) || to_tsvector('english', coalesce(pg_search_b1bc4c0f44e7f4799d8caf.pg_search_9474fb5b090e75ade5136f::text, '')) || to_tsvector('english', coalesce(pg_search_93dd21271636bd02b16bc3.pg_search_484f77386a5aecc6e01094::text, ''))), (to_tsquery('english', ''' ' || 'dann' || ' ''' || ':*')), 0))) AS pg_search_rank FROM "nodes" LEFT OUTER JOIN (SELECT "nodes"."id" AS id, string_agg("comments"."message"::text, ' ') AS pg_search_344e3c62d13849726da22e FROM "nodes" INNER JOIN "comments" ON "comments"."node_id" = "nodes"."id" GROUP BY "nodes"."id") pg_search_121ea89914a721445aee70 ON pg_search_121ea89914a721445aee70.id = "nodes"."id" LEFT OUTER JOIN (SELECT "nodes"."id" AS id, string_agg("users"."first_name"::text, ' ') AS pg_search_acfcdbc0b3d3a65f40eab7, string_agg("users"."last_name"::text, ' ') AS pg_search_eeb842708b24d4f7fcf549, string_agg("users"."email"::text, ' ') AS pg_search_cb8eb1b84bf18ee1412ffd FROM "nodes" INNER JOIN "users" ON "users"."id" = "nodes"."user_id" GROUP BY "nodes"."id") pg_search_4aab10cdca183dac25f479 ON pg_search_4aab10cdca183dac25f479.id = "nodes"."id" LEFT OUTER JOIN (SELECT "nodes"."id" AS id, string_agg("memberships"."relation"::text, ' ') AS pg_search_9474fb5b090e75ade5136f FROM "nodes" INNER JOIN "family_trees" ON "family_trees"."id" = "nodes"."family_tree_id" INNER JOIN "memberships" ON "memberships"."family_tree_id" = "family_trees"."id" GROUP BY "nodes"."id") pg_search_b1bc4c0f44e7f4799d8caf ON pg_search_b1bc4c0f44e7f4799d8caf.id = "nodes"."id" LEFT OUTER JOIN (SELECT "nodes"."id" AS id, string_agg("tags"."name"::text, ' ') AS pg_search_484f77386a5aecc6e01094 FROM "nodes" INNER JOIN "taggings" ON "taggings"."taggable_id" = "nodes"."id" AND "taggings"."taggable_type" = 'Node' AND "taggings"."context" = 'user_tags' INNER JOIN "tags" ON "tags"."id" = "taggings"."tag_id" GROUP BY "nodes"."id") pg_search_93dd21271636bd02b16bc3 ON pg_search_93dd21271636bd02b16bc3.id = "nodes"."id" WHERE (((to_tsvector('english', coalesce("nodes"."name"::text, '')) || to_tsvector('english', coalesce("nodes"."user_id"::text, '')) || to_tsvector('english', coalesce("nodes"."circa"::text, '')) || to_tsvector('english', coalesce("nodes"."cached_tagged_user_names"::text, '')) || to_tsvector('english', coalesce("nodes"."cached_user_tag_list"::text, '')) || to_tsvector('english', coalesce(pg_search_121ea89914a721445aee70.pg_search_344e3c62d13849726da22e::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_acfcdbc0b3d3a65f40eab7::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_eeb842708b24d4f7fcf549::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_cb8eb1b84bf18ee1412ffd::text, '')) || to_tsvector('english', coalesce(pg_search_b1bc4c0f44e7f4799d8caf.pg_search_9474fb5b090e75ade5136f::text, '')) || to_tsvector('english', coalesce(pg_search_93dd21271636bd02b16bc3.pg_search_484f77386a5aecc6e01094::text, ''))) @@ (to_tsquery('english', ''' ' || 'dann' || ' ''' || ':*'))))  ORDER BY pg_search_rank DESC, "nodes"."id" ASC
=> [#<Node id: 85, name: "House Fire 2", family_tree_id: 57, user_id: 57, media_id: 228, media_type: "Video", created_at: "2015-05-15 00:20:26", updated_at: "2015-06-08 22:25:49", circa: nil, is_comment: nil, cached_votes_total: 0, cached_votes_score: 0, cached_votes_up: 0, cached_votes_down: 0, cached_weighted_score: 0, cached_weighted_total: 0, cached_weighted_average: 0.0, cached_user_tag_list: "[email protected], [email protected]", cached_num_user_tags: 2, cached_tagged_user_names: ["Daniel Marty", "Marcamus Prime"]>]
[186] pry(main)> Node.node_search("dan")
  Node Load (4.2ms)  SELECT "nodes".*, ((ts_rank((to_tsvector('english', coalesce("nodes"."name"::text, '')) || to_tsvector('english', coalesce("nodes"."user_id"::text, '')) || to_tsvector('english', coalesce("nodes"."circa"::text, '')) || to_tsvector('english', coalesce("nodes"."cached_tagged_user_names"::text, '')) || to_tsvector('english', coalesce("nodes"."cached_user_tag_list"::text, '')) || to_tsvector('english', coalesce(pg_search_121ea89914a721445aee70.pg_search_344e3c62d13849726da22e::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_acfcdbc0b3d3a65f40eab7::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_eeb842708b24d4f7fcf549::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_cb8eb1b84bf18ee1412ffd::text, '')) || to_tsvector('english', coalesce(pg_search_b1bc4c0f44e7f4799d8caf.pg_search_9474fb5b090e75ade5136f::text, '')) || to_tsvector('english', coalesce(pg_search_93dd21271636bd02b16bc3.pg_search_484f77386a5aecc6e01094::text, ''))), (to_tsquery('english', ''' ' || 'dan' || ' ''' || ':*')), 0))) AS pg_search_rank FROM "nodes" LEFT OUTER JOIN (SELECT "nodes"."id" AS id, string_agg("comments"."message"::text, ' ') AS pg_search_344e3c62d13849726da22e FROM "nodes" INNER JOIN "comments" ON "comments"."node_id" = "nodes"."id" GROUP BY "nodes"."id") pg_search_121ea89914a721445aee70 ON pg_search_121ea89914a721445aee70.id = "nodes"."id" LEFT OUTER JOIN (SELECT "nodes"."id" AS id, string_agg("users"."first_name"::text, ' ') AS pg_search_acfcdbc0b3d3a65f40eab7, string_agg("users"."last_name"::text, ' ') AS pg_search_eeb842708b24d4f7fcf549, string_agg("users"."email"::text, ' ') AS pg_search_cb8eb1b84bf18ee1412ffd FROM "nodes" INNER JOIN "users" ON "users"."id" = "nodes"."user_id" GROUP BY "nodes"."id") pg_search_4aab10cdca183dac25f479 ON pg_search_4aab10cdca183dac25f479.id = "nodes"."id" LEFT OUTER JOIN (SELECT "nodes"."id" AS id, string_agg("memberships"."relation"::text, ' ') AS pg_search_9474fb5b090e75ade5136f FROM "nodes" INNER JOIN "family_trees" ON "family_trees"."id" = "nodes"."family_tree_id" INNER JOIN "memberships" ON "memberships"."family_tree_id" = "family_trees"."id" GROUP BY "nodes"."id") pg_search_b1bc4c0f44e7f4799d8caf ON pg_search_b1bc4c0f44e7f4799d8caf.id = "nodes"."id" LEFT OUTER JOIN (SELECT "nodes"."id" AS id, string_agg("tags"."name"::text, ' ') AS pg_search_484f77386a5aecc6e01094 FROM "nodes" INNER JOIN "taggings" ON "taggings"."taggable_id" = "nodes"."id" AND "taggings"."taggable_type" = 'Node' AND "taggings"."context" = 'user_tags' INNER JOIN "tags" ON "tags"."id" = "taggings"."tag_id" GROUP BY "nodes"."id") pg_search_93dd21271636bd02b16bc3 ON pg_search_93dd21271636bd02b16bc3.id = "nodes"."id" WHERE (((to_tsvector('english', coalesce("nodes"."name"::text, '')) || to_tsvector('english', coalesce("nodes"."user_id"::text, '')) || to_tsvector('english', coalesce("nodes"."circa"::text, '')) || to_tsvector('english', coalesce("nodes"."cached_tagged_user_names"::text, '')) || to_tsvector('english', coalesce("nodes"."cached_user_tag_list"::text, '')) || to_tsvector('english', coalesce(pg_search_121ea89914a721445aee70.pg_search_344e3c62d13849726da22e::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_acfcdbc0b3d3a65f40eab7::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_eeb842708b24d4f7fcf549::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_cb8eb1b84bf18ee1412ffd::text, '')) || to_tsvector('english', coalesce(pg_search_b1bc4c0f44e7f4799d8caf.pg_search_9474fb5b090e75ade5136f::text, '')) || to_tsvector('english', coalesce(pg_search_93dd21271636bd02b16bc3.pg_search_484f77386a5aecc6e01094::text, ''))) @@ (to_tsquery('english', ''' ' || 'dan' || ' ''' || ':*'))))  ORDER BY pg_search_rank DESC, "nodes"."id" ASC
=> [#<Node id: 85, name: "House Fire 2", family_tree_id: 57, user_id: 57, media_id: 228, media_type: "Video", created_at: "2015-05-15 00:20:26", updated_at: "2015-06-08 22:25:49", circa: nil, is_comment: nil, cached_votes_total: 0, cached_votes_score: 0, cached_votes_up: 0, cached_votes_down: 0, cached_weighted_score: 0, cached_weighted_total: 0, cached_weighted_average: 0.0, cached_user_tag_list: "[email protected], [email protected]", cached_num_user_tags: 2, cached_tagged_user_names: ["Daniel Marty", "Marcamus Prime"]>]
[187] pry(main)> Node.node_search("danny")
  Node Load (2.8ms)  SELECT "nodes".*, ((ts_rank((to_tsvector('english', coalesce("nodes"."name"::text, '')) || to_tsvector('english', coalesce("nodes"."user_id"::text, '')) || to_tsvector('english', coalesce("nodes"."circa"::text, '')) || to_tsvector('english', coalesce("nodes"."cached_tagged_user_names"::text, '')) || to_tsvector('english', coalesce("nodes"."cached_user_tag_list"::text, '')) || to_tsvector('english', coalesce(pg_search_121ea89914a721445aee70.pg_search_344e3c62d13849726da22e::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_acfcdbc0b3d3a65f40eab7::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_eeb842708b24d4f7fcf549::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_cb8eb1b84bf18ee1412ffd::text, '')) || to_tsvector('english', coalesce(pg_search_b1bc4c0f44e7f4799d8caf.pg_search_9474fb5b090e75ade5136f::text, '')) || to_tsvector('english', coalesce(pg_search_93dd21271636bd02b16bc3.pg_search_484f77386a5aecc6e01094::text, ''))), (to_tsquery('english', ''' ' || 'danny' || ' ''' || ':*')), 0))) AS pg_search_rank FROM "nodes" LEFT OUTER JOIN (SELECT "nodes"."id" AS id, string_agg("comments"."message"::text, ' ') AS pg_search_344e3c62d13849726da22e FROM "nodes" INNER JOIN "comments" ON "comments"."node_id" = "nodes"."id" GROUP BY "nodes"."id") pg_search_121ea89914a721445aee70 ON pg_search_121ea89914a721445aee70.id = "nodes"."id" LEFT OUTER JOIN (SELECT "nodes"."id" AS id, string_agg("users"."first_name"::text, ' ') AS pg_search_acfcdbc0b3d3a65f40eab7, string_agg("users"."last_name"::text, ' ') AS pg_search_eeb842708b24d4f7fcf549, string_agg("users"."email"::text, ' ') AS pg_search_cb8eb1b84bf18ee1412ffd FROM "nodes" INNER JOIN "users" ON "users"."id" = "nodes"."user_id" GROUP BY "nodes"."id") pg_search_4aab10cdca183dac25f479 ON pg_search_4aab10cdca183dac25f479.id = "nodes"."id" LEFT OUTER JOIN (SELECT "nodes"."id" AS id, string_agg("memberships"."relation"::text, ' ') AS pg_search_9474fb5b090e75ade5136f FROM "nodes" INNER JOIN "family_trees" ON "family_trees"."id" = "nodes"."family_tree_id" INNER JOIN "memberships" ON "memberships"."family_tree_id" = "family_trees"."id" GROUP BY "nodes"."id") pg_search_b1bc4c0f44e7f4799d8caf ON pg_search_b1bc4c0f44e7f4799d8caf.id = "nodes"."id" LEFT OUTER JOIN (SELECT "nodes"."id" AS id, string_agg("tags"."name"::text, ' ') AS pg_search_484f77386a5aecc6e01094 FROM "nodes" INNER JOIN "taggings" ON "taggings"."taggable_id" = "nodes"."id" AND "taggings"."taggable_type" = 'Node' AND "taggings"."context" = 'user_tags' INNER JOIN "tags" ON "tags"."id" = "taggings"."tag_id" GROUP BY "nodes"."id") pg_search_93dd21271636bd02b16bc3 ON pg_search_93dd21271636bd02b16bc3.id = "nodes"."id" WHERE (((to_tsvector('english', coalesce("nodes"."name"::text, '')) || to_tsvector('english', coalesce("nodes"."user_id"::text, '')) || to_tsvector('english', coalesce("nodes"."circa"::text, '')) || to_tsvector('english', coalesce("nodes"."cached_tagged_user_names"::text, '')) || to_tsvector('english', coalesce("nodes"."cached_user_tag_list"::text, '')) || to_tsvector('english', coalesce(pg_search_121ea89914a721445aee70.pg_search_344e3c62d13849726da22e::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_acfcdbc0b3d3a65f40eab7::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_eeb842708b24d4f7fcf549::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_cb8eb1b84bf18ee1412ffd::text, '')) || to_tsvector('english', coalesce(pg_search_b1bc4c0f44e7f4799d8caf.pg_search_9474fb5b090e75ade5136f::text, '')) || to_tsvector('english', coalesce(pg_search_93dd21271636bd02b16bc3.pg_search_484f77386a5aecc6e01094::text, ''))) @@ (to_tsquery('english', ''' ' || 'danny' || ' ''' || ':*'))))  ORDER BY pg_search_rank DESC, "nodes"."id" ASC
=> []

请注意,它在查询danny上返回空结果,但在查询dandann上返回正确的记录。

假设字符串是[email protected]danny是该字符串的前缀吗?

请注意,对于电子邮件地址[email protected],搜索abc将返回正确的结果,如下所示:
[188] pry(main)> Node.node_search("abc")
  Node Load (6.9ms)  SELECT "nodes".*, ((ts_rank((to_tsvector('english', coalesce("nodes"."name"::text, '')) || to_tsvector('english', coalesce("nodes"."user_id"::text, '')) || to_tsvector('english', coalesce("nodes"."circa"::text, '')) || to_tsvector('english', coalesce("nodes"."cached_tagged_user_names"::text, '')) || to_tsvector('english', coalesce("nodes"."cached_user_tag_list"::text, '')) || to_tsvector('english', coalesce(pg_search_121ea89914a721445aee70.pg_search_344e3c62d13849726da22e::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_acfcdbc0b3d3a65f40eab7::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_eeb842708b24d4f7fcf549::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_cb8eb1b84bf18ee1412ffd::text, '')) || to_tsvector('english', coalesce(pg_search_b1bc4c0f44e7f4799d8caf.pg_search_9474fb5b090e75ade5136f::text, '')) || to_tsvector('english', coalesce(pg_search_93dd21271636bd02b16bc3.pg_search_484f77386a5aecc6e01094::text, ''))), (to_tsquery('english', ''' ' || 'abc' || ' ''' || ':*')), 0))) AS pg_search_rank FROM "nodes" LEFT OUTER JOIN (SELECT "nodes"."id" AS id, string_agg("comments"."message"::text, ' ') AS pg_search_344e3c62d13849726da22e FROM "nodes" INNER JOIN "comments" ON "comments"."node_id" = "nodes"."id" GROUP BY "nodes"."id") pg_search_121ea89914a721445aee70 ON pg_search_121ea89914a721445aee70.id = "nodes"."id" LEFT OUTER JOIN (SELECT "nodes"."id" AS id, string_agg("users"."first_name"::text, ' ') AS pg_search_acfcdbc0b3d3a65f40eab7, string_agg("users"."last_name"::text, ' ') AS pg_search_eeb842708b24d4f7fcf549, string_agg("users"."email"::text, ' ') AS pg_search_cb8eb1b84bf18ee1412ffd FROM "nodes" INNER JOIN "users" ON "users"."id" = "nodes"."user_id" GROUP BY "nodes"."id") pg_search_4aab10cdca183dac25f479 ON pg_search_4aab10cdca183dac25f479.id = "nodes"."id" LEFT OUTER JOIN (SELECT "nodes"."id" AS id, string_agg("memberships"."relation"::text, ' ') AS pg_search_9474fb5b090e75ade5136f FROM "nodes" INNER JOIN "family_trees" ON "family_trees"."id" = "nodes"."family_tree_id" INNER JOIN "memberships" ON "memberships"."family_tree_id" = "family_trees"."id" GROUP BY "nodes"."id") pg_search_b1bc4c0f44e7f4799d8caf ON pg_search_b1bc4c0f44e7f4799d8caf.id = "nodes"."id" LEFT OUTER JOIN (SELECT "nodes"."id" AS id, string_agg("tags"."name"::text, ' ') AS pg_search_484f77386a5aecc6e01094 FROM "nodes" INNER JOIN "taggings" ON "taggings"."taggable_id" = "nodes"."id" AND "taggings"."taggable_type" = 'Node' AND "taggings"."context" = 'user_tags' INNER JOIN "tags" ON "tags"."id" = "taggings"."tag_id" GROUP BY "nodes"."id") pg_search_93dd21271636bd02b16bc3 ON pg_search_93dd21271636bd02b16bc3.id = "nodes"."id" WHERE (((to_tsvector('english', coalesce("nodes"."name"::text, '')) || to_tsvector('english', coalesce("nodes"."user_id"::text, '')) || to_tsvector('english', coalesce("nodes"."circa"::text, '')) || to_tsvector('english', coalesce("nodes"."cached_tagged_user_names"::text, '')) || to_tsvector('english', coalesce("nodes"."cached_user_tag_list"::text, '')) || to_tsvector('english', coalesce(pg_search_121ea89914a721445aee70.pg_search_344e3c62d13849726da22e::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_acfcdbc0b3d3a65f40eab7::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_eeb842708b24d4f7fcf549::text, '')) || to_tsvector('english', coalesce(pg_search_4aab10cdca183dac25f479.pg_search_cb8eb1b84bf18ee1412ffd::text, '')) || to_tsvector('english', coalesce(pg_search_b1bc4c0f44e7f4799d8caf.pg_search_9474fb5b090e75ade5136f::text, '')) || to_tsvector('english', coalesce(pg_search_93dd21271636bd02b16bc3.pg_search_484f77386a5aecc6e01094::text, ''))) @@ (to_tsquery('english', ''' ' || 'abc' || ' ''' || ':*'))))  ORDER BY pg_search_rank DESC, "nodes"."id" ASC
=> [#<Node id: 85, name: "House Fire 2", family_tree_id: 57, user_id: 57, media_id: 228, media_type: "Video", created_at: "2015-05-15 00:20:26", updated_at: "2015-06-08 22:25:49", circa: nil, is_comment: nil, cached_votes_total: 0, cached_votes_score: 0, cached_votes_up: 0, cached_votes_down: 0, cached_weighted_score: 0, cached_weighted_total: 0, cached_weighted_average: 0.0, cached_user_tag_list: "[email protected], [email protected]", cached_num_user_tags: 2, cached_tagged_user_names: ["Daniel Marty", "Marcamus Prime"]>,
 #<Node id: 86, name: "10PP Form Video", family_tree_id: 57, user_id: 57, media_id: 229, media_type: "Video", created_at: "2015-05-15 01:26:28", updated_at: "2015-06-05 21:10:09", circa: nil, is_comment: nil, cached_votes_total: 1, cached_votes_score: 1, cached_votes_up: 1, cached_votes_down: 0, cached_weighted_score: 1, cached_weighted_total: 1, cached_weighted_average: 0.0, cached_user_tag_list: "[email protected]", cached_num_user_tags: 1, cached_tagged_user_names: ["Gerry  Atrick"]>]

这可能是什么原因?

编辑1

为了使事情更奇怪,我认为可能是@可以摆脱前缀搜索,因此我通过简单地将cached_user_tag_list的属性从[email protected]更改为[email protected]进行了测试。然后,我搜索了dannyk,它返回了正确的结果,但是当我搜索danny时,它仍然返回[]。我不知道为什么。

最佳答案

您可以打开:trigram search并指定阈值。它匹配出现在可搜索文本中任意位置的任意子字符串。
您的最终代码将如下所示。

pg_search_scope :node_search, against: [:name, :user_id, :circa, :cached_tagged_user_names, :cached_user_tag_list],
     using: { tsearch: { any_word: true, dictionary: :english, prefix: true}, :trigram => { :threshold => 0.1 }  },
        :associated_against => {
          comments: [:message],
          user: [:first_name, :last_name, :email],
          memberships: [:relation],
          user_tags: [:name]
        }

09-26 05:06