how to implement search in codeigniter

$_searchfield = $_REQUEST['key'];
$_searchfield = str_replace("'", "", $_searchfield);

$query = $this->db->query("SELECT * FROM td_product WHERE active=1 AND product_code like '$_searchfield'
 UNION 
 SELECT * FROM td_product WHERE active=1 AND product_title like '%$_searchfield%'
 UNION 
 SELECT * FROM td_product WHERE active=1 AND product_keyword like '%$_searchfield%'
 UNION 
 SELECT * FROM td_product WHERE active=1 AND product_desc like '%$_searchfield%' limit 20");

 $search_list = $query->result_array();
 $total_search = $query->num_rows();