diff --git a/extensions/elasticsearch/ActiveRecord.php b/extensions/elasticsearch/ActiveRecord.php index 6ff1095d4f..b4b7abd5b5 100644 --- a/extensions/elasticsearch/ActiveRecord.php +++ b/extensions/elasticsearch/ActiveRecord.php @@ -42,6 +42,8 @@ use yii\helpers\StringHelper; * * @property float $score Returns the score of this record when it was retrieved via a [[find()]] query. This * property is read-only. + * @property array $highlight Returns a list of arrays with highlighted excerpts indexed by field names. This + * property is read-only. * * @author Carsten Brandt * @since 2.0 @@ -51,6 +53,7 @@ class ActiveRecord extends BaseActiveRecord private $_id; private $_score; private $_version; + private $_highlight; /** * Returns the database connection used by this AR class. @@ -175,6 +178,14 @@ class ActiveRecord extends BaseActiveRecord return $this->_score; } + /** + * @return array|null A list of arrays with highlighted excerpts indexed by field names. + */ + public function getHighlight() + { + return $this->_highlight; + } + /** * Sets the primary key * @param mixed $value @@ -302,6 +313,7 @@ class ActiveRecord extends BaseActiveRecord if ($pk === '_id') { $record->_id = $row['_id']; } + $record->_highlight = isset($row['highlight']) ? $row['highlight'] : null; $record->_score = isset($row['_score']) ? $row['_score'] : null; $record->_version = isset($row['_version']) ? $row['_version'] : null; // TODO version should always be available... } diff --git a/extensions/elasticsearch/CHANGELOG.md b/extensions/elasticsearch/CHANGELOG.md index 3710c9708c..92595c4693 100644 --- a/extensions/elasticsearch/CHANGELOG.md +++ b/extensions/elasticsearch/CHANGELOG.md @@ -5,8 +5,9 @@ Yii Framework 2 elasticsearch extension Change Log -------------------------- - Chg: asArray in ActiveQuery is now equal to using the normal Query. This means, that the output structure has changed and `with` is supported anymore. (cebe) -- Chg: Deletion of a record is now also considered successfull if the record did not exist. (cebe) +- Chg: Deletion of a record is now also considered successful if the record did not exist. (cebe) - Chg: Requirement changes: Yii now requires elasticsearch version 1.0 or higher (cebe) +- Enh #3527: Added `highlight` property to Query and ActiveRecord. (Borales) 2.0.0-beta April 13, 2014 diff --git a/extensions/elasticsearch/Command.php b/extensions/elasticsearch/Command.php index f1313ad15b..7528f0f7af 100644 --- a/extensions/elasticsearch/Command.php +++ b/extensions/elasticsearch/Command.php @@ -38,6 +38,11 @@ class Command extends Component * @var array list of arrays or json strings that become parts of a query */ public $queryParts; + /** + * @var array list of arrays to highlight search results on one or more fields + * @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-highlighting.html + */ + public $highlight; public $options = []; diff --git a/extensions/elasticsearch/Query.php b/extensions/elasticsearch/Query.php index 535e1c83eb..9c4f8e6c59 100644 --- a/extensions/elasticsearch/Query.php +++ b/extensions/elasticsearch/Query.php @@ -132,6 +132,11 @@ class Query extends Component implements QueryInterface * the elasticsearch [Query DSL](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl.html). */ public $filter; + /** + * @var array The highlight part of this search query. This is an array that allows to highlight search results + * on one or more fields. + */ + public $highlight; public $facets = []; @@ -525,6 +530,18 @@ class Query extends Component implements QueryInterface return $this; } + /** + * Sets a highlight parameters to retrieve from the documents. + * @param array $highlight array of parameters to highlight results. + * @return static the query object itself + * @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-highlighting.html + */ + public function highlight($highlight) + { + $this->highlight = $highlight; + return $this; + } + /** * Sets the source filtering, specifying how the `_source` field of the document should be returned. * @param array $source the source patterns to be selected. diff --git a/extensions/elasticsearch/QueryBuilder.php b/extensions/elasticsearch/QueryBuilder.php index 951e6f6d17..96aa374d43 100644 --- a/extensions/elasticsearch/QueryBuilder.php +++ b/extensions/elasticsearch/QueryBuilder.php @@ -97,6 +97,10 @@ class QueryBuilder extends \yii\base\Object $parts['filter'] = $whereFilter; } + if($query->highlight) { + $parts['highlight'] = $query->highlight; + } + $sort = $this->buildOrderBy($query->orderBy); if (!empty($sort)) { $parts['sort'] = $sort; diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index d210b03db6..b46901ae1b 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -28,6 +28,7 @@ Yii Framework 2 Change Log - Bug #3431: Allow using extended ErrorHandler class from the app namespace (cebe) - Bug #3436: Fixed the issue that `ServiceLocator` still returns the old component after calling `set()` with a new definition (qiangxue) - Bug #3458: Fixed the bug that the image rendered by `CaptchaAction` was using a wrong content type (MDMunir, qiangxue) +- Bug #3522: Fixed BaseFileHelper::normalizePath to allow a (.) for the current path. (skotos) - Bug: Fixed inconsistent return of `\yii\console\Application::runAction()` (samdark) - Enh #2264: `CookieCollection::has()` will return false for expired or removed cookies (qiangxue) - Enh #2435: `yii\db\IntegrityException` is now thrown on database integrity errors instead of general `yii\db\Exception` (samdark) diff --git a/framework/helpers/BaseFileHelper.php b/framework/helpers/BaseFileHelper.php index 0974d8d315..edf81a1df0 100644 --- a/framework/helpers/BaseFileHelper.php +++ b/framework/helpers/BaseFileHelper.php @@ -56,7 +56,8 @@ class BaseFileHelper $parts[] = $part; } } - return implode($ds, $parts); + $path = implode($ds, $parts); + return $path === '' ? '.' : $path; } /** diff --git a/tests/unit/framework/helpers/FileHelperTest.php b/tests/unit/framework/helpers/FileHelperTest.php index b8822dfb0e..3eb8f35e1c 100644 --- a/tests/unit/framework/helpers/FileHelperTest.php +++ b/tests/unit/framework/helpers/FileHelperTest.php @@ -369,10 +369,16 @@ class FileHelperTest extends TestCase $this->assertEquals("..{$ds}c", FileHelper::normalizePath('//a/.\\b//..//..//../../c')); // relative paths + $this->assertEquals(".", FileHelper::normalizePath('.')); + $this->assertEquals(".", FileHelper::normalizePath('./')); + $this->assertEquals("a", FileHelper::normalizePath('.\\a')); + $this->assertEquals("a{$ds}b", FileHelper::normalizePath('./a\\b')); + $this->assertEquals(".", FileHelper::normalizePath('./a\\../')); $this->assertEquals("..{$ds}..{$ds}a", FileHelper::normalizePath('../..\\a')); $this->assertEquals("..{$ds}..{$ds}a", FileHelper::normalizePath('../..\\a/../a')); $this->assertEquals("..{$ds}..{$ds}b", FileHelper::normalizePath('../..\\a/../b')); $this->assertEquals("..{$ds}a", FileHelper::normalizePath('./..\\a')); + $this->assertEquals("..{$ds}a", FileHelper::normalizePath('././..\\a')); $this->assertEquals("..{$ds}a", FileHelper::normalizePath('./..\\a/../a')); $this->assertEquals("..{$ds}b", FileHelper::normalizePath('./..\\a/../b')); }