File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed
Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,11 @@ public function getError(): array
147147 return $ this ->error ;
148148 }
149149
150+ public function getTotalHits (): int
151+ {
152+ return $ this ->hits ;
153+ }
154+
150155 public function toArray (): array
151156 {
152157 $ return = [
@@ -156,6 +161,7 @@ public function toArray(): array
156161 'timed_out ' => $ this ->timed_out ,
157162 'took ' => $ this ->took ,
158163 'total ' => $ this ->total ,
164+ 'hits ' => $ this ->hits ,
159165 ];
160166 if ($ this ->maxScore ) {
161167 $ return ['max_score ' ] = $ this ->maxScore ;
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ public function getQueryMeta(): QueryMeta
5353
5454 public function getQueryMetaAsArray (): array
5555 {
56- return $ this ->meta ->asArray ();
56+ return $ this ->meta ->toArray ();
5757 }
5858
5959 public function getDsl (): array
Original file line number Diff line number Diff line change 606606 'id ' ,
607607 '_id ' ,
608608]);
609+
610+ it ('tests meta total hits ' , function () {
611+ $ users = [];
612+ for ($ i = 0 ; $ i < 8500 ; $ i ++) {
613+ $ users [] = [
614+ 'name ' => "User {$ i }" ,
615+ 'age ' => rand (1 , 100 ),
616+ 'order ' => $ i ,
617+ 'title ' => rand (0 , 1 ) ? 'admin ' : 'user ' ,
618+ ];
619+ }
620+ User::insert ($ users );
621+
622+ $ query = User::wherePhrasePrefix ('name ' , 'User ' )->limit (10 )->get ();
623+ expect ($ query ->getQueryMeta ()->getTotalHits ())->toBe (8500 )
624+ ->and (count ($ query ))->toBe (10 );
625+ });
You can’t perform that action at this time.
0 commit comments