瀏覽代碼

EAGLESIX-3004: Added respective code to MatchExpressionParser.js.

Scott Munday 11 年之前
父節點
當前提交
b73e376fdc
共有 2 個文件被更改,包括 34 次插入3 次删除
  1. 9 3
      lib/pipeline/matcher/MatchExpressionParser.js
  2. 25 0
      lib/pipeline/matcher/TextMatchExpressionParser.js

+ 9 - 3
lib/pipeline/matcher/MatchExpressionParser.js

@@ -32,6 +32,8 @@ var errors = require("../../Errors.js"),
 	AllElemMatchOp = require("./AllElemMatchOp.js"),
 	AtomicMatchExpression = require("./AtomicMatchExpression.js");
 
+proto.expressionParserTextCallback = require('./TextMatchExpressionParser').expressionParserTextCallbackReal;
+
 /**
  *
  * Check if the input element is an expression
@@ -123,10 +125,14 @@ proto._parse = function _parse(obj, topLevel){
 				if (status.code != ErrorCodes.OK)
 					return status;
 				root.add(status.result);*/
+			} else if ('text' === rest) {
+				if (e._type !== 'Object') {
+					return {code: ErrorCodes.BAD_VALUE, description: '$text expects an object'};
+				}
+
+				return this.expressionTextCallback(e);
 			}
-			else if ("comment" == rest) {
-				1+1;
-			}
+			else if ("comment" == rest) {}
 			else {
 				return {code:ErrorCodes.BAD_VALUE, description:"unknown top level operator: " + currname};
 			}

+ 25 - 0
lib/pipeline/matcher/TextMatchExpressionParser.js

@@ -0,0 +1,25 @@
+/**
+ * Expression parser's text callback function.
+ *
+ * @param queryObj
+ * @returns {*}
+ * @private
+ */
+var _expressionParserTextCallbackReal = function _expressionParserTextCallbackReal(queryObj) {
+	if (queryObj.$search._type !== 'string') {
+		return {code: ErrorCodes.BadValue, description: '$search needs a String'};
+	}
+
+	var e = new TextMatchExpression(),
+		s = e.init(query, language);
+
+	if (s.code !== 'OK') {
+		return s;
+	}
+
+	return e.release();
+}
+
+module.exports = {
+	expressionParserTextCallbackReal: _expressionParserTextCallbackReal
+};