Casecommons / pg_search

pg_search builds ActiveRecord named scopes that take advantage of PostgreSQL’s full text search
http://www.casebook.net
MIT License
1.31k stars 369 forks source link

Rails 7 encryption column is not working with pg_search #486

Closed sulmanweb closed 2 years ago

sulmanweb commented 2 years ago

I have user model:

class User < ApplicationRecord
  include PgSearch::Model
  encrypts :email, deterministic: true

  pg_search_scope :search_user, against: { email: 'A', name: 'B' }, using: {
    tsearch: { prefix: true }
  }

then User.search_user doesn't find the user with exact email but finds with name. If I remove encryption then it works fine.

james-em commented 2 years ago

I believe this would be the expected behavior because the search happens at SQL level and the data is encrypted in database.

nertzy commented 2 years ago

Yes, there is no reasonable way to search encrypted data.

You could store a tsvector column with the text to the side of your column, but that would defeat the point of encryption.