当前位置: 首页>>代码示例>>PHP>>正文


PHP SphinxClient::GetLastError方法代码示例

本文整理汇总了PHP中SphinxClient::GetLastError方法的典型用法代码示例。如果您正苦于以下问题:PHP SphinxClient::GetLastError方法的具体用法?PHP SphinxClient::GetLastError怎么用?PHP SphinxClient::GetLastError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SphinxClient的用法示例。


在下文中一共展示了SphinxClient::GetLastError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: search

 /**
  * Search in sphinx client
  *
  * @param string $query
  * @param string $index
  * @return SphinxResult|string
  * @throws \Exception
  */
 public function search($query, $index = '*')
 {
     $result = $this->_sphinx_client->Query($query, $index);
     if (!$result) {
         throw new \Exception("Sphinx client error: " . $this->_sphinx_client->GetLastError());
     } else {
         if (!empty($result['warning'])) {
             return $this->_sphinx_client->GetLastWarning();
         }
         return new SphinxResult($result);
     }
 }
开发者ID:triadev,项目名称:sphinx-silex-service,代码行数:20,代码来源:SphinxAdapter.php

示例2: searchTasks

 /**
  *
  * @param string $query
  * @return array of integers - taskIds
  */
 public static function searchTasks($query)
 {
     $fieldWeights = array('description' => 10, 'note' => 6);
     $indexName = 'plancake_tasks';
     $client = new SphinxClient();
     // $client->SetServer (sfConfig::get('app_sphinx_host'), sfConfig::get('app_sphinx_port'));
     $client->SetFilter("author_id", array(PcUserPeer::getLoggedInUser()->getId()));
     $client->SetConnectTimeout(1);
     $client->SetMatchMode(SPH_MATCH_ANY);
     $client->SetSortMode(SPH_SORT_RELEVANCE);
     $client->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
     $client->SetArrayResult(true);
     $client->SetFieldWeights($fieldWeights);
     $client->setLimits(0, 100);
     $results = $client->query($client->EscapeString($query), $indexName);
     if ($results === false) {
         $error = "Sphinx Error - " . $client->GetLastError();
         sfErrorNotifier::alert($error);
     }
     $ids = array();
     if (isset($results['matches']) && count($results['matches'])) {
         foreach ($results['matches'] as $match) {
             $ids[] = $match['id'];
         }
     }
     return PcTaskPeer::retrieveByPKs($ids);
 }
开发者ID:ntemple,项目名称:intelli-plancake,代码行数:32,代码来源:Searcher.php

示例3: search

 /**
  * @{inheritDoc}
  */
 public function search()
 {
     $result = $this->get_result();
     // Could be connection to localhost:9312 failed (errno=111,
     // msg=Connection refused) during rotate, retry if so
     $retries = self::CONNECT_RETRIES;
     while (!$result && strpos($this->client->GetLastError(), "errno=111,") !== false && $retries--) {
         usleep(self::CONNECT_WAIT_TIME);
         $result = $this->get_result();
     }
     if ($this->client->GetLastError()) {
         if ($this->auth->acl_get('a_')) {
             throw new http_exception(500, 'SPHINX_SEARCH_FAILED', array($this->client->GetLastError()));
         } else {
             throw new http_exception(500, 'SPHINX_SEARCH_FAILED_LOG');
         }
     }
     $_result = array('documents' => array(), 'user_ids' => array(), 'total' => 0);
     if (!empty($result['matches'])) {
         foreach ($result['matches'] as $data) {
             $attrs = $data['attrs'];
             $attrs['id'] = $attrs['real_id'];
             unset($attrs['real_id']);
             $_result['documents'][$attrs['type'] . '_' . $attrs['id']] = $attrs;
             $_result['user_ids'][] = $attrs['author'];
         }
         $_result['total'] = $result['total_found'];
     }
     return $_result;
 }
开发者ID:Sajaki,项目名称:customisation-db,代码行数:33,代码来源:fulltext_sphinx.php

示例4: setFilter

 /**
  * Adds new integer values set filter to the existing list of filters.
  *
  * @param $attribute An attribute name.
  * @param $values Plain array of integer values.
  * @param bool $exclude If set to TRUE, matching items are excluded from the result set.
  * @return SphinxSearch_Abstract_List
  * @throws Exception on failure
  */
 public function setFilter($attribute, $values, $exclude = false)
 {
     $result = $this->SphinxClient->SetFilter($attribute, $values, $exclude);
     if ($result === false) {
         throw new Exception("Error on setting filter \"" . $attribute . "\":\n" . $this->SphinxClient->GetLastError());
     }
     return $this;
 }
开发者ID:VadzimBelski-ScienceSoft,项目名称:pimcore-plugin-SphinxSearch,代码行数:17,代码来源:List.php

示例5: query

 /**
  * {@inheritdoc}
  */
 public function query($query, $offset, $perPage, SearchEngineOptions $options = null)
 {
     if (null === $options) {
         $options = new SearchEngineOptions();
     }
     $this->applyOptions($options);
     assert(is_int($offset));
     assert($offset >= 0);
     assert(is_int($perPage));
     $query = $this->parseQuery($query);
     $preg = preg_match('/\\s?(recordid|storyid)\\s?=\\s?([0-9]+)/i', $query, $matches, 0, 0);
     if ($preg > 0) {
         $this->sphinx->SetFilter('record_id', [$matches[2]]);
         $query = '';
     }
     $this->sphinx->SetLimits($offset, $perPage);
     $this->sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
     $index = $this->getQueryIndex($query, $options);
     $res = $this->sphinx->Query($query, $index);
     $results = new ArrayCollection();
     if ($res === false) {
         if ($this->sphinx->IsConnectError() === true) {
             $error = $this->app->trans('Sphinx server is offline');
         } else {
             $error = $this->sphinx->GetLastError();
         }
         $warning = $this->sphinx->GetLastWarning();
         $total = $available = $duration = 0;
         $suggestions = new ArrayCollection();
         $propositions = [];
     } else {
         $error = $res['error'];
         $warning = $res['warning'];
         $duration = $res['time'];
         $total = $res['total_found'];
         $available = $res['total'];
         $resultOffset = $offset;
         if (isset($res['matches'])) {
             foreach ($res['matches'] as $record_id => $match) {
                 try {
                     $record = new \record_adapter($this->app, $match['attrs']['sbas_id'], $match['attrs']['record_id'], $resultOffset);
                     $results->add($record);
                 } catch (\Exception $e) {
                 }
                 $resultOffset++;
             }
         }
         $suggestions = $this->getSuggestions($query, $options);
         $propositions = '';
     }
     return new SearchEngineResult($results, $query, $duration, $offset, $available, $total, $error, $warning, $suggestions, $propositions, $index);
 }
开发者ID:romainneutron,项目名称:Phraseanet,代码行数:55,代码来源:SphinxSearchEngine.php

示例6: execute

 protected function execute()
 {
     $sph = $this->sphinxClient->RunQueries();
     if ($error = $this->sphinxClient->GetLastError()) {
         throw new ESphinxException($error);
     }
     if ($error = $this->sphinxClient->GetLastWarning()) {
         throw new ESphinxException($error);
     }
     if (!is_array($sph)) {
         throw new ESphinxException("Sphinx client returns result not array");
     }
     $results = array();
     foreach ($sph as $result) {
         if (isset($result['error']) && strlen($result['error'])) {
             throw new ESphinxException($result['error']);
         }
         $results[] = new ESphinxResult($result);
     }
     return $results;
 }
开发者ID:jerrylsxu,项目名称:yii-sphinx,代码行数:21,代码来源:ESphinxConnection.php

示例7: foreach

