Skip to content

Instantly share code, notes, and snippets.

@EcZachly
Created April 1, 2015 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save EcZachly/c002b0405facacf4715c to your computer and use it in GitHub Desktop.
Save EcZachly/c002b0405facacf4715c to your computer and use it in GitHub Desktop.
app.get '/Cards/adv/search', (req, res) ->
console.log(req.query)
colors1 = req.query.colors
if(colors1 == undefined)
colors1 = ["White", "Blue","Black","Green", "Red"]
if(colors1.length == 0)
colors1 = ["White", "Blue","Black","Green", "Red"]
rarity1 = req.query.rares
if(rarity1 == undefined)
rarity1 = ['Common','Uncommon','Rare', 'Mythic Rare']
if(rarity1.length == 0)
rarity1 = ['Common','Uncommon','Rare', 'Mythic Rare']
keyword = req.query.keyword
if(keyword != undefined && req.query.subtype != undefined)
keyword = keyword.trim()
curs = cardCollection.find(
{ colors: { $in: colors1 } , rarity:{$in: rarity1}, $text: { $search: keyword}, subtypes: { $elemMatch: { $eq: req.query.subtype} }}).limit(100)
else if (req.query.subtype != undefined)
curs = cardCollection.find(
{ colors: { $in: colors1 } , rarity:{$in: rarity1}, subtypes: { $elemMatch: { $eq: req.query.subtype} }}).limit(100)
else if keyword != undefined
curs = cardCollection.find(
{ colors: { $in: colors1 } , rarity:{$in: rarity1}, $text: { $search: keyword}}).limit(100)
else
curs = cardCollection.find(
{ colors: { $in: colors1 } , rarity:{$in: rarity1}}).limit(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment