search result not in prioritize order drupal 7 Hi i am new to drupal 7 and also to sql query builder format.i have a requirement to search the string. in that i hav to display exact matched string at the top followed by related matches. i explode a string with space and searched a each word exist or not.the code as follows.

$keys -> contain the search term

 $keys = preg_replace('!\*+!', '%', $keys);

$keys = explode(' ', trim(str_replace(array( '\'', '"', ',' , ';', '&lt;', '&gt;','!','_','-','+','@','#','$','%','^','&amp;','.'), ' ', $keys)));;

 $query = db_select('file')-&gt;extend('PagerDefault');
 $query-&gt;fields('file', array('fid','filename'))
  -&gt;fields('fs', array('e_id','f_subtitle_value'));

 $subquery = db_select('field_data_sub','fs');
 $subquery-&gt;Fields('fs', array('e_id','f_subtitle_value'));
 $subquery-&gt;condition('fs.e_type', 'node','!=');

 $query-&gt;leftjoin($subquery,'fs','file.fid = fs.e_id');
 $db_or = db_or();
foreach ($keys as $key) {
if(!(empty($key))) {
 $db_or-&gt;condition('filename', "%$key%", 'LIKE');
 }
}

$query-&gt;condition($db_or); 
  $query-&gt;condition(db_and()-&gt;
          condition('filemime', 'image/jpeg', '!=')-&gt;
           condition('filemime', 'image/png', '!='));


i tried union all - wrote two query and combine it.. it fetches output but the exact searched result came twice . is that a gud way or else is there any other way.. please suggest the best way :)
You can use default drupal's search from admin/config/search/settings and se Views module for searching specific fields. You need not write any code or Query to search in a Drupal site unless it is needed.