Passed
Push — master ( 099c87...4cfe3e )
by Christopher
07:03 queued 01:40
created

Search::getIndex()   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\Leopard\Business\Dsl;
3
4
use ONGR\ElasticsearchDSL\Sort\FieldSort;
5
use Triadev\Leopard\Busines\Dsl\Query\Specialized;
6
use Triadev\Leopard\Business\Dsl\Query\Compound;
7
use Triadev\Leopard\Business\Dsl\Query\Fulltext;
8
use Triadev\Leopard\Business\Dsl\Query\Geo;
9
use Triadev\Leopard\Business\Dsl\Query\InnerHit;
10
use Triadev\Leopard\Business\Dsl\Query\Joining;
11
use Triadev\Leopard\Business\Dsl\Query\TermLevel;
12
13
class Search extends AbstractQuery
14
{
15
    /**
16
     * Aggregation
17
     *
18
     * @param \Closure $aggregation
19
     * @return Search
20
     */
21 1
    public function aggregation(\Closure $aggregation) : Search
22
    {
23 1
        $aggregation(new Aggregation($this->search));
24 1
        return $this;
25
    }
26
    
27
    /**
28
     * Term level
29
     *
30
     * @return TermLevel
31
     */
32 22
    public function termLevel() : TermLevel
33
    {
34 22
        return new TermLevel($this->search, $this->model);
35
    }
36
    
37
    /**
38
     * Fulltext
39
     *
40
     * @return Fulltext
41
     */
42 2
    public function fulltext() : Fulltext
43
    {
44 2
        return new Fulltext($this->search, $this->model);
45
    }
46
    
47
    /**
48
     * Geo
49
     *
50
     * @return Geo
51
     */
52 1
    public function geo() : Geo
53
    {
54 1
        return new Geo($this->search, $this->model);
55
    }
56
    
57
    /**
58
     * Compound
59
     *
60
     * @return Compound
61
     */
62 7
    public function compound() : Compound
63
    {
64 7
        return new Compound($this->search, $this->model);
65
    }
66
    
67
    /**
68
     * Joining
69
     *
70
     * @return Joining
71
     */
72 1
    public function joining() : Joining
73
    {
74 1
        return new Joining($this->search, $this->model);
75
    }
76
    
77
    /**
78
     * Specialized
79
     *
80
     * @return Specialized
81
     */
82 1
    public function specialized() : Specialized
83
    {
84 1
        return new Specialized($this->search, $this->model);
85
    }
86
    
87
    /**
88
     * Inner hit
89
     *
90
     * @return InnerHit
91
     */
92 1
    public function innerHit() : InnerHit
93
    {
94 1
        return new InnerHit($this->search, $this->model);
95
    }
96
    
97
    /**
98
     * Paginate
99
     *
100
     * @param int $page
101
     * @param int $limit
102
     * @return Search
103
     */
104 1
    public function paginate(int $page, int $limit = 25) : Search
105
    {
106 1
        $this->search->setFrom($limit * ($page - 1))->setSize($limit);
107 1
        return $this;
108
    }
109
    
110
    /**
111
     * Min score
112
     *
113
     * @param int $minScore
114
     * @return Search
115
     */
116 1
    public function minScore(int $minScore) : Search
117
    {
118 1
        $this->search->setMinScore($minScore);
119 1
        return $this;
120
    }
121
    
122
    /**
123
     * Sort
124
     *
125
     * @param string $field
126
     * @param string $order
127
     * @param array $params
128
     * @return Search
129
     */
130 1
    public function sort(string $field, string $order = FieldSort::DESC, array $params = []) : Search
131
    {
132 1
        $this->search->addSort(new FieldSort(
133 1
            $field,
134 1
            $order,
135 1
            $params
136
        ));
137
        
138 1
        return $this;
139
    }
140
}
141