Пример #1
0
 public function search($fields, $text)
 {
     static $min_word_len = 0;
     /*
     # Short words are ignored, the default minimum length is 4 characters. You can change the min and max word length with the variables ft_min_word_len and ft_max_word_len
     # Words called stopwords are ignored, you can specify your own stopwords, but default words include the, have, some - see default stopwords list.
     # You can disable stopwords by setting the variable ft_stopword_file to an empty string.
     */
     if (!$min_word_len) {
         $min_word_len = u_fetch_row('SHOW VARIABLES LIKE \'ft_min_word_len\'');
         $min_word_len = max(intval($min_word_len[0]), 3);
     }
     preg_match_all('#[^\\s]{' . $min_word_len . ',}#', $text, $text);
     return ' MATCH(' . implode(',', $fields) . ') AGAINST(' . $this->quote(implode(' ', $text[0])) . ') ';
     $text = Poodle_Unicode::as_search_txt($text);
     $prefix = $this->server_info < 8.300000000000001 ? "'default'," : '';
     //		$searchstring = $this->parseQuery($text);
     # We need a separate query here so gin does not complain about empty searches
     $res = pg_query($this->connection, "SELECT to_tsquery({$prefix} {$text})");
     if (!$res) {
         Poodle_Report::error('Sorry, that was not a valid search string. Please go back and try again');
     }
     $top = pg_fetch_result($res, 0, 0);
     # e.g. if only stopwords are used XXX return something better
     if (!$top) {
         $query = "SELECT page_id, page_namespace, page_title, 0 AS score " . "FROM page p, revision r, pagecontent c WHERE p.page_latest = r.rev_id " . "AND r.rev_text_id = c.old_id AND 1=0";
     } else {
         $m = array();
         if (preg_match_all("/'([^']+)'/", $top, $m, PREG_SET_ORDER)) {
             foreach ($m as $terms) {
                 $this->searchTerms[$terms[1]] = $terms[1];
             }
         }
         $score = $this->server_info > 8.199999999999999 ? 5 : 1;
         $rank = $this->server_info < 8.300000000000001 ? 'rank' : 'ts_rank';
         $query = "SELECT page_id, page_namespace, page_title, " . "{$rank}({$fulltext}, to_tsquery({$prefix} {$searchstring}), {$score}) AS score " . "FROM page p, revision r, pagecontent c WHERE p.page_latest = r.rev_id " . "AND r.rev_text_id = c.old_id AND {$fulltext} @@ to_tsquery({$prefix} {$searchstring})";
     }
     ## Redirects
     if (!$this->showRedirects) {
         $query .= ' AND page_is_redirect = 0';
     }
     ## Namespaces - defaults to 0
     if (!is_null($this->namespaces)) {
         // null -> search all
         if (count($this->namespaces) < 1) {
             $query .= ' AND page_namespace = 0';
         } else {
             $namespaces = implode(',', $this->namespaces);
             $query .= " AND page_namespace IN ({$namespaces})";
         }
     }
     $query .= " ORDER BY score DESC, page_id DESC";
     $query .= $this->db->limitResult('', $this->limit, $this->offset);
     return $query;
 }
Пример #2
0
 public function search(array $fields, &$text)
 {
     static $min_word_len = 0;
     /*
      * Short words are ignored, the default minimum length is 4 characters. You can change the min and max word length with the variables ft_min_word_len and ft_max_word_len
      * Words called stopwords are ignored, you can specify your own stopwords, but default words include the, have, some - see default stopwords list.
      * You can disable stopwords by setting the variable ft_stopword_file to an empty string.
      * http://dev.mysql.com/doc/refman/5.1/en/fulltext-stopwords.html
      */
     if (!$min_word_len) {
         mysqli_report(MYSQLI_REPORT_OFF);
         if ($res = parent::query('SHOW VARIABLES LIKE \'ft_min_word_len\'')) {
             $min_word_len = $res->fetch_row();
             $min_word_len = intval($min_word_len[1]);
             $res->free();
         }
         mysqli_report(MYSQLI_REPORT_ERROR);
         $min_word_len = max($min_word_len, 3);
     }
     $text = Poodle_Unicode::as_search_txt($text);
     if (preg_match_all('#[^\\s]{' . $min_word_len . ',}#', $text, $match)) {
         $text = $match[0];
     }
     return ' MATCH (' . implode(',', $fields) . ') AGAINST (\'' . parent::escape_string(implode(' ', $text)) . '\') ';
 }