Commit 94e2f7fc by artur

Merge branch 'master' of github.com:yiisoft/yii2

parents 6c25675d 8dd3fad7
......@@ -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 <mail@cebe.cc>
* @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.
......@@ -176,6 +179,14 @@ class ActiveRecord extends BaseActiveRecord
}
/**
* @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
* @throws \yii\base\InvalidCallException when record is not new
......@@ -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...
}
......
......@@ -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
......
......@@ -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 = [];
......
......@@ -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 = [];
......@@ -526,6 +531,18 @@ class Query extends Component implements QueryInterface
}
/**
* 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.
* @return static the query object itself
......
......@@ -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;
......
......@@ -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)
......
......@@ -56,7 +56,8 @@ class BaseFileHelper
$parts[] = $part;
}
}
return implode($ds, $parts);
$path = implode($ds, $parts);
return $path === '' ? '.' : $path;
}
/**
......
......@@ -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'));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment