Skip to content
Browse files

tweak

  • Loading branch information...
1 parent c66c422 commit 606243b6fb7d8b7e3ece35b595243e4554ed7045 billy committed
Showing with 39 additions and 19 deletions.
  1. +19 −18 part2/MongoDB.cfc
  2. +20 −1 part2/SearchMongoTest.cfc
View
37 part2/MongoDB.cfc
@@ -23,22 +23,21 @@ expression_builder = createObject('component', 'ExpressionBuilder') ;
DSL for MongoDB searches:
- mongo.expressionBuilder().
-
- results = mongo.getCollection('blog').
- startsWith('name','foo'). //string
- endsWith('title','bar'). //string
- exists('field','value'). //string
- regex('field','value'). //string
- eq('field','value'). //numeric
- lt('field','value'). //numeric
- gt('field','value'). //numeric
- gte('field','value'). //numeric
- lte('field','value'). //numeric
- in('field','value'). //array
- nin('field','value'). //array
- mod('field','value'). //numeric
- size('field','value'). //numeric
+ results = mongo.collection('blog').
+ startsWith('name','foo'). //string
+ endsWith('title','bar'). //string
+ exists('field','value'). //string
+ regex('field','value'). //string
+ before('field', 'value'). //date
+ after('field', 'value'). //date
+ $eq('field','value'). //numeric
+ $gt('field','value'). //numeric
+ $gte('field','value'). //numeric
+ $lte('field','value'). //numeric
+ $in('field','value'). //array
+ $nin('field','value'). //array
+ $mod('field','value'). //numeric
+ size('field','value'). //numeric
search('title,author,date', limit, start);
search(keys=list_of_keys_to_return,sort={field=direction},limit=num,start=num);
@@ -256,14 +255,16 @@ function after(element,val){
<cffunction name="search">
- <cfargument name="keys_to_return" type="string" required="false" default="" hint="A list of keys to return" />
+ <cfargument name="keys" type="string" required="false" default="" hint="A list of keys to return" />
+ <cfargument name="limit" type="numeric" required="false" default="0" hint="Number of the maximum items to return" />
+ <cfargument name="sort" type="struct" required="false" default="#structNew()#" hint="A struct representing how the items are to be sorted" />
<cfscript>
var key_exp = listToStruct(keys_to_return);
var keys = createObject('java', 'com.mongodb.BasicDBObject').init(key_exp);
var search_results = [];
var criteria = expression_builder.get();
var q = createObject('java', 'com.mongodb.BasicDBObject').init(criteria);
- search_results = collection.find(q,keys);
+ search_results = collection.find(q,keys).limit(limit);
return search_results;
</cfscript>
</cffunction>
View
21 part2/SearchMongoTest.cfc
@@ -1,6 +1,25 @@
<cfcomponent output="false" extends="mxunit.framework.TestCase">
<cfscript>
+ //this would be a good data driven test! pass in an arbitrary list of integers
+ function $TestTheLimits(){
+ results = mongo.collection('blog').after( 'PUB_DATE', '01/01/1971' ).search('TITLE,TS,AUTHOR,PUB_DATE',1000);
+ debug(results.toArray().size());
+ assertEquals( 1000,results.toArray().size() );
+
+ results = mongo.collection('blog').after( 'PUB_DATE', '01/01/1971' ).search('TITLE,TS,AUTHOR,PUB_DATE');
+ debug(results.toArray().size());
+ assertEquals( 1000,results.toArray().size() );
+
+ results = mongo.collection('blog').after( 'PUB_DATE', '01/01/1971' ).search('TITLE,TS,AUTHOR,PUB_DATE',512);
+ debug(results.toArray().size());
+ assertEquals( 512,results.toArray().size() );
+
+ results = mongo.collection('blog').after( 'PUB_DATE', '01/01/1971' ).search('TITLE,TS,AUTHOR,PUB_DATE',1);
+ debug(results.toArray().size());
+ assertEquals( 1,results.toArray().size() );
+ }
+
function $searchBeforeDateReturns0(){
results = mongo.collection('blog').before( 'PUB_DATE', '01/01/1971' ).search('TITLE,TS,AUTHOR,PUB_DATE');
@@ -9,7 +28,7 @@
}
function $searchAfterDateReturns1000(){
- results = mongo.collection('blog').after( 'PUB_DATE', '01/01/1971' ).search('TITLE,TS,AUTHOR,PUB_DATE');
+ results = mongo.collection('blog').after( 'PUB_DATE', '01/01/1971' ).search('TITLE,TS,AUTHOR,PUB_DATE',1000);
debug(results.toArray().size());
assertEquals( 1000,results.toArray().size() );
}

0 comments on commit 606243b

Please sign in to comment.
Something went wrong with that request. Please try again.