Browse Source

moved elasticsearch to extensions

tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
b081cf5e46
  1. 0
      extensions/elasticsearch/ActiveQuery.php
  2. 1
      extensions/elasticsearch/ActiveRecord.php
  3. 0
      extensions/elasticsearch/ActiveRelation.php
  4. 0
      extensions/elasticsearch/Cluster.php
  5. 0
      extensions/elasticsearch/Command.php
  6. 0
      extensions/elasticsearch/Connection.php
  7. 32
      extensions/elasticsearch/LICENSE.md
  8. 0
      extensions/elasticsearch/Node.php
  9. 0
      extensions/elasticsearch/Query.php
  10. 0
      extensions/elasticsearch/QueryBuilder.php
  11. 92
      extensions/elasticsearch/README.md
  12. 27
      extensions/elasticsearch/composer.json
  13. 2
      extensions/redis/ActiveQuery.php
  14. 2
      extensions/redis/README.md
  15. 2
      tests/unit/data/ar/elasticsearch/Customer.php
  16. 2
      tests/unit/data/ar/redis/Customer.php
  17. 3
      tests/unit/extensions/elasticsearch/ActiveRecordTest.php
  18. 14
      tests/unit/extensions/elasticsearch/ElasticSearchConnectionTest.php
  19. 5
      tests/unit/extensions/elasticsearch/ElasticSearchTestCase.php
  20. 2
      tests/unit/extensions/elasticsearch/QueryTest.php
  21. 22
      tests/unit/framework/elasticsearch/ElasticSearchConnectionTest.php

0
framework/yii/elasticsearch/ActiveQuery.php → extensions/elasticsearch/ActiveQuery.php

1
framework/yii/elasticsearch/ActiveRecord.php → extensions/elasticsearch/ActiveRecord.php

@ -24,6 +24,7 @@ use yii\helpers\StringHelper;
* For defining a record a subclass should at least implement the [[attributes()]] method to define
* attributes.
* The primary key (the `_id` field in elasticsearch terms) is represented by `getId()` and `setId()`.
* The primary key is not part of the attributes.
*
* The following is an example model called `Customer`:
*

0
framework/yii/elasticsearch/ActiveRelation.php → extensions/elasticsearch/ActiveRelation.php

0
framework/yii/elasticsearch/Cluster.php → extensions/elasticsearch/Cluster.php

0
framework/yii/elasticsearch/Command.php → extensions/elasticsearch/Command.php

0
framework/yii/elasticsearch/Connection.php → extensions/elasticsearch/Connection.php

32
extensions/elasticsearch/LICENSE.md

@ -0,0 +1,32 @@
The Yii framework is free software. It is released under the terms of
the following BSD License.
Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Yii Software LLC nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

0
framework/yii/elasticsearch/Node.php → extensions/elasticsearch/Node.php

0
framework/yii/elasticsearch/Query.php → extensions/elasticsearch/Query.php

0
framework/yii/elasticsearch/QueryBuilder.php → extensions/elasticsearch/QueryBuilder.php

92
extensions/elasticsearch/README.md

