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


PHP SphinxClient::setFieldWeights方法代码示例

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


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

示例1: resetClient

 /**
  * Reset settings sphinx
  */
 public function resetClient()
 {
     $this->_client->resetFilters();
     $this->_client->resetGroupBy();
     $this->_client->setArrayResult(false);
     //DEPRECATED: Do not call this method or, even better, use SphinxQL instead of an API
     //$this->_client->setMatchMode(SPH_MATCH_EXTENDED2);
     $this->_client->setLimits(0, 20, 1000, 0);
     $this->_client->setFieldWeights(array());
     $this->_client->setSortMode(SPH_SORT_RELEVANCE, '');
     $this->_client->_error = '';
     $this->_client->_warning = '';
 }
开发者ID:bleid3,项目名称:yii-component-sphinx,代码行数:16,代码来源:AdvSphinxConnection.php

示例2: search

 /**
  * Search for the specified query string.
  *
  * @param string $query The query string that we are searching for.
  * @param array $indexes The indexes to perform the search on.
  * @param array $options The options for the query.
  * @param bool $escapeQuery Should the query string be escaped?
  *
  * @return array The results of the search.
  */
 public function search($query, array $indexes, array $options = array(), $escapeQuery = true)
 {
     if ($escapeQuery) {
         $query = $this->sphinx->escapeString($query);
     }
     /**
      * Build the list of indexes to be queried.
      */
     $indexNames = '';
     foreach ($indexes as &$label) {
         if (isset($this->indexes[$label])) {
             $indexNames .= $this->indexes[$label] . ' ';
         }
     }
     /**
      * If no valid indexes were specified, return an empty result set.
      *
      * FIXME: This should probably throw an exception.
      */
     if (empty($indexNames)) {
         return array();
     }
     /**
      * Set the offset and limit for the returned results.
      */
     if (isset($options['result_offset']) && isset($options['result_limit'])) {
         $this->sphinx->setLimits($options['result_offset'], $options['result_limit']);
     }
     /**
      * Weight the individual fields.
      */
     if (isset($options['field_weights'])) {
         $this->sphinx->setFieldWeights($options['field_weights']);
     }
     /**
      * Perform the query.
      */
     $start = round(microtime(true) * 1000);
     $results = $this->sphinx->query($query, $indexNames);
     if ($results['status'] === SEARCHD_ERROR) {
         throw new \RuntimeException(sprintf('Searching index "%s" for "%s" failed with error "%s".', $label, $query, $this->sphinx->getLastError()));
     }
     if ($results['status'] === SEARCHD_RETRY) {
         throw new \RuntimeException(sprintf('Searching index "%s" for "%s" failed with retry "%s".', $label, $query, $this->sphinx->getLastError()));
     }
     $end = round(microtime(true) * 1000) - $start;
     $event = new SearchEvent($query, $indexes, $end);
     $this->dispatcher->dispatch("sphinx.event.search", $event);
     return $results;
 }
开发者ID:headzoo,项目名称:sphinx-search-bundle,代码行数:60,代码来源:SphinxSearch.php

示例3: search

 /**
  * Search for the specified query string.
  *
  * @param string $query The query string that we are searching for.
  * @param array $indexes The indexes to perform the search on.
  *
  * @return array The results of the search.
  *
  * $indexes should look like:
  *
  * $indexes = array(
  *   'IndexLabel' => array(
  *     'result_offset' => (int), // optional unless result_limit is set
  *     'result_limit'  => (int), // optional unless result_offset is set
  *     'field_weights' => array( // optional
  *       'FieldName'   => (int),
  *       ...,
  *     ),
  *   ),
  *   ...,
  * );
  */
 public function search($query, array $indexes, $escapeQuery = true)
 {
     if ($escapeQuery) {
         $query = $this->sphinx->escapeString($query);
     }
     $results = array();
     foreach ($indexes as $label => $options) {
         /**
          * Ensure that the label corresponds to a defined index.
          */
         if (!isset($this->indexes[$label])) {
             continue;
         }
         /**
          * Set the offset and limit for the returned results.
          */
         if (isset($options['result_offset']) && isset($options['result_limit'])) {
             $this->sphinx->setLimits($options['result_offset'], $options['result_limit']);
         }
         /**
          * Weight the individual fields.
          */
         if (isset($options['field_weights'])) {
             $this->sphinx->setFieldWeights($options['field_weights']);
         }
         /**
          * Perform the query.
          */
         $results[$label] = $this->sphinx->query($query, implode(' ', $this->indexes[$label]["index"]));
         if ($results[$label]['status'] !== SEARCHD_OK) {
             throw new \RuntimeException(sprintf('Searching index "%s" for "%s" failed with error "%s".', $label, $query, $this->sphinx->getLastError()));
         }
     }
     /**
      * If only one index was searched, return that index's results directly.
      */
     if (count($indexes) === 1 && count($results) === 1) {
         $results = reset($results);
     }
     /**
      * FIXME: Throw an exception if $results is empty?
      */
     return $results;
 }
