Matcher2.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. // Autogenerated by cport.py on 2013-09-17 14:37
  3. var Matcher2 = module.exports = function Matcher2(pattern, whereCallback){
  4. this._pattern = pattern;
  5. this.parser = new MatchExpressionParser();
  6. var result = this.parser.parse(pattern);
  7. if (result.code != ErrorCodes.OK)
  8. return {code:16810, description:"bad query: " + result};
  9. this._expression = result.result;
  10. }, klass = Matcher2, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  11. // DEPENDENCIES
  12. var errors = require("../../Errors.js"),
  13. ErrorCodes = errors.ErrorCodes,
  14. MatchExpressionParser = require("./MatchExpressionParser.js"),
  15. proto._expression = undefined;
  16. proto._pattern = undefined;
  17. /**
  18. *
  19. * matches checks the input doc against the internal element path to see if it is a match
  20. * @method matches
  21. * @param doc
  22. * @param details
  23. *
  24. */
  25. proto.matches = function matches(doc, details){
  26. if (!this._expression)
  27. return true;
  28. if ((doc != {}) && (Object.keys(doc)[0]))
  29. return this._expression.matchesBSON(doc, details);
  30. return this._expression.matches(mydoc, details);
  31. };
  32. /**
  33. *
  34. * Return the _pattern property
  35. * @method getQuery
  36. *
  37. */
  38. proto.getQuery = function getQuery(){
  39. return this._pattern;
  40. };
  41. /**
  42. *
  43. * Convert _pattern into a string
  44. * @method toString
  45. *
  46. */
  47. proto.toString = function toString(){
  48. return this._pattern.toString();
  49. };