-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
142 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Search\Search; | ||
use Illuminate\Console\Command; | ||
|
||
class CreateIndexCommand extends Command | ||
{ | ||
/** @var Search */ | ||
private $search; | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'index:create'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Command description'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(Search $search) | ||
{ | ||
$this->search = $search; | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
// | ||
} | ||
} |
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 |
---|---|---|
@@ -1,21 +1,105 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: cc | ||
* Date: 11/22/15 | ||
* Time: 1:36 AM | ||
*/ | ||
|
||
namespace App\Search; | ||
|
||
|
||
use Elasticsearch\ClientBuilder; | ||
use Elasticsearch\Client; | ||
|
||
class Search | ||
{ | ||
/** @var Client */ | ||
private $client; | ||
|
||
public function __construct() | ||
{ | ||
$client = ClientBuilder::create()->setHosts([env('ES_HOST')])->build(); | ||
$this->client = ClientBuilder::create() | ||
->setHosts([env('ES_HOST')]) | ||
->setRetries(3) | ||
->build(); | ||
} | ||
|
||
/** | ||
* Create the index. | ||
*/ | ||
public function createIndex() | ||
{ | ||
|
||
$create = [ | ||
'index' => 'my_index', | ||
'body' => [ | ||
'settings' => [ | ||
'number_of_shards' => 3, | ||
'number_of_replicas' => 2 | ||
], | ||
'mappings' => [ | ||
'my_type' => [ | ||
'_source' => [ | ||
'enabled' => true, | ||
'properties' => [ | ||
'first_name' => [ | ||
'type' => 'string', | ||
'analyzer' => 'standard' | ||
], | ||
'age' => [ | ||
'type' => 'integer' | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
]; | ||
|
||
} | ||
|
||
/** | ||
* Get the schema. | ||
* | ||
* @return array | ||
*/ | ||
public function getSchema() | ||
{ | ||
|
||
return []; | ||
} | ||
|
||
/** | ||
* Faceted search | ||
* | ||
* @param array $params | ||
*/ | ||
public function search(array $params) | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* Fast search for autocomplete. Only search specific fields. | ||
* | ||
* @param $text | ||
*/ | ||
public function searchAutocomplete($text) | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* Insert a document. | ||
* | ||
* @param array $doc | ||
*/ | ||
public function insertDocument(array $doc) | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* Insert an array of documents. | ||
* | ||
* @param array $docs | ||
*/ | ||
public function insertDocuments(array $docs) | ||
{ | ||
|
||
} | ||
} |