contributions/sphinx/model/base/dataobjectsphinx.base.cls.php
Go to the documentation of this file.00001 <?php 00002 /** 00003 * A DataObject class for Sphinx indexes 00004 * 00005 * @author Gerd Riesselmann 00006 * @ingroup Sphinx 00007 */ 00008 class DataObjectSphinxBase extends DataObjectBase { 00009 /** 00010 * Used to keep query for all fields 00011 * 00012 * @var string 00013 */ 00014 public $sphinx_all_fields = ''; 00015 /** 00016 * Set Sphinx features, like weights 00017 * 00018 * @var array 00019 */ 00020 public $sphinx_features = array(); 00021 00022 /** 00023 * Configure a select query 00024 * 00025 * @param DBQuerySelect $query 00026 * @param int $policy 00027 */ 00028 protected function configure_select_query($query, $policy) { 00029 parent::configure_select_query($query, $policy); 00030 if (!empty($this->sphinx_all_fields)) { 00031 $query->add_where('*', '=', $this->sphinx_all_fields); 00032 } 00033 $query->sphinx_features = $this->sphinx_features; 00034 } 00035 00036 // ---------------------------------------------- 00037 // Sphinx specific functions 00038 // ---------------------------------------------- 00039 00040 /** 00041 * Reindex 00042 * 00043 * @return Status 00044 */ 00045 public function index_rotate() { 00046 Load::commands('sphinx/index.rotate'); 00047 $cmd = new SphinxIndexRotateCommand($this); 00048 return $cmd->execute(); 00049 } 00050 00051 /** 00052 * Return a count suitable for pagers. 00053 * 00054 * Sphinx will return a limited number of results, usually 1,000, regardless 00055 * of the number of matches. This is defined by the configuration setting 00056 * "max_matches" in the server config file. 00057 * 00058 * This means limiting a result to - say - items 1,100 to 1,110 will result in 00059 * an error, and due to the Gyro way of dealing with DB error will raise an exception. 00060 * 00061 * Therefor when creating a pager instance, use this function rather than the 00062 * usual count() function. 00063 * 00064 * @return int 00065 */ 00066 public function count_pager() { 00067 return min($this->count(), APP_SPHINX_MAX_MATCHES); 00068 } 00069 00070 /** 00071 * Set a sphinx feature 00072 */ 00073 public function set_sphinx_feature($name, $value) { 00074 $this->sphinx_features[$name] = $value; 00075 } 00076 00077 /** 00078 * Get a sphinx feature 00079 * 00080 * @return mixed The feature's value or NULL, if not set 00081 */ 00082 public function get_sphinx_feature($name) { 00083 return Arr::get_item($this->sphinx_features, $name, null); 00084 } 00085 }