Example #1
0
 /**
  * Возвращает запрос к сфинксу
  * @return \yii\sphinx\Query
  * @throws \yii\base\InvalidConfigException
  */
 public function getSphinxQuery()
 {
     if ($this->_sphinxQuery === null) {
         $this->_sphinxQuery = \Yii::createObject(\yii\sphinx\Query::className());
         $this->_sphinxQuery->from($this->index)->options(array_merge(["ranker" => "wordcount"], $this->options));
     }
     return $this->_sphinxQuery;
 }
Example #2
0
 /**
  * @inheritdoc
  */
 protected function prepareTotalCount()
 {
     if (!$this->query instanceof Query) {
         throw new InvalidConfigException('The "query" property must be an instance "' . Query::className() . '" or its subclasses.');
     }
     if (!empty($this->query->showMeta)) {
         $meta = $this->getMeta();
         if (isset($meta['total_found'])) {
             return (int) $meta['total_found'];
         }
         if (isset($meta['total'])) {
             return (int) $meta['total'];
         }
     }
     $query = clone $this->query;
     return (int) $query->limit(-1)->offset(-1)->orderBy([])->facets([])->showMeta(false)->count('*', $this->db);
 }