Skip to content

Commit

Permalink
Add more skeleton code (#8 #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
cachan committed Nov 22, 2015
1 parent 0532bba commit 30964c3
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 10 deletions.
47 changes: 47 additions & 0 deletions app/Console/Commands/CreateIndexCommand.php
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()
{
//
}
}
5 changes: 3 additions & 2 deletions app/Http/Controllers/Api/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

class SearchController extends Controller
{
/** @var Search */
private $search;

public function __construct(Search $search)
{
var_dump($search);
$this->search = $search;
}
/**
* Display a listing of the resource.
Expand All @@ -23,7 +25,6 @@ public function __construct(Search $search)
*/
public function getIndex(Request $request)
{

foreach ($request->all() as $key => $value) {
if ('q' === $key) {
// Fuzzy search.
Expand Down
100 changes: 92 additions & 8 deletions app/Search/Search.php
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)
{

}
}

0 comments on commit 30964c3

Please sign in to comment.