예제 #1
0
function _run_query($query)
{
    for ($i = 0; $i < vBSphinxSearch_Core::RECONNECT_LIMIT; $i++) {
        $con = vBSphinxSearch_Core::get_sphinxql_conection();
        if (false != $con) {
            $result_res = mysql_query($query, $con);
            if ($result_res) {
                $table_str = '<table id="results" name="results" border="1">';
                while ($docinfo = mysql_fetch_assoc($result_res)) {
                    // не эстетично, но быстро
                    $link = '';
                    if (isset($docinfo['primaryid'])) {
                        $thread['threadid'] = $docinfo['groupid'];
                        $thread['postidid'] = $docinfo['primaryid'];
                        $link = '<a href="' . fetch_seo_url('thread', $thread) . '#post' . $thread['postidid'] . '">' . $thread['postidid'] . '<a>';
                        $docinfo = array_merge(array('link' => $link), $docinfo);
                    }
                    $head = '<tr><td>' . implode('</td><td>', array_keys($docinfo)) . '</td></tr>';
                    $entry .= '<tr><td>' . implode('</td><td>', $docinfo) . '</td></tr>';
                }
                $table_str .= $head . $entry . '</table>';
                echo $table_str;
                return true;
            }
            echo 'Нет результатов<br />';
        }
    }
    echo 'Ошибка: <br />' . mysql_error() . '<br />';
    return false;
}
예제 #2
0
 /**
  * Fetch list of ids by group_id. (For example - all posts by thread id)
  * 
  * Attention(!) Selection by pure attributes is ineffective in sphinx.
  * There will be problems for mass threads rebuild.
  * 
  * This code is for compatibility reasons, if optimised version
  * not implementer in index controler
  */
 protected function _fetch_object_id_list($group_id, $only_first = false)
 {
     if (is_null($this->_content_type_id) or 0 == (int) $group_id) {
         return false;
     }
     $indexes = implode(",", vBSphinxSearch_Core::get_sphinx_index_map($this->_content_type_id));
     if (empty($indexes)) {
         return false;
     }
     $limit = vBSphinxSearch_Core::SPH_DEFAULT_RESULTS_LIMIT;
     $query = 'SELECT *
                 FROM 
                     ' . $indexes . '
                 WHERE
                     contenttypeid = ' . $this->_content_type_id . ' AND
                     groupid = ' . $group_id . ($only_first ? ' AND isfirst = 1' : '') . '
                 LIMIT ' . $limit . ' OPTION max_matches=' . $limit;
     $this->_id_list = array();
     for ($i = 0; $i < vBSphinxSearch_Core::SPH_RECONNECT_LIMIT; $i++) {
         $con = vBSphinxSearch_Core::get_sphinxql_conection();
         if (false != $con) {
             $result_res = mysql_query($query, $con);
             if ($result_res) {
                 while ($docinfo = mysql_fetch_assoc($result_res)) {
                     $this->_id_list[] = $docinfo['primaryid'];
                 }
                 return true;
             }
         }
     }
     $error = mysql_error();
     $message = "\n\nSphinx: Can't get primaryid list for groupid={$group_id}\nUsed indexes: {$indexes}\n Error:\n{$error}\n";
     vBSphinxSearch_Core::log_errors($message);
     return false;
 }
 /**
  * Run query & transform result to vBulletin format
  * 
  * Note: Blogs have unique result format. I think, system architect
  * should die or stop prorgamming.
  *
  */
 protected function _run_query($query, $show_errors = false)
 {
     // Hack to fix blog search result (part 1)
     // Big brother will look for this content types in result,
     // to update data
     $blog_content_type_ids = array(vB_Types::instance()->getContentTypeId('vBBlog_BlogEntry'), vB_Types::instance()->getContentTypeId('vBBlog_BlogComment'));
     // Connect to sphinx & get result
     for ($i = 0; $i < vBSphinxSearch_Core::SPH_RECONNECT_LIMIT; $i++) {
         $con = vBSphinxSearch_Core::get_sphinxql_conection();
         if (false != $con) {
             $result_res = mysql_query($query, $con);
             if ($result_res) {
                 while ($docinfo = mysql_fetch_assoc($result_res)) {
                     unset($row);
                     /* Hack to update blog results (uses different format, part 2)
                      * 
                      * blog row content:
                      * 
                      *   contenttypeid,
                      *   primaryid,
                      *   groupid,
                      *   empty_string
                      * 
                      * other results:
                      * 
                      *   contenttypeid,
                      *   groupid,
                      *   empty_string
                      * 
                      * For blog, contenttypeid should be always Blog Entry, because
                      * View does not support comments display as 'posts'
                      * 
                      */
                     if (in_array($docinfo['contenttypeid'], $blog_content_type_ids)) {
                         $row[] = $blog_content_type_ids[0];
                     } else {
                         $row[] = $docinfo['contenttypeid'];
                         $row[] = $docinfo['primaryid'];
                     }
                     $row[] = $docinfo['groupid'];
                     $row[] = '';
                     $result[] = $row;
                 }
                 return $result;
             }
         }
     }
     $this->add_error(mysql_error(), $query);
     if ($show_errors) {
         $error_message_id = 'sph_invalid_query';
         if (vBSphinxSearch_Core::SPH_CONNECTION_ERROR_NO == mysql_errno()) {
             $error_message_id = 'sph_connection_error';
         }
         global $vbulletin;
         eval(standard_error(fetch_error($error_message_id, $vbulletin->options['contactuslink'])));
     }
     return array();
 }