Permalink
Browse files

Set list is now based on facets from querystring

  • Loading branch information...
1 parent 0d97b79 commit 7971f1b1a995705e8330e3274c84cdf9b95c6f7d Michael Hughes committed Feb 16, 2013
@@ -3,5 +3,6 @@
ul
each f in facet
li
- span.facet-name= f._id
- span.facet-amount= f.count
+ a(href="/?#{facetQuery}=#{f._id}")
+ span.facet-name= f._id
+ span.facet-amount= f.count
@@ -6,9 +6,11 @@ block content
img(src=s.thumbnailURL)
block facet
facetName = "Theme"
+ facetQuery = "theme"
facet = searchResults.theme
include facet
facetName = "Year"
+ facetQuery = "year"
facet = searchResults.year
include facet
View
@@ -2,14 +2,14 @@ _ = require 'underscore'
exports.createSearch = (mongostore)->
- getResults:(fun)->
+ getResults:(search,fun)->
res = {}
facets = ["theme","year"]
fin = (facetName,expected)->(err,results)->
res[facetName] = results
fun(null,res) if _.keys(res).length == expected
- mongostore.getSets fin("sets",facets.length+1)
+ mongostore.getSets search, fin("sets",facets.length+1)
for facet in facets
- mongostore.getFacet facet, fin(facet,facets.length+1)
+ mongostore.getFacet search, facet, fin(facet,facets.length+1)
@@ -26,12 +26,12 @@ exports.createMongostore = (connectionString)->
fun err,null if err
collection.insert data,{w:1},fun
- getSets:(fun)->
+ getSets:(search,fun)->
@connect (err,collection)->
fun err,null if err
- collection.find().toArray fun
+ collection.find(search).toArray fun
- getFacet:(facetName,fun)->
+ getFacet:(search,facetName,fun)->
@connect (err,collection)->
fun err,null if err
collection.aggregate [{$group:{_id:"$"+facetName,count:{$sum:1}}},{$sort:{count:-1}}],[],fun
@@ -18,9 +18,9 @@ port = process.env.PORT or 5555
app.get '/', (req, res)->
search = domain.createSearch mongostore.createMongostore(connectionString)
- search.getResults (err,result)=>
+ search.getResults req.query,(err,result)=>
res.send err if err
res.render('index',{title:"Your Lego Sets",searchResults:result})
# Start Server
-app.listen port, -> console.log "Listening on #{port}\nPress CTRL-C to stop server."
+app.listen port, -> console.log "LegoDatabase server is listening on #{port}\nPress CTRL-C to stop server."
@@ -5,4 +5,4 @@ app.use express.static(process.cwd() + '/test/server/collector/resources')
port = 7777
# Start Server
-app.listen port, -> console.log "Listening on #{port}\nPress CTRL-C to stop server."
+app.listen port, -> console.log "FakeSet server is listening on #{port}\nPress CTRL-C to stop server."
@@ -17,7 +17,7 @@ describe 'A domain', ->
{"setID":"333","setName":"Alien","theme":"Space","year":"1998"}]
@ms.insert data,(err,result)=>
d = domain.createSearch(@ms)
- d.getResults (err,result)->
+ d.getResults null,(err,result)->
result.sets.length.should.equal 3
result.sets[0].setID.should.equal "111"
result.theme.should.eql [{_id:"Star Wars",count:2},{_id:"Space",count:1}]
@@ -3,6 +3,11 @@ should = require 'should'
connectionString = "mongodb://localhost:27000/legodb"
+setData = [
+ {"setID":"111","setName":"Y-Wing","theme":"Star Wars","year":"1996"},
+ {"setID":"222","setName":"X-Wing","theme":"Star Wars","year":"1998"},
+ {"setID":"333","setName":"Alien","theme":"Space","year":"1998"}]
+
describe 'A mongodb store', ->
beforeEach (done) ->
@ms = mongostore.createMongostore(connectionString)
@@ -28,24 +33,26 @@ describe 'A mongodb store', ->
done()
it 'should be able to get facet information about data in the db', (done)->
- data = [
- {"theme":"Star Wars"},
- {"theme":"Star Wars"},
- {"theme":"Space"}]
- @ms.insert data,(err,result)=>
- @ms.getFacet "theme",(err,result)->
+ @ms.insert setData,(err,result)=>
+ @ms.getFacet null,"theme",(err,result)->
result.should.eql [{_id:"Star Wars",count:2},{_id:"Space",count:1}]
for facet in result when facet._id=="Star Wars"
facet.count.should.equal 2
done()
- it 'should be able to get Set information', (done)->
- data = [
- {"theme":"Star Wars"},
- {"theme":"Star Wars"},
- {"theme":"Space"}]
- @ms.insert data,(err,result)=>
- @ms.getSets (err,result)->
+ it 'should be able to get facet information with an existing facet search', (done)->
+ done()
+
+ it 'should be able to get Set information', (done)->
+ @ms.insert setData,(err,result)=>
+ @ms.getSets null,(err,result)->
result.length.should.equal 3
result[0].theme.should.equal "Star Wars"
done()
+
+ it 'should be able to get Set information with an existing facet search', (done)->
+ @ms.insert setData,(err,result)=>
+ facets={"theme":"Star Wars"}
+ @ms.getSets facets,(err,result)->
+ result.length.should.equal 2
+ done()

0 comments on commit 7971f1b

Please sign in to comment.