@ -0,0 +1,92 @@
Elasticsearch Query and ActiveRecord for Yii 2
==============================================
This extension provides the [elasticsearch](http://www.elasticsearch.org/) integration for the Yii2 framework.
It includes basic querying/search support and also implements the `ActiveRecord` pattern that allows you to store active
records in elasticsearch.
To use this extension, you have to configure the Connection class in your application configuration:
```php
return [
//....
'components' => [
'elasticsearch' => [
'class' => 'yii\elasticsearch\Connection',
'hosts' => [
['hostname' => 'localhost', 'port' => 9200],
// configure more hosts if you have a cluster
],
],
]
];
```
Installation
------------
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require yiisoft/yii2-elasticsearch "*"
```
or add
```json
"yiisoft/yii2-elasticsearch": "*"
```
to the require section of your composer.json.
Using the Query
---------------
TBD
Using the ActiveRecord
----------------------
For general information on how to use yii's ActiveRecord please refer to the [guide](https://github.com/yiisoft/yii2/blob/master/docs/guide/active-record.md).
For defining an elasticsearch ActiveRecord class your record class needs to extend from `yii\elasticsearch\ActiveRecord` and
implement at least the `attributes()` method to define the attributes of the record.
The primary key (the `_id` field in elasticsearch terms) is represented by `getId()` and `setId()` and can not be changed.
The primary key is not part of the attributes.
primary key can be defined via [[primaryKey()]] which defaults to `id` if not specified.
The primaryKey needs to be part of the attributes so make sure you have an `id` attribute defined if you do
not specify your own primary key.
The following is an example model called `Customer`:
```php
class Customer extends \yii\elasticsearch\ActiveRecord
{
public function attributes()
{
return ['id', 'name', 'address', 'registration_date'];
}
}
```
You may override [[index()]] and [[type()]] to define the index and type this record represents.
The general usage of elasticsearch ActiveRecord is very similar to the database ActiveRecord as described in the
[guide](https://github.com/yiisoft/yii2/blob/master/docs/guide/active-record.md).
It supports the same interface and features except the following limitations and additions(*!*):
- As elasticsearch does not support SQL, the query API does not support `join()`, `groupBy()`, `having()` and `union()`.
Sorting, limit, offset and conditional where are all supported.
- `from()` does not select the tables, but the [index](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/glossary.html#glossary-index)
and [type](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/glossary.html#glossary-type) to query against.
- `select()` has been replaced with `fields()` which basically does the same but `fields` is more elasticsearch terminology.
It defines the fields to retrieve from a document.
- `via`-relations can not be defined via a table as there are not tables in elasticsearch. You can only define relations via other records.
- As elasticsearch is a data storage and search engine there is of course support added for search your records.
TBD ...
- It is also possible to define relations from elasticsearch ActiveRecords to normal ActiveRecord classes and vice versa.

27
extensions/elasticsearch/composer.json

@ -0,0 +1,27 @@
{
"name": "yiisoft/yii2-elasticsearch",
"description": "Elasticsearch integration and ActiveRecord for the Yii framework",
"keywords": ["yii", "elasticsearch", "active-record", "search", "fulltext"],
"type": "yii2-extension",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?labels=ext%3Aelasticsearch",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"authors": [
{
"name": "Carsten Brandt",
"email": "mail@cebe.cc"
}
],
"require": {
"yiisoft/yii2": "*"
},
"autoload": {
"psr-0": { "yii\\elasticsearch\\": "" }
},
"target-dir": "yii/elasticsearch"
}

2
extensions/redis/ActiveQuery.php

@ -226,7 +226,7 @@ class ActiveQuery extends \yii\base\Component implements ActiveQueryInterface
{
$record = $this->one($db);
if ($record !== null) {
return $record->$attribute;
return $record->hasAttribute($attribute) ? $record->$attribute : null;
} else {
return null;
}

2
extensions/redis/README.md

@ -2,7 +2,7 @@ Redis Cache and ActiveRecord for Yii 2
======================================
This extension provides the [redis](http://redis.io/) key-value store support for the Yii2 framework.
It includes a `Cache` class and implents the `ActiveRecord` pattern that allows you to store active
It includes a `Cache` class and implements the `ActiveRecord` pattern that allows you to store active
records in redis.
To use this extension, you have to configure the Connection class in your application configuration:

2
tests/unit/data/ar/elasticsearch/Customer.php

@ -1,7 +1,7 @@
<?php
namespace yiiunit\data\ar\elasticsearch;
use yiiunit\framework\elasticsearch\ActiveRecordTest;
use yiiunit\extensions\elasticsearch\ActiveRecordTest;
/**
* Class Customer

2
tests/unit/data/ar/redis/Customer.php

@ -2,7 +2,7 @@
namespace yiiunit\data\ar\redis;
use yiiunit\framework\redis\ActiveRecordTest;
use yiiunit\extensions\redis\ActiveRecordTest;
class Customer extends ActiveRecord
{

3
tests/unit/framework/elasticsearch/ActiveRecordTest.php → tests/unit/extensions/elasticsearch/ActiveRecordTest.php

@ -1,9 +1,8 @@
<?php
namespace yiiunit\framework\elasticsearch;
namespace yiiunit\extensions\elasticsearch;
use yii\elasticsearch\Connection;
use yii\elasticsearch\ActiveQuery;
use yii\helpers\Json;
use yiiunit\framework\ar\ActiveRecordTestTrait;
use yiiunit\data\ar\elasticsearch\ActiveRecord;

14
tests/unit/extensions/elasticsearch/ElasticSearchConnectionTest.php

@ -0,0 +1,14 @@
<?php
namespace yiiunit\extensions\elasticsearch;
use yii\redis\Connection;
/**
* @group elasticsearch
*/
class ElasticSearchConnectionTest extends ElasticSearchTestCase
{
// TODO
}

5
tests/unit/framework/elasticsearch/ElasticSearchTestCase.php → tests/unit/extensions/elasticsearch/ElasticSearchTestCase.php

@ -1,10 +1,13 @@
<?php
namespace yiiunit\framework\elasticsearch;
namespace yiiunit\extensions\elasticsearch;
use Yii;
use yii\elasticsearch\Connection;
use yiiunit\TestCase;
Yii::setAlias('@yii/elasticsearch', __DIR__ . '/../../../../extensions/elasticsearch');
/**
* ElasticSearchTestCase is the base class for all elasticsearch related test cases
*/

2
tests/unit/framework/elasticsearch/QueryTest.php → tests/unit/extensions/elasticsearch/QueryTest.php

@ -1,6 +1,6 @@
<?php
namespace yiiunit\framework\elasticsearch;
namespace yiiunit\extensions\elasticsearch;
use yii\elasticsearch\Query;

22
tests/unit/framework/elasticsearch/ElasticSearchConnectionTest.php

@ -1,22 +0,0 @@
<?php
namespace yiiunit\framework\elasticsearch;
use yii\redis\Connection;
/**
* @group elasticsearch
*/
class ElasticSearchConnectionTest extends ElasticSearchTestCase
{
/**
* Empty DSN should throw exception
* @expectedException \yii\base\InvalidConfigException
*/
public function testEmptyDSN()
{
$db = new Connection();
$db->open();
}
}
Loading…
Cancel
Save