if ($distinct) {
    $cl->SetGroupDistinct($distinct);
}
if ($select) {
    $cl->SetSelect($select);
}
if ($limit) {
    $cl->SetLimits(0, $limit, $limit > 1000 ? $limit : 1000);
}
$cl->SetRankingMode($ranker);
$res = $cl->Query($q, $index);
////////////////
// print me out
////////////////
if ($res === false) {
    print "Query failed: " . $cl->GetLastError() . ".\n";
} else {
    if ($cl->GetLastWarning()) {
        print "WARNING: " . $cl->GetLastWarning() . "\n\n";
    }
    print "Query '{$q}' retrieved {$res['total']} of {$res['total_found']} matches in {$res['time']} sec.\n";
    print "Query stats:\n";
    if (is_array($res["words"])) {
        foreach ($res["words"] as $word => $info) {
            print "    '{$word}' found {$info['hits']} times in {$info['docs']} documents\n";
        }
    }
    print "\n";
    if (is_array($res["matches"])) {
        $n = 1;
        print "Matches:\n";
开发者ID:jzawodn,项目名称:Sphinx-at-Craigslist,代码行数:31,代码来源:test.php

示例8: explode

            }
        } else {
            $query = explode(' ', $query);
            $q = '(';
            foreach ($query as $k => $w) {
                if (strlen($w) > 2) {
                    $q .= $w . ' | ' . $w . '* | *' . $w . '* | *' . $w;
                    if ($k < count($query) - 1) {
                        $q .= ' | ';
                    }
                }
            }
            $q .= ')';
            $result = $sphinx->Query($q, 'name' . $GLOBALS['CONFIG']['search_index_prefix']);
            if ($result === false) {
                print_r("Произошла ошибка: " . $sphinx->GetLastError());
            }
            $i = 0;
            foreach ($result['matches'] as $val) {
                $res[$i] = $val['id'];
                $i++;
            }
            if (!empty($res) && count($res > 0)) {
                $where_arr['customs'][] = 'p.id_product IN (' . implode(', ', $res) . ')';
            } else {
                $where_arr['customs'][] = 'p.id_product = 2';
            }
        }
    }
}
// =========================================================
开发者ID:Arikito,项目名称:webking.xt,代码行数:31,代码来源:products.php

示例9: run


