/** * @param string $word * @return int */ public function getId($word) { if (isset(self::$words_cache[$word])) { return self::$words_cache[$word]; } if (mb_strlen($word) > 255) { $word = mb_strlen($word, 0, 255); } $sql = "SELECT * FROM " . $this->table . " WHERE name LIKE '" . $this->escape($word, 'like') . "'"; $row = $this->query($sql)->fetch(); if ($row) { $id = $row['id']; } else { $id = $this->insert(array('name' => $word), 2); } if (count(self::$words_cache) > 5000) { self::$words_cache = array(); } if ($id) { self::$words_cache[$word] = $id; } return $id; }
public function search($query) { $word_model = new shopSearchWordModel(); $word_ids = $word_model->getByString($query); $result = array(); $result['joins'] = array(array('table' => 'shop_search_index', 'alias' => 'si')); $result['where'] = array('si.word_id IN (' . implode(",", $word_ids) . ')'); if (count($word_ids) > 1) { $result['fields'] = array("SUM(si.weight) AS weight"); $result['order_by'] = 'weight DESC'; $result['group_by'] = 'p.id'; } else { $result['fields'] = array("si.weight"); $result['order_by'] = 'si.weight DESC'; } return $result; }