@@ -699,7 +699,6 @@ Collection.prototype.search = function (filters, options, cb) {
699699
700700  query  =  self . kuzzle . addHeaders ( { body : filters } ,  this . headers ) ; 
701701
702- 
703702  self . kuzzle . query ( this . buildQueryArgs ( 'document' ,  'search' ) ,  query ,  options ,  function  ( error ,  result )  { 
704703    var  documents  =  [ ] ; 
705704
@@ -811,7 +810,8 @@ Collection.prototype.scroll = function (scrollId, options, filters, cb) {
811810 */ 
812811Collection . prototype . scrollSpecifications  =  function  ( scrollId ,  options ,  cb )  { 
813812  var 
814-     data  =  {  scrollId : scrollId  } ; 
813+     data  =  {  scrollId : scrollId  } , 
814+     self  =  this ; 
815815
816816  if  ( ! scrollId )  { 
817817    throw  new  Error ( 'Collection.scrollSpecifications: scrollId is required' ) ; 
@@ -828,14 +828,36 @@ Collection.prototype.scrollSpecifications = function (scrollId, options, cb) {
828828    data . scroll  =  options . scroll ; 
829829  } 
830830
831-   this . kuzzle . query ( 
832-     {  controller : 'collection' ,  action : 'scrollSpecifications' } , 
833-     this . kuzzle . addHeaders ( data ,  this . headers ) , 
834-     options , 
835-     function  ( err ,  res )  { 
836-       cb  ( err ,  err  ? undefined  : res . result ) ; 
831+   this . kuzzle . query ( {  controller : 'collection' ,  action : 'scrollSpecifications' } ,  this . kuzzle . addHeaders ( data ,  this . headers ) ,  options ,  function  ( err ,  res )  { 
832+     var 
833+       documents  =  [ ] ; 
834+ 
835+     if  ( err )  { 
836+       return  cb ( err ) ; 
837+     } 
838+ 
839+     res . result . hits . forEach ( function  ( doc )  { 
840+       var  newDocument  =  new  Document ( self ,  doc . _id ,  doc . _source ,  doc . _meta ) ; 
841+ 
842+       newDocument . version  =  doc . _version ; 
843+ 
844+       documents . push ( newDocument ) ; 
845+     } ) ; 
846+ 
847+     if  ( res . result . scrollId )  { 
848+       options . scrollId  =  res . result . scrollId ; 
837849    } 
838-   ) ; 
850+ 
851+     cb ( null ,  new  KuzzleSearchResult ( 
852+       self , 
853+       res . result . total , 
854+       documents , 
855+       res . result . aggregations  ? res . result . aggregations  : { } , 
856+       options , 
857+       null , 
858+       options . previous  ||  null 
859+     ) ) ; 
860+   } ) ; 
839861} ; 
840862
841863/** 
@@ -860,7 +882,34 @@ Collection.prototype.searchSpecifications = function (filters, options, cb) {
860882  data  =  self . kuzzle . addHeaders ( data ,  this . headers ) ; 
861883
862884  self . kuzzle . query ( {  controller : 'collection' ,  action : 'searchSpecifications'  } ,  data ,  options ,  function  ( err ,  res )  { 
863-     cb ( err ,  err  ? undefined  : res . result ) ; 
885+     var 
886+       documents  =  [ ] ; 
887+ 
888+     if  ( err )  { 
889+       return  cb ( err ) ; 
890+     } 
891+ 
892+     res . result . hits . forEach ( function  ( doc )  { 
893+       var  newDocument  =  new  Document ( self ,  doc . _id ,  doc . _source ,  doc . _meta ) ; 
894+ 
895+       newDocument . version  =  doc . _version ; 
896+ 
897+       documents . push ( newDocument ) ; 
898+     } ) ; 
899+ 
900+     if  ( res . result . scrollId )  { 
901+       options . scrollId  =  res . result . scrollId ; 
902+     } 
903+ 
904+     cb ( null ,  new  KuzzleSearchResult ( 
905+       self , 
906+       res . result . total , 
907+       documents , 
908+       res . result . aggregations  ? res . result . aggregations  : { } , 
909+       options , 
910+       filters , 
911+       options . previous  ||  null 
912+     ) ) ; 
864913  } ) ; 
865914} ; 
866915
0 commit comments