From be2b76d40f1ecf9242aeabc94eabcde71dd5b09d Mon Sep 17 00:00:00 2001 From: Paul Klimov Date: Wed, 12 Feb 2014 23:20:12 +0200 Subject: [PATCH] Method "callSnippetsInternal" for the Sphinx Query extracted --- extensions/sphinx/ActiveQuery.php | 15 +++++++++++++++ extensions/sphinx/Query.php | 14 +++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/extensions/sphinx/ActiveQuery.php b/extensions/sphinx/ActiveQuery.php index 3961bd6522..b74846cec4 100644 --- a/extensions/sphinx/ActiveQuery.php +++ b/extensions/sphinx/ActiveQuery.php @@ -201,4 +201,19 @@ class ActiveQuery extends Query implements ActiveQueryInterface } return $result; } + + /** + * @inheritdoc + */ + protected function callSnippets(array $source) + { + $from = $this->from; + if ($from === null) { + /** @var ActiveRecord $modelClass */ + $modelClass = $this->modelClass; + $tableName = $modelClass::indexName(); + $from = [$tableName]; + } + return $this->callSnippetsInternal($source, $from[0]); + } } diff --git a/extensions/sphinx/Query.php b/extensions/sphinx/Query.php index a2c70e1848..8ad7c3ae5c 100644 --- a/extensions/sphinx/Query.php +++ b/extensions/sphinx/Query.php @@ -692,6 +692,18 @@ class Query extends Component implements QueryInterface * @return array snippets list. */ protected function callSnippets(array $source) + { + return $this->callSnippetsInternal($source, $this->from[0]); + } + + /** + * Builds a snippets from provided source data by the given index. + * @param array $source the source data to extract a snippet from. + * @param string $from name of the source index. + * @return array snippets list. + * @throws InvalidCallException in case [[match]] is not specified. + */ + protected function callSnippetsInternal(array $source, $from) { $connection = $this->getConnection(); $match = $this->match; @@ -699,7 +711,7 @@ class Query extends Component implements QueryInterface throw new InvalidCallException('Unable to call snippets: "' . $this->className() . '::match" should be specified.'); } return $connection->createCommand() - ->callSnippets($this->from[0], $source, $match, $this->snippetOptions) + ->callSnippets($from, $source, $match, $this->snippetOptions) ->queryColumn(); } }