开发者ID:remilemonnier,项目名称:SphinxsearchBundle0.9,代码行数:66,代码来源:Sphinxsearch.php

示例4: getSphinxAdapter

 public function getSphinxAdapter()
 {
     require_once Mage::getBaseDir('lib') . DIRECTORY_SEPARATOR . 'sphinxapi.php';
     // Connect to our Sphinx Search Engine and run our queries
     $sphinx = new SphinxClient();
     $host = Mage::getStoreConfig('sphinxsearch/server/host');
     $port = Mage::getStoreConfig('sphinxsearch/server/port');
     if (empty($host)) {
         return $sphinx;
     }
     if (empty($port)) {
         $port = 9312;
     }
     $sphinx->SetServer($host, $port);
     $sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
     $sphinx->setFieldWeights(array('name' => 7, 'category' => 1, 'name_attributes' => 1, 'data_index' => 3));
     $sphinx->setLimits(0, 200, 1000, 5000);
     // SPH_RANK_PROXIMITY_BM25 ist default
     $sphinx->SetRankingMode(SPH_RANK_SPH04, "");
     // 2nd parameter is rank expr?
     return $sphinx;
 }
开发者ID:elderxavier,项目名称:sphinxsearch,代码行数:22,代码来源:Data.php

示例5: search

 /**
  * Search for the specified query string.
  *
  * @param string $query The query string that we are searching for.
  * @param array $indexes The indexes to perform the search on.
  *
  * @return ResultCollection The results of the search.
  *
  * $indexes should have the format:
  *
  *	$indexes = array(
  *		'IndexLabel' => array(
  *			'result_offset'	=> (int),
  *			'result_limit'	=> (int)
  *		),
  *		...,
  *	);
  */
 public function search($query, array $indexes)
 {
     // $query = $this->sphinx->escapeString($query);
     $results = array();
     foreach ($indexes as $label => $options) {
         /**
          * Ensure that the label corresponds to a defined index.
          */
         if (!isset($this->indexes[$label])) {
             continue;
         }
         /**
          * Set the offset and limit for the returned results.
          */
         if (isset($options['result_offset']) && isset($options['result_limit']) && is_numeric($options['result_offset']) && is_numeric($options['result_limit'])) {
             $this->sphinx->setLimits($options['result_offset'], $options['result_limit']);
         }
         /**
          * Weight the individual fields.
          */
         if (!empty($this->indexes[$label]['field_weights'])) {
             $this->sphinx->setFieldWeights($this->indexes[$label]['field_weights']);
         }
         /**
          * Perform the query.
          */
         $results[$label] = $this->sphinx->query($query, implode(' ', $this->indexes[$label]["index"]));
         if ($this->sphinx->IsConnectError()) {
             throw new ConnectionException(sprintf('Searching index "%s" for "%s" failed with error "%s".', $label, $query, $this->sphinx->getLastError()));
         } elseif ($results[$label]['status'] !== SEARCHD_OK) {
             throw new \RuntimeException(sprintf('Searching index "%s" for "%s" failed with error "%s".', $label, $query, $this->sphinx->getLastError()));
         }
     }
     /**
      * FIXME: Throw an exception if $results is empty?
      */
     return new ResultCollection($results, $this->mapping, $this->em);
 }
开发者ID:maninhat,项目名称:search-sphinxsearchbundle,代码行数:56,代码来源:Sphinxsearch.php

