@@ -27,7 +27,7 @@ exports.renderComments = function(req, res) {
27
27
search = { } ;
28
28
search . index = 'comments' ;
29
29
search . type = 'comment' ;
30
- search . size = 10 ;
30
+ search . size = 1000 ;
31
31
search . body = { } ;
32
32
search . body . query = { } ;
33
33
search . body . query . match = { } ;
@@ -40,7 +40,6 @@ exports.renderComments = function(req, res) {
40
40
41
41
client . search ( search ) . then ( function ( result ) {
42
42
var hits = result . hits . hits ;
43
- console . log ( hits ) ;
44
43
for ( var i = 0 ; i < hits . length ; i ++ ) {
45
44
hits [ i ] . votes = hits [ i ] . _source . upvotes . length - hits [ i ] . _source . downvotes . length ;
46
45
}
@@ -85,54 +84,55 @@ exports.storeComment = function(req, res) {
85
84
} ;
86
85
87
86
exports . upvoteComment = function ( req , res ) {
87
+
88
88
var comment = req . comment ;
89
- if ( ! comment . upvotes ) {
90
- comment . upvotes = [ ] ;
89
+ if ( ! comment . _source . upvotes ) {
90
+ comment . _source . upvotes = [ ] ;
91
91
}
92
- if ( ! comment . downvotes ) {
93
- comment . downvotes = [ ] ;
92
+ if ( ! comment . _source . downvotes ) {
93
+ comment . _source . downvotes = [ ] ;
94
94
}
95
- if ( comment . downvotes . indexOf ( req . session . user . id ) > - 1 ) {
96
- comment . downvotes . splice ( comment . downvotes . indexOf ( req . session . user . id ) , 1 ) ;
95
+ if ( comment . _source . downvotes . indexOf ( req . session . user . id ) > - 1 ) {
96
+ comment . _source . downvotes . splice ( comment . _source . downvotes . indexOf ( req . session . user . id ) , 1 ) ;
97
97
}
98
- if ( comment . upvotes . indexOf ( req . session . user . id ) === - 1 ) {
99
- comment . upvotes . push ( req . session . user . id ) ;
98
+ if ( comment . _source . upvotes . indexOf ( req . session . user . id ) === - 1 ) {
99
+ comment . _source . upvotes . push ( req . session . user . id ) ;
100
100
}
101
101
var update = { } ;
102
102
update . index = 'comments' ;
103
103
update . type = 'comment' ;
104
104
update . id = comment . _id ;
105
105
update . body = { } ;
106
106
update . body . doc = { } ;
107
- update . body . upvotes = comment . upvotes ;
108
- update . body . downvotes = comment . downvotes ;
107
+ update . body . doc . upvotes = comment . _source . upvotes ;
108
+ update . body . doc . downvotes = comment . _source . downvotes ;
109
109
client . update ( update ) . then ( function ( result ) {
110
110
res . send ( result ) ;
111
111
} ) ;
112
112
} ;
113
113
114
114
exports . downvoteComment = function ( req , res ) {
115
115
var comment = req . comment ;
116
- if ( ! comment . downvotes ) {
117
- comment . downvotes = [ ] ;
116
+ if ( ! comment . _source . downvotes ) {
117
+ comment . _source . downvotes = [ ] ;
118
118
}
119
- if ( ! comment . upvotes ) {
120
- comment . upvotes = [ ] ;
119
+ if ( ! comment . _source . upvotes ) {
120
+ comment . _source . upvotes = [ ] ;
121
121
}
122
- if ( comment . upvotes . indexOf ( req . session . user . id ) > - 1 ) {
123
- comment . upvotes . splice ( comment . upvotes . indexOf ( req . session . user . id ) , 1 ) ;
122
+ if ( comment . _source . upvotes . indexOf ( req . session . user . id ) > - 1 ) {
123
+ comment . _source . upvotes . splice ( comment . _source . upvotes . indexOf ( req . session . user . id ) , 1 ) ;
124
124
}
125
- if ( comment . downvotes . indexOf ( req . session . user . id ) === - 1 ) {
126
- comment . downvotes . push ( req . session . user . id ) ;
125
+ if ( comment . _source . downvotes . indexOf ( req . session . user . id ) === - 1 ) {
126
+ comment . _source . downvotes . push ( req . session . user . id ) ;
127
127
}
128
128
var update = { } ;
129
129
update . index = 'comments' ;
130
130
update . type = 'comment' ;
131
131
update . id = comment . _id ;
132
132
update . body = { } ;
133
133
update . body . doc = { } ;
134
- update . body . upvotes = comment . upvotes ;
135
- update . body . downvotes = comment . downvotes ;
134
+ update . body . doc . upvotes = comment . _source . upvotes ;
135
+ update . body . doc . downvotes = comment . _source . downvotes ;
136
136
client . update ( update ) . then ( function ( result ) {
137
137
res . send ( result ) ;
138
138
} ) ;
0 commit comments