How to perform a wildcard search on encrypted items in a database

I use attr_encrypted to encrypt some of my model fields, and I use Tire with Elasticsearch for full-text search. I use a simple search form. here is part of my model:

class Student < ActiveRecord::Base

  include Tire::Model::Search
  include Tire::Model::Callbacks

  attr_accessible :name, :surname
  attr_encrypted :name,             :key => 'f98gd9regre9gr9gre9gerh'
  attr_encrypted :surname,          :key => 'f98gd9regre9gr9gre9gerh'

  def self.search(params)
    tire.search(load: true) do
      query { string Student.encrypt_name(params[:search]) } if params[:search].present?
    end  
  end
end

So, for example, if I have the name “John” in the database, when I search for “John”, the request is encrypted (Student.encrypt_name (params [: search])) before querying the database, and the result is returned. Elasticsearch allows you to search for a wildcard search, for example, if I search for "Joh *", it should return a consistent result, but the encrypted keyword "Joh" is different from the encrypted "John", and db does not return the result. Any decisions on this will be appreciated.

,

+5
2

- .

:

  • soundex . , . , .

  • (, , ) , , ( ). , google " " " ", . , .

  • , .

+2

, , - . , :

  • ~ 1000 .
  • - ,
  • ,

, - . .

0

All Articles