title: How to make a fast ajax live search
body: <p>Hi, im trying to do a ajax live search. It work`s, but i want it to be fast. Currently i`m processing the html by php, but even if i change the processing to js and only get the data from php it only improves my search from 2.1 to 1.8 seconds (this is the request time, but it takes 4/5 seconds for the data to appear) </p>
  
  <p>Heres my code: </p>
  
  <pre><code>$("#searchfield").change(function() {
      term = $(this).val();
      if (searchReq != false) {
      searchReq.abort();
      }
      searchReq = $.get("/searchModal.php", {
          term : term
      }).done(function(data) {
          $("#liveSearch").html(data);
      });
  
  });
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>php code:</p>
  
  <p>search.php:</p>
  
  <pre><code>$files = filecontroller::search($term);
  </code></pre>
  
  <p>file controller:</p>
  
  <pre><code>public static function search($term, $by = false, $order = false) {
      connection::connect();
  
      $files = ($by &amp;&amp; $order &amp;&amp; validation::filesOrder($by, $order)) ? file::Search($term, $by, $order) : file::Search($term);
  
      return $files;
  }
  </code></pre>
  
  <p>File model:</p>
  
  <pre><code>public static function Search($term, $by = 'date', $order = 'DESC') {
  
      $session_id = $_SESSION["user_id"];
      $term = mysql_real_escape_string($term);
      $query = mysql_query("SELECT * FROM files WHERE idUser = '$session_id' AND (name LIKE '%$term%' OR description LIKE '%$term%') ORDER BY $by $order");
  
      $files = self::CreateFromDb($query);
      return $files;
  
  }
  
  private static function CreateFromDb($query) {
      GLOBAL $imgDir; // just get the img dir from a config file
      GLOBAL $userDir; // same
      $files = array();
      while ($row = mysql_fetch_assoc($query)) {
  
          $file = new File();
          $file -&gt; type = $row['type'];
  
          $file -&gt; idFile = $row['idFile'];
          $file -&gt; user = $row['idUser'];
          $file -&gt; gallery = $row['idGallery'];
          $file -&gt; name = htmlspecialchars($row['name']);
          $file -&gt; description = htmlspecialchars($row['description']);
          $file -&gt; date = $file -&gt; timecheck($row['date']);
          $file -&gt; size['kb'] = $row['size'];
          $file -&gt; galleryName = Gallery::getName($file -&gt; gallery);
  
          $files[] = $file;
      }
  
      return $files;
  }
  </code></pre>
  
  <p>Is there anyway to improve it? Im testing in local.</p>