code: private void checkRewritten(IndexReader reader) throws IOException
     {
        if (!rewritten)
        {
           IndexReader r = reader;
           if (r == null)
           {
              r = index.getIndexReader();
           }
           try
           {
              query = query.rewrite(r);
           }
           finally
           {
              // only close reader if this method opened one
              if (reader == null)
              {
                 Util.closeOrRelease(r);
              }
           }
           rewritten = true;
        }
     }
docs: Makes sure the {@link #query} is rewritten. If the query is already
  rewritten, this method returns immediately.
  
  @param reader an optional index reader, if none is passed this method
  will retrieve one from the {@link #index} and close it
  again after the rewrite operation.
  @throws IOException if an error occurs while the query is rewritten.