Completed
Push — master ( dceab7...a92a53 )
by Christopher
08:16 queued 04:04
created

ElasticsearchDsl::getEsClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Triadev\Es\Dsl;
3
4
use Elasticsearch\Client;
5
use ONGR\ElasticsearchDSL\Search as OngrSearch;
6
use Triadev\Es\Contract\ElasticsearchContract;
7
use Triadev\Es\Dsl\Contract\ElasticsearchDslContract;
8
use Triadev\Es\Dsl\Dsl\Search;
9
use Triadev\Es\Dsl\Dsl\Suggestion;
10
11
class ElasticsearchDsl implements ElasticsearchDslContract
12
{
13
    /**
14
     * Get es client
15
     *
16
     * @return Client
17
     */
18 1
    public function getEsClient(): Client
19
    {
20 1
        return $this->getElasticsearch()->getClient();
21
    }
22
    
23 1
    private function getElasticsearch() : ElasticsearchContract
24
    {
25 1
        return app(ElasticsearchContract::class);
26
    }
27
    
28
    /**
29
     * Search
30
     *
31
     * @param OngrSearch|null $search
32
     * @param string|null $esIndex
33
     * @param string|null $esType
34
     * @return Search
35
     */
36 14
    public function search(
37
        ?OngrSearch $search = null,
38
        ?string $esIndex = null,
39
        ?string $esType = null
40
    ): Search {
41 14
        return app()->makeWith(Search::class, [
42 14
            'search' => $search,
43 14
            'esIndex' => $esIndex,
44 14
            'esType' => $esType
45
        ]);
46
    }
47
    
48
    /**
49
     * Suggestion
50
     *
51
     * @param OngrSearch|null $search
52
     * @return Suggestion
53
     */
54 3
    public function suggest(?OngrSearch $search = null): Suggestion
55
    {
56 3
        return app()->makeWith(Suggestion::class, [
57 3
            'search' => $search
58
        ]);
59
    }
60
}
61