浏览代码

EAGLESIX-3082: Fixed test cases.

Scott Munday 11 年之前
父节点
当前提交
163edb6b82
共有 1 个文件被更改,包括 9 次插入20 次删除
  1. 9 20
      lib/pipeline/documentSources/SortDocumentSource.js

+ 9 - 20
lib/pipeline/documentSources/SortDocumentSource.js

@@ -2,7 +2,8 @@
 
 var async = require("async"),
 	DocumentSource = require("./DocumentSource"),
-	LimitDocumentSource = require("./LimitDocumentSource");
+	LimitDocumentSource = require("./LimitDocumentSource"),
+	Document = require('../Document');
 
 /**
  * A document source sorter
@@ -49,10 +50,6 @@ proto.getFactory = function getFactory(){
 	return klass;	// using the ctor rather than a separate .create() method
 };
 
-klass.GetDepsReturn = {
-	SEE_NEXT: "SEE_NEXT" // Add the next Source's deps to the set
-};
-
 proto.dispose = function dispose() {
 	this.docIterator = 0;
 	this.documents = [];
@@ -68,7 +65,7 @@ proto.getDependencies = function getDependencies(deps) {
 	for(var i = 0; i < this.vSortKey.length; ++i) {
 		this.vSortKey[i].addDependencies(deps);
 	}
-	return klass.GetDepsReturn.SEE_NEXT;
+	return DocumentSource.GetDepsReturn.SEE_NEXT;
 };
 
 proto.coalesce = function coalesce(nextSource) {
@@ -96,7 +93,7 @@ proto.getNext = function getNext(callback) {
 			function(next) {
 				if (!self.populated)
 					self.populate(function(err) {
-						return next(err);
+						next(err);
 					});
 				else
 					next();
@@ -217,6 +214,7 @@ proto.populate = function populate(callback) {
 					// Don't add EOF; it doesn't sort well.
 					if (doc !== DocumentSource.EOF)
 						self.documents.push(doc);
+
 					return cb();
 				});
 			},
@@ -265,7 +263,7 @@ klass.IteratorFromCursor = (function(){
 })();
 
 proto.populateFromCursors = function populateFromCursors(cursors){
-	for (var i = 0; i < cursors.lenth; i++) {
+	for (var i = 0; i < cursors.length; i++) {
 		// TODO Create class
 		//this.iterators.push(boost::make_shared<IteratorFromBsonArray>(this, cursors[i]));
 	}
@@ -338,19 +336,11 @@ proto.compare = function compare(lhs,rhs) {
 	  However, the tricky part is what to do is none of the sort keys are
 	  present.  In this case, consider the document less.
 	*/
-	var n = this.vSortKey.length;
-	if ( n == 1) { // simple fast case
-		if ( this.vAscending[0] ) {
-			return Value.compare(lhs, rhs);
-		} else {
-			return -Value.compare(lhs, rhs);
-		}
-	}
 
-	// compound sort
-	for(var i = 0; i < n; ++i) {
+	for(var i = 0, n = this.vSortKey.length; i < n; ++i) {
+		var pathExpr = FieldPathExpression.create(this.vSortKey[i].getFieldPath(false).fieldNames.slice(1).join('.'));
+
 		/* evaluate the sort keys */
-		var pathExpr = FieldPathExpression.create(this.vSortKey[i].getFieldPath(false));
 		var left = pathExpr.evaluate(lhs), right = pathExpr.evaluate(rhs);
 
 		/*
@@ -406,7 +396,6 @@ proto.serializeSortKey = function serializeSortKey(explain) {
 klass.createFromJson = function createFromJson(elem, expCtx) {
 	if (typeof elem !== "object") throw new Error("code 15973; the " + klass.sortName + " key specification must be an object");
 
-	
 	return this.create(expCtx, elem);
 };