title: How can I do wildcarded search on encrypted elements in database
body: <p>I am using attr_encrypted to encrypt some of my model fields, and I use Tire with Elasticsearch for full text searching. I use just a simple search form.
  here is part of my model:</p>
  
  <pre><code>class Student &lt; ActiveRecord::Base
  
    include Tire::Model::Search
    include Tire::Model::Callbacks
  
    attr_accessible :name, :surname
    attr_encrypted :name,             :key =&gt; 'f98gd9regre9gr9gre9gerh'
    attr_encrypted :surname,          :key =&gt; 'f98gd9regre9gr9gre9gerh'
  
    def self.search(params)
      tire.search(load: true) do
        query { string Student.encrypt_name(params[:search]) } if params[:search].present?
      end  
    end
  end
  </code></pre>
  
  <p>So, for example, if I have the name "John" in the database, when I search for "John" the query is encrypted (Student.encrypt_name(params[:search])) before querying the database, and the result is returned. Elasticsearch allows wildcarded searching, for example if I search "Joh*", should return the matched result, but encrypted keyword "Joh" is different from encrypted "John", and db returns no result. Any solutions on this would be appreciated.</p>
  
  <p>Regards,
  Radoslav</p>