//.........这里部分代码省略.........
     }
     // if ( $sortexpr )			$cl->SetSortMode ( SPH_SORT_EXPR, $sortexpr );
     if ($distinct) {
         $cl->SetGroupDistinct($distinct);
     }
     if ($select) {
         $cl->SetSelect($select);
     }
     if ($limit) {
         $cl->SetLimits(0, $limit, $limit > 1000000 ? $limit : 1000000);
     }
     $cl->SetRankingMode($ranker);
     $res = $cl->Query($q, $index);
     //$res = true;
     ////////////
     // do Insert to DB
     ////////////
     // Current matching
     $current_matching = array();
     /*$query_matchs = $this->db->get_where('matchs',array('subject_id'=>$subject_id));
     		if($query_matchs->num_rows() > 0)
     		{
     			echo PHP_EOL.'currents matching :'.$query_matchs->num_rows();
     			foreach($query_matchs->result() as $match)
     			{
     				$current_matching[] = $match->post_id;
     			}
     		}*/
     // set matching date range from-to
     $from = strtotime($from);
     $to = strtotime($to);
     // Search and Update
     if ($res === false) {
         echo "Query failed: " . $cl->GetLastError() . ".\n";
     } else {
         if ($cl->GetLastWarning()) {
             echo "WARNING: " . $cl->GetLastWarning() . "\n\n";
         }
         echo "Query '{$q}' \nretrieved {$res['total']} of {$res['total_found']} matches in {$res['time']} sec.\n";
         if ($res['total'] == 0) {
             echo "no result<br/>\n";
         } else {
             if ($res['total'] > $limit + $offset) {
                 $this->run($subject_id, $limit + $offset);
             } else {
                 echo "Updating...";
                 foreach ($res["matches"] as $k => $docinfo) {
                     //					echo '('.$k.')'.$docinfo["id"]." ";
                     // Reset PHP Timeout to 1min
                     // if found in $current_matching then skip
                     if (in_array($docinfo["id"], $current_matching)) {
                         continue;
                     } else {
                         // else insert new match
                         set_time_limit(60);
                         $post = new Post_model();
                         $post->init($docinfo["id"]);
                         // if post_date is our of range then skip
                         $post_date = strtotime($post->post_date);
                         if ($post_date < $from || $post_date > $to) {
                             continue;
                         }
                         $mood = get_mood($post->body, $keywords);
                         //-----------------------------------------------------
                         $subject = $post->get_subject($subject_id);
                         //print_r($subject);
开发者ID:nytonkla,项目名称:stupidspider,代码行数:67,代码来源:matcher2.php

示例10: getErrorMessage

 function getErrorMessage()
 {
     return $this->sphinx->GetLastError();
 }
开发者ID:290329416,项目名称:guahao,代码行数:4,代码来源:sphinxsearch.php

示例11: SphinxClient

 //---------------BEGIN SPHINX
 require_once $basePath . "/../SPHINX.class.php";
 // Get the search variable from URL
 // $var = @$_GET['msg_mask'] ;
 // $trimmed = trim($$msg_mask); //trim whitespace from the stored variable
 // $q = $trimmed;
 #$q = "SELECT id ,group_id,title FROM documents where title = 'test one'";
 #$q = " SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content FROM documents";
 $index = "idx_logs";
 $cl = new SphinxClient();
 $hostip = $_SESSION['SPX_SRV'];
 $port = intval($_SESSION['SPX_PORT']);
 $cl->SetServer($hostip, $port);
 $res = $cl->Query($msg_mask, $index);
 if (!$res) {
     die("ERROR: " . $cl->GetLastError() . ".\n");
 } else {
     if ($res['total_found'] > 0) {
         $where .= " AND id IN (";
         foreach ($res["matches"] as $doc => $docinfo) {
             $where .= "'{$doc}',";
             // echo "$doc<br>\n";
         }
         $where = rtrim($where, ",");
         $where .= ")";
     } else {
         // Negate search since sphinx returned 0 hits
         $where = "WHERE 1<1";
         //  die(print_r($res));
     }
 }
开发者ID:Russell-IO,项目名称:php-syslog-ng,代码行数:31,代码来源:json.charts.header.php

示例12: getError

 /**
  * Return last error
  * @param bool $conn
  * @return bool|string
  */
 public function getError($conn = false)
 {
     return !$conn ? $this->client->GetLastError() : $this->client->IsConnectError();
 }
开发者ID:oneismore,项目名称:Discuss,代码行数:9,代码来源:dissphinxsearch.class.php

示例13: sphinx_search_action

function sphinx_search_action($arrSearch)
{
    global $PHORUM;
    // No pecl class, try php version
    if (!class_exists('SphinxClient')) {
        // loads from php include_path
        require_once 'sphinxapi.php';
    }
    // these are the index-names set in sphinx.conf - one for searching messages, the other for searching by authors only
    // both contain an additional index for the deltas - changes done after the last full reindex
    $index_name_msg = 'phorum5_msg_d phorum5_msg';
    $index_name_author = 'phorum5_author phorum5_author_d';
    // excerpts_index is just one index as that function only accepts one, it used for determining charsets / mapping tables, nothing more
    $excerpts_index = 'phorum5_msg';
    $index = $index_name_msg;
    if ($arrSearch['match_type'] == 'ALL') {
        $match_mode = SPH_MATCH_ALL;
    } elseif ($arrSearch['match_type'] == 'ANY') {
        $match_mode = SPH_MATCH_ANY;
    } elseif ($arrSearch['match_type'] == 'PHRASE') {
        $match_mode = SPH_MATCH_PHRASE;
    } elseif ($arrSearch['match_type'] == 'AUTHOR') {
        $match_mode = SPH_MATCH_PHRASE;
        $index = $index_name_author;
    } else {
        // Return search control to Phorum in case the search type isn't handled by the module.
        return $arrSearch;
    }
    if (empty($arrSearch['search']) && !empty($arrSearch['author'])) {
        $arrSearch['search'] = $arrSearch['author'];
        $index = $index_name_author;
    }
    $sphinx = new SphinxClient();
    $sphinx->SetServer($PHORUM['mod_sphinx_search']['hostname'], $PHORUM['mod_sphinx_search']['port']);
    $sphinx->SetMatchMode($match_mode);
    // set the limits for paging
    $sphinx->SetLimits($arrSearch['offset'], $arrSearch['length']);
    // set the timeframe to search
    if ($arrSearch['match_dates'] > 0) {
        $min_ts = time() - 86400 * $arrSearch['match_dates'];
        $max_ts = time();
        $sphinx->SetFilterRange('datestamp', $min_ts, $max_ts);
    }
    // Check what forums the active Phorum user can read.
    $allowed_forums = phorum_api_user_check_access(PHORUM_USER_ALLOW_READ, PHORUM_ACCESS_LIST);
    // If the user is not allowed to search any forum or the current
    // active forum, then return the emtpy search results array.
    if (empty($allowed_forums) || $PHORUM['forum_id'] > 0 && !in_array($PHORUM['forum_id'], $allowed_forums)) {
        $arrSearch['results'] = array();
        $arrSearch['totals'] = 0;
        $arrSearch['continue'] = 0;
        $arrSearch['raw_body'] = 1;
        return $arrSearch;
    }
    // Prepare forum_id restriction.
    $search_forums = array();
    foreach (explode(',', $arrSearch['match_forum']) as $forum_id) {
        if ($forum_id == 'ALL') {
            $search_forums = $allowed_forums;
            break;
        }
        if (isset($allowed_forums[$forum_id])) {
            $search_forums[] = $forum_id;
        }
    }
    $sphinx->SetFilter('forum_id', $search_forums);
    // set the sort-mode
    $sphinx->SetSortMode(SPH_SORT_ATTR_DESC, 'datestamp');
    // do the actual query
    $results = $sphinx->Query($arrSearch['search'], $index);
    $res = $sphinx->GetLastWarning();
    if ($res) {
        error_log("sphinx_search.php: WARNING: {$res}");
    }
    $res = $sphinx->GetLastError();
    if ($res) {
        error_log("sphinx_search.php: ERROR: {$res}");
    }
    // if no messages were found, then return empty handed.
    if (!isset($results['matches'])) {
        $arrSearch['results'] = array();
        $arrSearch['totals'] = 0;
        $arrSearch['continue'] = 0;
        $arrSearch['raw_body'] = 1;
        return $arrSearch;
    }
    $search_msg_ids = $results['matches'];
    // get the messages we found
    $found_messages = phorum_db_get_message(array_keys($search_msg_ids), 'message_id', true);
    // sort them in reverse order of the message_id to automagically sort them by date desc this way
    krsort($found_messages);
    reset($found_messages);
    // prepare the array for building highlighted excerpts
    $docs = array();
    foreach ($found_messages as $id => $data) {
        // remove hidden text in the output - only added by the hidden_msg module
        $data['body'] = preg_replace("/(\\[hide=([\\#a-z0-9]+?)\\](.+?)\\[\\/hide\\])/is", '', $data['body']);
        $docs[] = htmlspecialchars(phorum_strip_body($data['body']));
    }
    $words = '';
//.........这里部分代码省略.........
开发者ID:raul72,项目名称:phorum-sphinx_search,代码行数:101,代码来源:sphinx_search.php

示例14: __construct

 public function __construct($rowsPerPage, $currentPage, $siteID, $wildCardString, $sortBy, $sortDirection)
 {
     $this->_db = DatabaseConnection::getInstance();
     $this->_siteID = $siteID;
     $this->_sortByFields = array('firstName', 'lastName', 'city', 'state', 'dateModifiedSort', 'dateCreatedSort', 'ownerSort');
     if (ENABLE_SPHINX) {
         /* Sphinx API likes to throw PHP errors *AND* use it's own error
          * handling.
          */
         assert_options(ASSERT_WARNING, 0);
         $sphinx = new SphinxClient();
         $sphinx->SetServer(SPHINX_HOST, SPHINX_PORT);
         $sphinx->SetWeights(array(0, 100, 0, 0, 50));
         $sphinx->SetMatchMode(SPH_MATCH_EXTENDED);
         $sphinx->SetLimits(0, 1000);
         $sphinx->SetSortMode(SPH_SORT_TIME_SEGMENTS, 'date_added');
         // FIXME: This can be sped up a bit by actually grouping ranges of
         //        site IDs into their own index's. Maybe every 500 or so at
         //        least on the Hosted system.
         $sphinx->SetFilter('site_id', array($this->_siteID));
         /* Create the Sphinx query string. */
         $wildCardString = DatabaseSearch::humanToSphinxBoolean($wildCardString);
         /* Execute the Sphinx query. Sphinx can ask us to retry if its
          * maxed out. Retry up to 5 times.
          */
         $tries = 0;
         do {
             /* Wait for one second if this isn't out first attempt. */
             if (++$tries > 1) {
                 sleep(1);
             }
             $results = $sphinx->Query($wildCardString, SPHINX_INDEX);
             $errorMessage = $sphinx->GetLastError();
         } while ($results === false && strpos($errorMessage, 'server maxed out, retry') !== false && $tries <= 5);
         /* Throw a fatal error if Sphinx errors occurred. */
         if ($results === false) {
             $this->fatal('Sphinx Error: ' . ucfirst($errorMessage) . '.');
         }
         /* Throw a fatal error (for now) if Sphinx warnings occurred. */
         $lastWarning = $sphinx->GetLastWarning();
         if (!empty($lastWarning)) {
             // FIXME: Just display a warning, and notify dev team.
             $this->fatal('Sphinx Warning: ' . ucfirst($lastWarning) . '.');
         }
         /* Show warnings for assert()s again. */
         assert_options(ASSERT_WARNING, 1);
         if (empty($results['matches'])) {
             $this->_WHERE = '0';
         } else {
             $attachmentIDs = implode(',', array_keys($results['matches']));
             $this->_WHERE = 'attachment.attachment_id IN(' . $attachmentIDs . ')';
         }
     } else {
         $this->_WHERE = DatabaseSearch::makeBooleanSQLWhere(DatabaseSearch::fulltextEncode($wildCardString), $this->_db, 'attachment.text');
     }
     /* How many companies do we have? */
     $sql = sprintf("SELECT\n                COUNT(*) AS count\n            FROM\n                attachment\n            LEFT JOIN candidate\n                ON attachment.data_item_id = candidate.candidate_id\n                AND attachment.data_item_type = %s\n                AND attachment.site_id = candidate.site_id\n            LEFT JOIN user AS owner_user\n                ON candidate.owner = owner_user.user_id\n            WHERE\n                resume = 1\n            AND\n                %s\n            AND\n                (ISNULL(candidate.is_admin_hidden) OR (candidate.is_admin_hidden = 0))\n            AND\n                (ISNULL(candidate.is_active) OR (candidate.is_active = 1))\n            AND\n                attachment.site_id = %s", DATA_ITEM_CANDIDATE, $this->_WHERE, $this->_siteID);
     $rs = $this->_db->getAssoc($sql);
     /* Pass "Search By Resume"-specific parameters to Pager constructor. */
     parent::__construct($rs['count'], $rowsPerPage, $currentPage);
 }
开发者ID:rankinp,项目名称:OpenCATS,代码行数:61,代码来源:Search.php

示例15: keyword_search


//.........这里部分代码省略.........
      * @since 3.1.7-RC1
      */
     $sphinx = $this->sphinx;
     $vars = array('type', 'fields', 'terms', 'sort_days', 'sort_key', 'topic_id', 'ex_fid_ary', 'post_visibility', 'author_ary', 'author_name', 'sphinx');
     extract($this->phpbb_dispatcher->trigger_event('core.search_sphinx_keywords_modify_options', compact($vars)));
     $this->sphinx = $sphinx;
     unset($sphinx);
     $search_query_prefix = '';
     switch ($fields) {
         case 'titleonly':
             // Only search the title
             if ($terms == 'all') {
                 $search_query_prefix = '@title ';
             }
             // Weight for the title
             $this->sphinx->SetFieldWeights(array("title" => 5, "data" => 1));
             // 1 is first_post, 0 is not first post
             $this->sphinx->SetFilter('topic_first_post', array(1));
             break;
         case 'msgonly':
             // Only search the body
             if ($terms == 'all') {
                 $search_query_prefix = '@data ';
             }
             // Weight for the body
             $this->sphinx->SetFieldWeights(array("title" => 1, "data" => 5));
             break;
         case 'firstpost':
             // More relative weight for the title, also search the body
             $this->sphinx->SetFieldWeights(array("title" => 5, "data" => 1));
             // 1 is first_post, 0 is not first post
             $this->sphinx->SetFilter('topic_first_post', array(1));
             break;
         default:
             // More relative weight for the title, also search the body
             $this->sphinx->SetFieldWeights(array("title" => 5, "data" => 1));
             break;
     }
     if (sizeof($author_ary)) {
         $this->sphinx->SetFilter('poster_id', $author_ary);
     }
     // As this is not simply possible at the moment, we limit the result to approved posts.
     // This will make it impossible for moderators to search unapproved and softdeleted posts,
     // but at least it will also cause the same for normal users.
     $this->sphinx->SetFilter('post_visibility', array(ITEM_APPROVED));
     if (sizeof($ex_fid_ary)) {
         // All forums that a user is allowed to access
         $fid_ary = array_unique(array_intersect(array_keys($this->auth->acl_getf('f_read', true)), array_keys($this->auth->acl_getf('f_search', true))));
         // All forums that the user wants to and can search in
         $search_forums = array_diff($fid_ary, $ex_fid_ary);
         if (sizeof($search_forums)) {
             $this->sphinx->SetFilter('forum_id', $search_forums);
         }
     }
     $this->sphinx->SetFilter('deleted', array(0));
     $this->sphinx->SetLimits($start, (int) $per_page, SPHINX_MAX_MATCHES);
     $result = $this->sphinx->Query($search_query_prefix . str_replace('&quot;', '"', $this->search_query), $this->indexes);
     // Could be connection to localhost:9312 failed (errno=111,
     // msg=Connection refused) during rotate, retry if so
     $retries = SPHINX_CONNECT_RETRIES;
     while (!$result && strpos($this->sphinx->GetLastError(), "errno=111,") !== false && $retries--) {
         usleep(SPHINX_CONNECT_WAIT_TIME);
         $result = $this->sphinx->Query($search_query_prefix . str_replace('&quot;', '"', $this->search_query), $this->indexes);
     }
     if ($this->sphinx->GetLastError()) {
         $phpbb_log->add('critical', $user->data['user_id'], $user->ip, 'LOG_SPHINX_ERROR', false, array($this->sphinx->GetLastError()));
         if ($this->auth->acl_get('a_')) {
             trigger_error($this->user->lang('SPHINX_SEARCH_FAILED', $this->sphinx->GetLastError()));
         } else {
             trigger_error($this->user->lang('SPHINX_SEARCH_FAILED_LOG'));
         }
     }
     $result_count = $result['total_found'];
     if ($result_count && $start >= $result_count) {
         $start = floor(($result_count - 1) / $per_page) * $per_page;
         $this->sphinx->SetLimits((int) $start, (int) $per_page, SPHINX_MAX_MATCHES);
         $result = $this->sphinx->Query($search_query_prefix . str_replace('&quot;', '"', $this->search_query), $this->indexes);
         // Could be connection to localhost:9312 failed (errno=111,
         // msg=Connection refused) during rotate, retry if so
         $retries = SPHINX_CONNECT_RETRIES;
         while (!$result && strpos($this->sphinx->GetLastError(), "errno=111,") !== false && $retries--) {
             usleep(SPHINX_CONNECT_WAIT_TIME);
             $result = $this->sphinx->Query($search_query_prefix . str_replace('&quot;', '"', $this->search_query), $this->indexes);
         }
     }
     $id_ary = array();
     if (isset($result['matches'])) {
         if ($type == 'posts') {
             $id_ary = array_keys($result['matches']);
         } else {
             foreach ($result['matches'] as $key => $value) {
                 $id_ary[] = $value['attrs']['topic_id'];
             }
         }
     } else {
         return false;
     }
     $id_ary = array_slice($id_ary, 0, (int) $per_page);
     return $result_count;
 }
开发者ID:bruninoit,项目名称:phpbb,代码行数:101,代码来源:fulltext_sphinx.php


注:本文中的SphinxClient::GetLastError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。