Exemplo n.º 1
0
 public function getIds($words, $by_part = 0)
 {
     $where = array();
     foreach ($words as $w) {
         $w = trim($w);
         if ($w) {
             $w = shopSearch::stem($w);
             $where[] = "name LIKE '" . $this->escape($w, 'like') . ($by_part && mb_strlen($w) >= $by_part ? '%' : '') . "'";
         }
     }
     if ($where) {
         $sql = "SELECT id FROM " . $this->table . " WHERE " . implode(' OR ', $where);
         return $this->query($sql)->fetchAll(null, true);
     }
     return array();
 }
Exemplo n.º 2
0
 public function getWordIds($string, $only_exist = false)
 {
     $words = preg_split("/([\\s,;:]+|[\\.!\\?](\\s+|\$))/su", $string, null, PREG_SPLIT_NO_EMPTY);
     $additional_words = array();
     foreach ($words as $i => $w) {
         if ($this->options['ignore']) {
             $clear_w = str_replace($this->options['ignore'], '', $w);
         } else {
             $clear_w = $w;
         }
         if ($clear_w) {
             $words[$i] = mb_strtolower($clear_w);
             if ($word_forms = $this->getWordForms($words[$i], $only_exist)) {
                 $additional_words = array_merge($additional_words, $word_forms);
             }
         } else {
             unset($words[$i]);
         }
     }
     if ($additional_words) {
         $words = array_merge($words, $additional_words);
     }
     $words = array_unique($words);
     $result = array();
     $word_model = $this->getWordModel();
     if ($only_exist) {
         return $word_model->getIds($words, $this->options['by_part']);
     }
     foreach ($words as $w) {
         if ($w) {
             if ($w_id = $word_model->getId(shopSearch::stem($w))) {
                 $result[] = $w_id;
             }
         }
     }
     return array_unique($result);
 }