title: Postgresql 9.4: index not working in a pattern search
body: <p>I have a table called "doctors" and a field called "fullname" which will store names with accents.
  What I need to do is an "accent insensitive + case insensitive" search, something like:</p>
  
  <pre><code>SELECT * 
  FROM doctors
  WHERE unaccent_t(fullname) ~* 'unaccented_and_lowercase_string';
  </code></pre>
  
  <p>where the value to search will come unaccented+lowercase and unaccent_t is a function defined as:</p>
  
  <pre><code>CREATE FUNCTION unaccent_t(text, lowercase boolean DEFAULT false)
  RETURNS text AS
  $BODY$
  SELECT CASE
    WHEN $2 THEN unaccent('unaccent', lower(trim($1)))
    ELSE unaccent('unaccent', trim($1))
  END;
  $BODY$ LANGUAGE sql IMMUTABLE SET search_path = public, pg_temp;
  </code></pre>
  
  <p>(I already installed 'unaccent' extension).</p>
  
  <p>So, I went ahead and created the index for "fullname" field:</p>
  
  <pre><code>CREATE INDEX doctors_fullname ON doctors (unaccent_t(fullname) text_pattern_ops);
  </code></pre>
  
  <p>(I also tried with varchar_pattern_ops and also no specifying ops at all)</p>
  
  <p>In the doctors table, I have around 15K rows.</p>
  
  <p>The query works and I get the expected results, but when I add the <code>explain analyze</code> to the query, I don't see that the index is used:</p>
  
  <pre><code>Seq Scan on doctors  (cost=0.00..4201.76 rows=5 width=395) (actual time=0.282..182.025 rows=15000 loops=1)
    Filter: (unaccent_t((fullname)::text, false) ~* 'garcia'::text)
    Rows Removed by Filter: 1
  Planning time: 0.207 ms
  Execution time: 183.387 ms
  </code></pre>
  
  <p>I also tried removing the optional parameter from unaccent_t but I got the same results.</p>
  
  <p>In a scenario like this, how should I define the index so it gets used in a query like the one above?</p>