Skip to content

Commit ae63a17

Browse files
authored
Merge pull request #1 from mehdichaouch/search-limit
Add limit to SOSL search
2 parents fa07803 + 6b79d11 commit ae63a17

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/Search.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Search {
1818
'find' => '',
1919
'searchGroup' => '',
2020
'from' => null,
21+
'limit' => null,
2122
];
2223

2324
/**
@@ -47,6 +48,11 @@ class Search {
4748
*/
4849
protected $from = '';
4950

51+
/**
52+
* @var int
53+
*/
54+
protected $limit = null;
55+
5056
/**
5157
* HTTP Client Instance
5258
* @see \GuzzleHttp\Client
@@ -93,6 +99,7 @@ public function resetComponents() {
9399
'find' => '',
94100
'searchGroup' => '',
95101
'from' => null,
102+
'limit' => null,
96103
];
97104
}
98105

@@ -189,6 +196,10 @@ public function compiled() {
189196
. 'RETURNING ' . $this->components['from']
190197
. '(' . $this->components['select'] . ')';
191198

199+
if ($this->components['limit']) {
200+
$query .= ' LIMIT ' . $this->components['limit'];
201+
}
202+
192203
return $query;
193204
}
194205
/**
@@ -254,6 +265,11 @@ public function from($from) {
254265
return $this;
255266
}
256267

268+
public function limit($limit) {
269+
$this->components['limit'] = (int)$limit;
270+
return $this;
271+
}
272+
257273
public function in($searchGroup) {
258274
$searchGroup = strtoupper($searchGroup);
259275
if (!in_array($searchGroup, ['ALL', 'NAME', 'EMAIL', 'PHONE', 'SIDEBAR'])) {
@@ -342,4 +358,4 @@ public function notFind($value_or_array_or_callable)
342358
{
343359
return $this->find($value_or_array_or_callable, 'andnot');
344360
}
345-
}
361+
}

0 commit comments

Comments
 (0)