Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

getting search happening

  • Loading branch information...
commit 27b92a295f79764aafa7d02d956bf0df722f8b03 1 parent 31cb5da
unknown authored
View
1  part2/ExpressionBuilder.cfc
@@ -76,6 +76,7 @@ function get(){
//May need at least some exception handling
function where( js_expression ){
builder.add( '$where', js_expression );
+ return this;
}
function inArray(element, val){
View
2  part2/ExpressionBuilderTest.cfc
@@ -59,7 +59,7 @@ function $testWhereJSExpression(){
ia = items.toArray();
debug(items.count());
debug(items.toArray().toString());
- assertEquals( 7, items.count() );
+ assertEquals( 5, items.count() );
}
View
7 part2/MongoDB.cfc
@@ -17,7 +17,7 @@ config = {
mongo = createObject('java', 'com.mongodb.Mongo').init( variables.config.server_name , variables.config.server_port );
db = mongo.getDb(config.db_name);
collection = db.getCollection(config.collection_name);
-expression_builder = createObject('component', 'ExpressionBuilder')
+expression_builder = createObject('component', 'ExpressionBuilder') ;
/*---------------------------------------------------------------------
@@ -180,12 +180,13 @@ function exists(element, val){
function regex(element, val){
var regex = val;
- expression_builder.regex( element, pattern.compile(regex) );
+ expression_builder.regex( element, regex );
return this;
}
function where( js_expression ){
- expression_builder.where( '$where', js_expression );
+ expression_builder.where( js_expression );
+ return this;
}
function inArray(element, val){
View
22 part2/MongoDBTest.cfc
@@ -51,16 +51,10 @@
key_exp = {TITLE=1,TS=1};
keys = createObject('java', 'com.mongodb.BasicDBObject').init(key_exp);
-
- // { a : { $gt: 3 } }
- //exp['$where'] = 'this.TS > 1256133363469';
- //exp = { $gt=1256133363469 };
- //exp = {};
- //exp['$gte']= javacast('long',1256148921000 );
+
exp['$gte']= javacast('long',1256148921000 );
debug( exp );
-
- //q = createObject('java', 'com.mongodb.BasicDBObject').init("TS", javacast('long',1256148921000) );
+ //q = createObject('java', 'com.mongodb.BasicDBObject').init("TS", javacast('long',1256148921000) );
q = createObject('java', 'com.mongodb.BasicDBObject').init("TS", exp );
items = coll.find( q, keys );
@@ -73,11 +67,7 @@
function $findByRegEx(){
coll = mongo.getCollection('blog');
- //raw = mongo.getMongo(); //raw jo
debug(coll.getName());
- //debug(coll);
- //import java.util.regex.Pattern;
- //import java.util.regex.Matcher;
p = createObject('java', 'java.util.regex.Pattern').compile('bill_6[0-2].*');
exp = { AUTHOR=p };
key_exp = {AUTHOR=1,TITLE=1,TS=1};
@@ -91,7 +81,8 @@
function genDataTest(){
- // genBlogData() ;
+ // uncomment next line to generate data :
+ // genBlogData() ;
}
@@ -124,10 +115,9 @@
createObject('java','java.util.Collections').shuffle(tags);
r1 = randrange(1,max);
r2 = randrange(r1,max);
- newTags = shuffled.subList(r1,r2);
- //createObject('java','java.util.Collections').shuffle(newTags);
-
+ newTags = shuffled.subList(r1,r2);
entry.title = 'Blog Title No.' & i;
+ entry.incr = javacast('int',i);
entry.author = 'bill_' & i;
entry.tags = newTags;
entry.ts = javacast('long',getTickCount());
View
31 part2/SearchMongoTest.cfc
@@ -1,6 +1,37 @@
<cfcomponent output="false" extends="mxunit.framework.TestCase">
<cfscript>
+ function searchINCRWithNE(){
+ results = mongo.collection('blog').$ne( 'INCR', javacast('int',1) ).search('TITLE,TS,AUTHOR,PUB_DATE');
+ assertEquals( 999,results.toArray().size() );
+ }
+
+
+ function searchINCRWithWhere(){
+ results = mongo.collection('blog').where( "this.INCR == 1").search('TITLE,TS,AUTHOR,PUB_DATE');
+ assertEquals( 1,results.toArray().size() );
+
+ results = mongo.collection('blog').where( "this.INCR > 0 && this.INCR < 100").search('TITLE,TS,AUTHOR,PUB_DATE');
+ assertEquals( 99,results.toArray().size() );
+ }
+
+ //1256242383663
+ function searchTSWithWhere(){
+ results = mongo.collection('blog').where( "this.TS > 1256242383663").search('TITLE,TS,AUTHOR,PUB_DATE');
+ assertEquals( 1000,results.toArray().size() );
+ }
+
+ function searchTAGSWithWhere(){
+ results = mongo.collection('blog').where( "this.TAGS == 'Java'").search('TITLE,TS,AUTHOR,PUB_DATE');
+ assert( results.toArray().size() > 1 );
+ }
+
+ function searchTitleWithRegEx() {
+ results = mongo.collection('blog').regex('TITLE','Blog Title No.6[0]{1,1}').search('TITLE,AUTHOR,PUB_DATE');
+ debug( results.toArray().toString() );
+ assertEquals( 11,results.toArray().size() );
+ }
+
function searchTitleContains() {
results = mongo.collection('blog').exists('TITLE','Blog Title No.60').search('TITLE,AUTHOR,PUB_DATE');
debug( results.toArray().toString() );
Please sign in to comment.
Something went wrong with that request. Please try again.