Created
August 4, 2012 22:01
-
-
Save korczis/3260246 to your computer and use it in GitHub Desktop.
Node.js + Geddy + MongoDB + search (not working)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.index = function (req, resp, params) { | |
var self = this; | |
// Limit in params? | |
var limit = 100; // default limit | |
if(params.limit) { | |
limit = parseInt(params.limit); | |
} | |
// Offset in params? | |
var offset = 0; // default offset | |
if(params.offset) { | |
offset = parseInt(params.offset); | |
} | |
// TODO: Get total count | |
var count = -1; | |
// Query in params? | |
var query = {}; | |
if(params.q) { | |
query = { title: params.q } | |
} else if (params.fts) { | |
query = { fts: ["adorable", "teen", "gets", "fucked"] }; | |
} | |
// Fetch data | |
geddy.model.adapter.Movie.all(query | |
, {sort: {title: 1}, limit: limit, skip: offset} | |
, function(err, data) { | |
self.respond({params: params | |
, movies: data | |
, count: count | |
, limit: limit | |
, offset: offset | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment