ElasticsearchDsl::suggest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
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 app(ElasticsearchContract::class)->getClient();
21
    }
22
    
23
    /**
24
     * Search
25
     *
26
     * @param OngrSearch|null $search
27
     * @param string|null $esIndex
28
     * @param string|null $esType
29
     * @return Search
30
     */
31 14
    public function search(
32
        ?OngrSearch $search = null,
33
        ?string $esIndex = null,
34
        ?string $esType = null
35
    ): Search {
36 14
        return app()->makeWith(Search::class, [
37 14
            'search' => $search,
38 14
            'esIndex' => $esIndex,
39 14
            'esType' => $esType
40
        ]);
41
    }
42
    
43
    /**
44
     * Suggestion
45
     *
46
     * @param OngrSearch|null $search
47
     * @return Suggestion
48
     */
49 3
    public function suggest(?OngrSearch $search = null): Suggestion
50
    {
51 3
        return app()->makeWith(Suggestion::class, [
52 3
            'search' => $search
53
        ]);
54
    }
55
}
56