我在使用CodeIgniter进行全文搜索时遇到了问题。在这里,我有一个动态行和列的表,当我使用全文索引搜索输入字段到一行非常缓慢。这里已经将以下值设置为数据库引擎作为MYISAM,将表列设置为FULLTEXT INDEX。我希望输入字段中的数据非常快。我附上了我累了的东西。请检查并告诉我。
public function product_autocomplete()
{
$name_startsWith = $_POST['name_startsWith'];
$type = $_POST['type'];
$row_num = $_POST['row_num'];
$this->db->like('item_number', $name_startsWith);
$query = $this->db->select('item_id,item_number,name,tax_included,cost_price,categoryid,unit_price,supplier_id,quantity_received')
->from('bgs_items')
->where('MATCH (bgs_items.item_number) AGAINST ("'. $name_startsWith .'")', NULL, false)
->limit(10)
->get();
$data = array();
foreach ($query->result_array() as $row)
{
$name = $row['item_number']."-".$row['name'].'|'.$row['name'].'|'.$row['tax_included'].'|'.$row['cost_price'].'|'.$row['categoryid'].'|'.$row['unit_price'].'|'.$row['supplier_id'].'|'.$row['quantity_received'].'|'.$row['item_number'].'|'.$row['item_id'].'|'.$row['supplier_id'].'|'.$row_num;
array_push($data, $name);
}
echo json_encode($data);
}
答案 0 :(得分:0)
请尝试使用以下查询
public function product_autocomplete()
{
$name_startsWith = $_POST['name_startsWith'];
$type = $_POST['type'];
$row_num = $_POST['row_num'];
$query = $this->db->select('item_id,item_number,name,tax_included,cost_price,categoryid,unit_price,supplier_id,quantity_received')
->from('bgs_items')
->where('MATCH (bgs_items.item_number) AGAINST ("'. $name_startsWith .'")', NULL, false)
->limit(10)
->get();
$data = array();
foreach ($query->result_array() as $row)
{
$name = $row['item_number']."-".$row['name'].'|'.$row['name'].'|'.$row['tax_included'].'|'.$row['cost_price'].'|'.$row['categoryid'].'|'.$row['unit_price'].'|'.$row['supplier_id'].'|'.$row['quantity_received'].'|'.$row['item_number'].'|'.$row['item_id'].'|'.$row['supplier_id'].'|'.$row_num;
array_push($data, $name);
}
echo json_encode($data);
}