function total_matches($currindex, $arr, $short_or_long) { $percents = array(); foreach ($arr as $key => $value) { if ($key != $currindex) { if (isset($value['short'])) { $percents[] = leven_algoritm($arr[$currindex][$short_or_long], $value['short']); } if (isset($value['long'])) { $percents[] = leven_algoritm($arr[$currindex][$short_or_long], $value['long']); } } } if (!empty($percents)) { return max($percents); } return false; }
public function getByProductName($im_data_id, $selected_product_name = '', $manufacturer = '', $strict = false) { $special_list = array('mixer', 'oven', 'masher', 'extractor', 'maker', 'cooker', 'tv', 'laptop', 'belt', 'blender', 'tablet', 'toaster', 'kettle', 'watch', 'sneakers', 'griddle', 'grinder', 'camera'); $this->db->from($this->tables['imported_data_parsed'] . ' as p'); if ($strict) { $this->db->like('p.product_name', '"' . $manufacturer . '"'); $this->db->or_like('p.parsed_attributes', '"' . $manufacturer . '"'); $this->db->or_like('p.url', '"' . $manufacturer . '"'); } else { $this->db->like('p.product_name', $manufacturer); $this->db->or_like('p.parsed_attributes', $manufacturer); $this->db->or_like('p.url', $manufacturer); } $query = $this->db->get(); if ($query->num_rows() > 0) { $results = $query->result_array(); $data = array(); $for_groups = array(); foreach ($results as $key => $result) { if ($key == 'url') { if ($results['imported_data_id'] == $im_data_id) { $selected_url = $result; } $data[$results['imported_data_id']]['url'] = $result; } if ($key == 'parsed_attributes') { $data[$results['imported_data_id']]['parsed_attributes'] = unserialize($result); } $data[$results['imported_data_id']][$key] = $result; } $urls = array($this->get_base_url($selected_url)); $for_groups[] = $im_data_id; $selected_product = ''; foreach ($special_list as $product) { if (substr_count(strtolower($selected_product_name), $product) > 0) { $selected_product = $product; break; } } foreach ($data as $key => $val1) { if ($selected_product != '' && substr_count(strtolower($val1['product_name']), $selected_product) <= 0) { continue; } if ($selected_product == '') { $other_product = false; foreach ($special_list as $product) { if (substr_count(strtolower($val1['product_name']), $product) > 0) { $other_product = true; break; } } if ($other_product) { continue; } } if (isset($val1['product_name']) && isset($val1['url'])) { if ($key == $im_data_id) { //$for_groups[] = $key; } else { if (!in_array($this->get_base_url($val1['url']), $urls)) { if (isset($val1['parsed_attributes']['manufacturer'])) { if (preg_match('/' . $val1['parsed_attributes']['manufacturer'] . '/', $selected_product_name)) { if (leven_algoritm(strtolower($val1['product_name']), strtolower($selected_product_name)) > 37) { $urls[] = $this->get_base_url($val1['url']); $for_groups[] = $key; } } } else { if (leven_algoritm(strtolower($val1['product_name']), strtolower($selected_product_name)) > 37) { $urls[] = $this->get_base_url($val1['url']); $for_groups[] = $key; } } } } } } } $data1 = array(); foreach ($for_groups as $key => $result) { $this->db->select('imported_data_id,description,long_description,url,product_name,features'); $this->db->where('imported_data_id', $result); $query = $this->db->get($this->tables['imported_data_parsed']); if ($query->num_rows() > 0) { $data1[$key] = $query->result_array(); if ($key == 'url') { if ($data1[$key]['imported_data_id'] == $im_data_id) { $selected_url = $result; } $data[$data1[$key]['imported_data_id']]['url'] = $result; } } } if ($data1) { $rows = $data1; $customers_list = array(); $query_cus = $this->db->order_by('name', 'asc')->get($this->tables['customers']); $query_cus_res = $query_cus->result(); if (count($query_cus_res) > 0) { foreach ($query_cus_res as $key => $value) { $n = parse_url($value->url); $customers_list[] = $n['host']; } } $customers_list = array_unique($customers_list); foreach ($rows as $key => $row) { $cus_val = ""; foreach ($customers_list as $ki => $vi) { if (strpos($rows[$key]['url'], "{$vi}") !== false) { $cus_val = $vi; } } if ($cus_val !== "") { $rows[$key]['customer'] = $cus_val; } } $ids = array(); $this->load->model('similar_product_groups_model'); if (!$this->similar_product_groups_model->checkIfgroupExists($im_data_id)) { $this->db->insert('similar_product_groups', array('ipd_id' => $im_data_id)); foreach ($for_groups as $id) { $this->db->insert('similar_data', array('group_id' => $im_data_id, 'black_list' => 0, 'imported_data_id' => $id)); } } return $rows; } }