Skip to content

Commit aabec4d

Browse files
committed
Improve comments
1 parent 1ffcc19 commit aabec4d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ services:
2222
interval: 10s
2323
timeout: 10s
2424
retries: 5
25-
s

src/Scout/ScoutEngine.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use MongoDB\Exception\RuntimeException as MongoDBRuntimeException;
2222
use MongoDB\Laravel\Connection;
2323
use Override;
24+
use stdClass;
2425
use Traversable;
2526
use TypeError;
2627

@@ -212,6 +213,13 @@ private function performSearch(Builder $builder, ?int $offset = null): array
212213
return $cursor->toArray();
213214
}
214215

216+
// Using compound to combine search operators
217+
// https://www.mongodb.com/docs/atlas/atlas-search/compound/#options
218+
// "should" specifies conditions that contribute to the relevance score
219+
// at least one of them must match,
220+
// - "text" search for the text including fuzzy matching
221+
// - "wildcard" allows special characters like * and ?, similar to LIKE in SQL
222+
// These are the only search operators to accept wildcard path.
215223
$compound = [
216224
'should' => [
217225
[
@@ -236,7 +244,6 @@ private function performSearch(Builder $builder, ?int $offset = null): array
236244
// "filter" specifies conditions on exact values to match
237245
// "mustNot" specifies conditions on exact values that must not match
238246
// They don't contribute to the relevance score
239-
// https://www.mongodb.com/docs/atlas/atlas-search/compound/#options
240247
foreach ($builder->wheres as $field => $value) {
241248
if ($field === '__soft_deleted') {
242249
$value = (bool) $value;
@@ -378,8 +385,9 @@ private function performMap(Builder $builder, array $results, Model $model, bool
378385
* This is an estimate if the count is larger than 1000.
379386
*
380387
* @see Engine::getTotalCount()
388+
* @see https://www.mongodb.com/docs/atlas/atlas-search/counting/
381389
*
382-
* @param mixed $results
390+
* @param stdClass[] $results
383391
*/
384392
#[Override]
385393
public function getTotalCount($results): int
@@ -388,6 +396,8 @@ public function getTotalCount($results): int
388396
return 0;
389397
}
390398

399+
// __count field is added by the aggregation pipeline in performSearch()
400+
// using the count.lowerBound in the $search stage
391401
return $results[0]->__count;
392402
}
393403

0 commit comments

Comments
 (0)