Skip to content
Browse files

Facets now match the querystring

  • Loading branch information...
1 parent 7971f1b commit bcd782f8a4c568b4a0b25ed0fa27188de2808c5b Michael Hughes committed
View
11 src/resources/views/facet.jade
@@ -1,8 +1,9 @@
.facet
div=facetName
ul
- each f in facet
- li
- a(href="/?#{facetQuery}=#{f._id}")
- span.facet-name= f._id
- span.facet-amount= f.count
+ - if (facet.length)
+ each f in facet
+ li
+ a(href="/?#{facetQuery}=#{f._id}")
+ span.facet-name= f._id
+ span.facet-amount= f.count
View
1 src/server/domain.coffee
@@ -7,6 +7,7 @@ exports.createSearch = (mongostore)->
facets = ["theme","year"]
fin = (facetName,expected)->(err,results)->
+ fun(err,res) if err
res[facetName] = results
fun(null,res) if _.keys(res).length == expected
View
5 src/server/mongostore.coffee
@@ -34,4 +34,7 @@ exports.createMongostore = (connectionString)->
getFacet:(search,facetName,fun)->
@connect (err,collection)->
fun err,null if err
- collection.aggregate [{$group:{_id:"$"+facetName,count:{$sum:1}}},{$sort:{count:-1}}],[],fun
+ query=
+ if search? then [{$match:search}]
+ else []
+ collection.aggregate query.concat([{$group:{_id:"$"+facetName,count:{$sum:1}}},{$sort:{count:-1}}]),[],fun
View
6 test/server/mongostore_test.coffee
@@ -41,7 +41,11 @@ describe 'A mongodb store', ->
done()
it 'should be able to get facet information with an existing facet search', (done)->
- done()
+ @ms.insert setData,(err,result)=>
+ facets={"year":"1996"}
+ @ms.getFacet facets,"theme",(err,result)->
+ result.length.should.equal 1
+ done()
it 'should be able to get Set information', (done)->
@ms.insert setData,(err,result)=>

0 comments on commit bcd782f

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