-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from hkulekci/feature/search-module
#6 Search Module
- Loading branch information
Showing
18 changed files
with
597 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* Elastica Configuration Override | ||
* | ||
* This configuration override file is for overriding environment-specific and | ||
* security-sensitive configuration information. Copy this file without the | ||
* .dist extension at the end and populate values as needed. | ||
* | ||
* @NOTE: This file is ignored from Git by default with the .gitignore included | ||
* in ZendSkeletonApplication. This is a good practice, as it prevents sensitive | ||
* credentials from accidentally being committed into version control. | ||
*/ | ||
|
||
return [ | ||
'elastica' => [ | ||
'servers' => [ | ||
'host' => '127.0.0.1', | ||
'port' => 9200, | ||
] | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
<?php | ||
return array( | ||
); | ||
return [ | ||
'service_manager' => [ | ||
'factories' => [ | ||
'search.client.elastic' => 'Search\Client\Factory\ElasticClientFactory', | ||
'search.index.user' => 'Search\Index\Service\Factory\UserIndexServiceFactory', | ||
'search.query.user' => 'Search\Query\Service\Factory\UserQueryServiceFactory', | ||
], | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
/** | ||
* Elasticsearch Client Service | ||
* | ||
* @since Oct 2015 | ||
* @author Haydar KULEKCI <[email protected]> | ||
*/ | ||
namespace Search\Client; | ||
|
||
use Elastica\Client as ElasticaClient; | ||
use Search\Client\Interfaces\SearchClientInterface; | ||
|
||
class ElasticClient extends ElasticaClient implements SearchClientInterface | ||
{ | ||
} |
29 changes: 29 additions & 0 deletions
29
module/Search/src/Search/Client/Factory/ElasticClientFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
/** | ||
* Elastica Client Factory | ||
* | ||
* @since Nov 2015 | ||
* @author Haydar KULEKCI <[email protected]> | ||
*/ | ||
namespace Search\Client\Factory; | ||
|
||
use Search\Client\ElasticClient; | ||
use Zend\ServiceManager\FactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
class ElasticClientFactory implements FactoryInterface | ||
{ | ||
/** | ||
* Create elastica client | ||
* | ||
* @param ServiceLocatorInterface $sm | ||
* @return ElasticClient | ||
*/ | ||
public function createService(ServiceLocatorInterface $sm) | ||
{ | ||
$config = $sm->get('Config'); | ||
$clientConfig = isset($config['elastica']) ? $config['elastica'] : array(); | ||
|
||
return new ElasticClient($clientConfig); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
module/Search/src/Search/Client/Factory/SolrClientFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* Solra Client Factory | ||
* | ||
* @since Nov 2015 | ||
* @author Haydar KULEKCI <[email protected]> | ||
*/ | ||
namespace Search\Client\Factory; | ||
|
||
use Zend\ServiceManager\FactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
class SolrClientFactory implements FactoryInterface | ||
{ | ||
/** | ||
* Create Solr client | ||
* | ||
* @param ServiceLocatorInterface $sm | ||
* @return SolrClient | ||
*/ | ||
public function createService(ServiceLocatorInterface $sm) | ||
{ | ||
//TODO: Return a new Solr Client here | ||
// return new SolrClient($clientConfig); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
module/Search/src/Search/Client/Interfaces/SearchClientInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
/** | ||
* Search Client Inteface | ||
* | ||
* @since Nov 2015 | ||
* @author Haydar KULEKCI <[email protected]> | ||
*/ | ||
namespace Search\Client\Interfaces; | ||
|
||
interface SearchClientInterface | ||
{ | ||
} |
12 changes: 12 additions & 0 deletions
12
module/Search/src/Search/Exception/MissingDataException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
/** | ||
* Abstract Index Service | ||
* | ||
* @since Oct 2015 | ||
* @author Haydar KULEKCI <[email protected]> | ||
*/ | ||
namespace Search\Exception; | ||
|
||
class MissingDataException extends \InvalidArgumentException | ||
{ | ||
} |
31 changes: 31 additions & 0 deletions
31
module/Search/src/Search/Index/Service/AbstractIndexService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/** | ||
* Abstract Index Service | ||
* | ||
* @since Oct 2015 | ||
* @author Haydar KULEKCI <[email protected]> | ||
*/ | ||
namespace Search\Index\Service; | ||
|
||
use Search\Exception\MissingDataException; | ||
use Search\Service\AbstractSearchService; | ||
|
||
class AbstractIndexService extends AbstractSearchService | ||
{ | ||
/** | ||
* | ||
* @param array $data | ||
* @param integer $version | ||
* @return null | ||
*/ | ||
public function index(array $data, $version = 1) | ||
{ | ||
if (!array_key_exists('id', $data)) { | ||
throw new MissingDataException('`id` field is requeired to index data'); | ||
} | ||
|
||
//TODO: this creation will be moved to a builder | ||
$document = new \Elastica\Document($data['id'], $data); | ||
$this->getType($version)->addDocument($document); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
module/Search/src/Search/Index/Service/Factory/UserIndexServiceFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* Abstract Index Service Factory | ||
* | ||
* @since Nov 2015 | ||
* @author Haydar KULEKCI <[email protected]> | ||
*/ | ||
namespace Search\Index\Service\Factory; | ||
|
||
use Search\Index\Service\UserIndexService; | ||
use Zend\ServiceManager\FactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
class UserIndexServiceFactory implements FactoryInterface | ||
{ | ||
/** | ||
* Create service | ||
* | ||
* @param ServiceLocatorInterface $serviceLocator | ||
* @return UserIndexService | ||
*/ | ||
public function createService(ServiceLocatorInterface $sm) | ||
{ | ||
$userIndexService = new UserIndexService($sm->get('search.client.elastic')); | ||
|
||
return $userIndexService; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
module/Search/src/Search/Index/Service/UserIndexService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* Abstract Index Service | ||
* | ||
* @since Oct 2015 | ||
* @author Haydar KULEKCI <[email protected]> | ||
*/ | ||
namespace Search\Index\Service; | ||
|
||
class UserIndexService extends AbstractIndexService | ||
{ | ||
/** | ||
* @var string|array | ||
*/ | ||
protected $index = [ | ||
1 => 'users' | ||
]; | ||
|
||
/** | ||
* @var string|array | ||
*/ | ||
protected $type = [ | ||
1 => 'user' | ||
]; | ||
} |
52 changes: 52 additions & 0 deletions
52
module/Search/src/Search/Paginator/Adapter/ElasticsearchAdapter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* Elasticsearch Paginator Adapter | ||
* | ||
* @since Nov 2015 | ||
* @author Haydar KULEKCI <[email protected]> | ||
*/ | ||
namespace Search\Paginator\Adapter; | ||
|
||
use Zend\Paginator\Adapter\ArrayAdapter; | ||
|
||
class ElasticsearchAdapter extends ArrayAdapter | ||
{ | ||
protected $meta = []; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param array $array ArrayAdapter to paginate | ||
*/ | ||
public function __construct(array $array = array(), $count=0) | ||
{ | ||
$this->array = $array; | ||
$this->count = $count; | ||
} | ||
|
||
/** | ||
* Returns an array of items for a page. | ||
* | ||
* @param int $offset Page offset | ||
* @param int $itemCountPerPage Number of items per page | ||
* @return array | ||
*/ | ||
public function getItems($offset, $itemCountPerPage) | ||
{ | ||
return $this->array; | ||
} | ||
|
||
public function getMeta($key) | ||
{ | ||
if (isset($this->meta[$key])) { | ||
return $this->meta[$key]; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function setMeta($key, $value) | ||
{ | ||
$this->meta[$key] = $value; | ||
} | ||
} |
Oops, something went wrong.