示例6: fetch

 public function fetch()
 {
     if (!class_exists('SphinxClient')) {
         return false;
     }
     $s = new SphinxClient();
     $s->setServer($this->_sphinxHost, $this->_sphinxPort);
     if (count($this->_arrSearchOutRangeColumnMinMax) > 0) {
         foreach ($this->_arrSearchOutRangeColumnMinMax as $value) {
             $d = explode(',', $value);
             $s->setFilterRange($d[0], $d[1], $d[2], true);
         }
     }
     if (count($this->_arrSearchInRangeColumnMinMax) > 0) {
         foreach ($this->_arrSearchInRangeColumnMinMax as $value) {
             $d = explode(',', $value);
             $s->setFilterRange($d[0], $d[1], $d[2], false);
         }
     }
     $s->setConnectTimeout($this->_connectTimeout);
     $s->setMaxQueryTime($this->{$_maxquerytime});
     //            $s->setRetries ( int $this->retriesCount , int $this->retriesDelay  );
     //
     $s->setMatchMode($this->searchMode);
     $s->setFieldWeights($this->_fieldweights);
     //            $s->setFilter ( string $attribute , array $values [, bool $exclude = false ] );
     //            $s->setFilterFloatRange ( string $attribute , float $min , float $max [, bool $exclude = false ] );
     //            $s->setFilterRange ( string $attribute , int $min , int $max [, bool $exclude = false ] );
     //            $s->setGeoAnchor ( string $attrlat , string $attrlong , float $latitude , float $longitude );
     //            $s->setGroupBy ( string $attribute , int $func [, string $groupsort = "@group desc" ] );
     //            $s->setGroupDistinct ( string $attribute );
     //            $s->setIDRange ( int $min , int $max );
     $s->setIndexWeights($this->_arrIndexweights);
     //            $s->setLimits ( int $offset , int $limit [, int $max_matches = 0 [, int $cutoff = 0 ]] );
     $s->setMatchMode($this->searchMode);
     //            $s->setOverride ( string $attribute , int $type , array $values );
     $s->setRankingMode($this->rankMode);
     //            $s->setSelect ( string $clause );
     //            $s->setSortMode ( int $mode [, string $sortby ] );
     return $s->query($this->_query);
 }
开发者ID:falkbizz,项目名称:SphinxSearchTools,代码行数:41,代码来源:Query.php

示例7: resetCriteria

 /**
  * @brief reset search criteria to default
  * @details reset conditions and set default search options
  */
 public function resetCriteria()
 {
     if (is_object($this->criteria)) {
         $this->lastCriteria = clone $this->criteria;
     } else {
         $this->lastCriteria = new stdClass();
     }
     $this->criteria = new stdClass();
     $this->criteria->query = '';
     $this->client->resetFilters();
     $this->client->resetGroupBy();
     $this->client->setArrayResult(false);
     $this->client->setMatchMode($this->matchMode);
     //        $this->client->setRankingMode($this->rankMode);
     $this->client->setSortMode(SPH_SORT_RELEVANCE, '@relevance DESC');
     $this->client->setLimits(0, 1000000, 10000);
     if (!empty($this->fieldWeights)) {
         $this->client->setFieldWeights($this->fieldWeights);
     }
 }
开发者ID:zwq,项目名称:unpei,代码行数:24,代码来源:DGSphinxSearch.php

示例8: queryDocument

 public static function queryDocument($query, $params = array())
 {
     if (trim($query) == "") {
         return array();
     }
     $sphinx_config = SphinxSearch_Config::getInstance();
     $documents_config = $sphinx_config->getDocumentsAsArray();
     $SphinxClient = new SphinxClient();
     $entries = array();
     $language = "all";
     if (SphinxSearch_Config_Plugin::getValue("documents", "use_i18n") == "true") {
         if (array_key_exists("language", $params)) {
             $language = $params["language"];
         } else {
             $locale = Zend_Registry::get("Zend_Locale");
             $language = $locale->getLanguage();
         }
     }
     $field_weights = array();
     $indexes = array();
     foreach ($documents_config as $document_name => $document_properties) {
         $indexes[] = "idx_document_" . $document_name . "_" . $language;
         foreach ($document_properties["elements"] as $field_name => $field_config) {
             if (array_key_exists("weight", $field_config) && intval($field_config["weight"]) > 0) {
                 $field_weights[$field_name] = intval($field_config["weight"]);
             }
         }
     }
     if (sizeof($field_weights) > 0) {
         $SphinxClient->setFieldWeights($field_weights);
     }
     $search_result = $SphinxClient->Query($query, implode(", ", $indexes));
     if ($search_result === false) {
         throw new Exception($SphinxClient->GetLastError());
     }
     if ($search_result["total_found"] > 0) {
         foreach ($search_result["matches"] as $id => $meta) {
             $entries[] = array("result" => Document::getById($id), "id" => $id, "meta" => $meta, "type" => "document");
         }
     }
     return $entries;
 }
开发者ID:VadzimBelski-ScienceSoft,项目名称:pimcore-plugin-SphinxSearch,代码行数:42,代码来源:SphinxSearch.php


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