title: Smart search with one input
body: <p>I have been browsing some social network, and found there an ability to search person by: name, age range, city, country and gender.
  The interesting thing is all this info may be inserted into one textbox separated by space. Then the search engine some how parses it in very accurate way and return a result list.</p>
  
  <p>On one hand it seems pretty simple: split query by space and search all relevant tables for occurrence. So far so good. 
  However </p>
  
  <ol>
  <li>There are cities which names are more than 2 words and user may enter them <strong>differently</strong> as it is free text.</li>
  <li>There are names that are more than 2 words</li>
  </ol>
  
  <p><strong>Question:</strong></p>
  
  <p>How can we split the query in such way, that we certainly know which
      part of it should be searched where? i.e. name in user table, city
      in cities table, country in countries etc.?</p>
  
  <p>What i have done so far is: <br></p>
  
  <ol>
  <li>fill users datasource with all the users</li>
  <li>Check if Country from Countries tableexist in the query</li>
  <li>if exist then filter datasource to have users from that country only</li>
  <li>Check if  from Cities table exist in the query</li>
  <li>if exist then filter datasource to have users from that city only</li>
  </ol>
  
  <p>and so on for each table, while each time we find a match in the table- we remove the found part from the query, leaving us with the most free parameter: <b>the name</b>.</p>
  
  <p>This seems to work if user would have known exactly how the cities/ countries etc. are written in my db,
  but the reality is that user may enter a part of the city or mistype the city. <br><br>
  I don't know if i am in the right direction at all with what i have done. Is just a point of start... </p>
  
  <p>PS: I just need an algorithm flow, so programming language doesn't really meters. Any Idea or guidance is more than welcome.</p>
  
  <p>Thanks </p>