5454 */
5555final class ScoutEngine extends Engine
5656{
57- /**
58- * Name of the Atlas Search index.
59- *
60- * @todo make this configurable
61- */
57+ /** Name of the Atlas Search index. */
6258 private const INDEX_NAME = 'scout ' ;
6359
6460 // Atlas Search index management operations are asynchronous.
@@ -201,6 +197,10 @@ protected function performSearch(Builder $builder, ?int $offset = null): array
201197 ],
202198 ];
203199
200+ // "filter" specifies conditions on exact values to match
201+ // "mustNot" specifies conditions on exact values that must not match
202+ // They don't contribute to the relevance score
203+ // https://www.mongodb.com/docs/atlas/atlas-search/compound/#options
204204 foreach ($ builder ->wheres as $ field => $ value ) {
205205 $ compound ['filter ' ][] = ['equals ' => ['path ' => $ field , 'value ' => $ value ]];
206206 }
@@ -213,6 +213,7 @@ protected function performSearch(Builder $builder, ?int $offset = null): array
213213 $ compound ['mustNot ' ][] = ['in ' => ['path ' => $ field , 'value ' => $ value ]];
214214 }
215215
216+ // Sort by field value only if specified
216217 $ sort = [];
217218 foreach ($ builder ->orders as $ order ) {
218219 $ sort [$ order ['column ' ]] = $ order ['direction ' ] === 'asc ' ? 1 : -1 ;
@@ -224,7 +225,7 @@ protected function performSearch(Builder $builder, ?int $offset = null): array
224225 'index ' => self ::INDEX_NAME ,
225226 'compound ' => $ compound ,
226227 'count ' => ['type ' => 'lowerBound ' ],
227- ...($ builder -> orders ? ['sort ' => $ sort ] : []),
228+ ...($ sort ? ['sort ' => $ sort ] : []),
228229 ],
229230 ],
230231 [
@@ -482,7 +483,7 @@ private function performSearchIndexOperation(Closure $closure): void
482483 } catch (ServerException $ exception ) {
483484 // @todo add error codes
484485 if (in_array ($ exception ->getCode (), [])) {
485- throw new \RuntimeException ('Failed to perform search index operation. MongoDB Atlas cluster M10+ is required ' , 0 , $ exception );
486+ throw new \RuntimeException ('Failed to perform search index operation. A MongoDB Atlas Cluster is required. ' , 0 , $ exception );
486487 }
487488 }
488489 }
@@ -497,6 +498,7 @@ private function getMapping(Model $model): array
497498
498499 if ($ this ->usesSoftDelete ($ model )) {
499500 // This field is a boolean represented with the integers 0 and 1
501+ // https://www.mongodb.com/docs/atlas/atlas-search/field-types/number-type/#configure-fts-field-type-field-properties
500502 $ mapping ['fields ' ]['__soft_deleted ' ] ??= [
501503 'type ' => 'number ' ,
502504 'representation ' => 'int64 ' ,
0 commit comments