Skip to content

Instantly share code, notes, and snippets.

@jmakeig
Last active May 11, 2017 21:20
Show Gist options
  • Save jmakeig/cf67640486e06335cb19bbe765dcfe7a to your computer and use it in GitHub Desktop.
Save jmakeig/cf67640486e06335cb19bbe765dcfe7a to your computer and use it in GitHub Desktop.
Monkey patch of MarkLogic’s JSearch API to change the default values for slice(). Proof-of-concept. Don’t actually do this.
'use strict';
const jsearch = require('/MarkLogic/jsearch');
// Monkey patch
const proto = Object.getPrototypeOf(
// Doesn’t actually run a query
jsearch.collections('.').documents().where(cts.trueQuery())
);
const _slice = proto.slice;
Object.assign(proto, {
slice(start = 0, end = 9007199254740991) {
// Call the stashed original slice method with the new defaults
return _slice.call(this, start, end);
}
});
jsearch.documents().where(cts.trueQuery()).slice().result().results.length;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment