Skip to content

Commit 797d703

Browse files
committed
Adds hasMore and reset for AV.SearchQuery.
1 parent c56fe4d commit 797d703

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/search.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,26 @@ module.exports = function(AV) {
196196
return json;
197197
},
198198

199+
/**
200+
* Returns true when there are more documents can be retrieved by this
201+
* query instance, you can call find function to get more results.
202+
* @see AV.SearchQuery#find
203+
* @return {Boolean}
204+
*/
205+
hasMore: function() {
206+
return !this._hitEnd;
207+
},
208+
209+
/**
210+
* Reset current query instance state(such as sid, hits etc) except params
211+
* for a new searching. After resetting, hasMore() will return true.
212+
*/
213+
reset: function() {
214+
this._hitEnd = false;
215+
this._sid = null;
216+
this._hits = 0;
217+
},
218+
199219
/**
200220
* Retrieves a list of AVObjects that satisfy this query.
201221
* Either options.success or options.error is called when the find
@@ -216,6 +236,9 @@ module.exports = function(AV) {
216236
if(response.sid) {
217237
self._oldSid = self._sid;
218238
self._sid = response.sid;
239+
} else {
240+
self._sid = null;
241+
self._hitEnd = true;
219242
}
220243
self._hits = response.hits || 0;
221244

0 commit comments

Comments
 (0)