title: Improve results of a "search" input field?
body: <p>I have a database with 20,000 records. Each record has a name. When a user wants to view a record, he can visit a webapp and type the name of the record in an inputfield. While typing, results from the database would be shown/filtered matchin what the user typed. I would like to know the basic architecture/concepts on how to program this</p>
  
  <p>I'm using the following language stack:
  frontend: html5/javascript (+ajax to make instant calls while user is typing)
  backend: java + jdbc to connect to simple sql database</p>
  
  <p>My initial idea is:</p>
  
  <ol>
  <li>A user types text</li>
  <li>Whenever a character is entered or removed in the inputfield, make an ajax request to the backend</li>
  <li>The backend does a LIKE %input% query on the name field in the database</li>
  <li>All data found by the query is send as a json string to the frontend</li>
  <li>The frontend processes the json string and displays whatever results it finds</li>
  </ol>
  
  <p>My two concerns are: the high amount of ajax requests to process, in conjunction with the possibly very heavy LIKE queries. What are ways to optimize this? Only search for every two characters they type/remove? Only query for the first ten results? </p>
  
  <p>Do you know of websites that utilise these optimizations?</p>
  
  <p>NOTE: assume the records are persons and names are like real people names, so some names are more common than others.</p>