@@ -8,9 +8,61 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
88 $scope . resultsRows = [ ] ;
99 $scope . searchLoading = false ;
1010 $scope . explainLoading = false ;
11+ $scope . nextLoading = false ;
1112 $scope . resultExplan = false ;
12-
13+ $scope . scrollId = null ;
14+ $scope . gotNext = false ;
15+
16+ $scope . nextSearch = function ( ) {
17+ $scope . error = "" ;
18+ $scope . nextLoading = true ;
19+ $scope . $apply ( ) ;
20+
21+
22+ if ( $scope . scrollId == null || $scope . scrollId == "" ) {
23+ $scope . error = "tryed scrolling with empty scrollId" ;
24+ return ;
25+ }
1326
27+ $http . get ( $scope . url + "_search/scroll?scroll=1m&scroll_id=" + $scope . scrollId )
28+ . success ( function ( data , status , headers , config ) {
29+ var handler = ResultHandlerFactory . create ( data ) ;
30+ var body = handler . getBody ( )
31+
32+ if ( body . length == null || body . length == 0 ) {
33+ $scope . gotNext = false ;
34+ }
35+ else
36+ {
37+ $scope . scrollId = handler . getScrollId ( ) ;
38+ }
39+
40+ if ( $scope . resultsRows . length > 0 ) {
41+ $scope . resultsRows = $scope . resultsRows . concat ( handler . getBody ( ) ) ;
42+ }
43+ else {
44+ $scope . resultsColumns = handler . getHead ( ) ;
45+ $scope . resultsRows = handler . getBody ( ) ;
46+
47+ }
48+
49+
50+ } )
51+ . error ( function ( data , status , headers , config ) {
52+ if ( data == "" ) {
53+ $scope . error = "Error occured! response is not avalible." ;
54+ }
55+ else {
56+ $scope . error = JSON . stringify ( data ) ;
57+ $scope . scrollId = null ;
58+ }
59+ } )
60+ . finally ( function ( ) {
61+ $scope . nextLoading = false ;
62+ $scope . $apply ( )
63+ } ) ;
64+
65+ }
1466
1567 $scope . search = function ( ) {
1668 // Reset results and error box
@@ -28,6 +80,10 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
2880 $http . post ( $scope . url + "_sql" , query )
2981 . success ( function ( data , status , headers , config ) {
3082 var handler = ResultHandlerFactory . create ( data ) ;
83+ if ( handler . isScroll ) {
84+ $scope . gotNext = true ;
85+ $scope . scrollId = handler . getScrollId ( ) ;
86+ }
3187 $scope . resultsColumns = handler . getHead ( ) ;
3288 $scope . resultsRows = handler . getBody ( ) ;
3389
0 commit comments