-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: tags_with_weight for subsets #18
Comments
Hi airy, Yes, they return the same... You can't limit or sort or do any of these things for this method, because it uses a low level collection for this data, in fact, after each save this data is cached on an internal collection for that. If you can send a good implementation that covers that and keeps performance, I will be happy to accept :) |
thanks for your confidence but i am not good enough on mongodb to write implementation :) i found some usefull information here : http://www.mongodb.org/display/DOCS/MapReduce#MapReduce-Overview there is a query option as well as limit and scope. |
In fact, the cached table data is created using the MapReduce, you can take a look here: https://github.com/wilkerlucio/mongoid_taggable/blob/master/lib/mongoid/taggable.rb#L78 It should not be so hard to finish the implementation of query methods to suporte the context, but need to dig a little on MongoId source to see how internally you can use the current search context. Currently Im most dedicated on other projects, but if you have some time, I mean read the MongoId source and do this implementation will be a good learning experience :) |
any progress on this front? scoped/contextual tags would be really convenient +1 |
For now you can use the aggregate method from mongoid. This works for me: # you define here your query
criteria = YourModel.where(my_attribute: "a value")
# and you count the tags
result = YourModel.collection.aggregate([
{ "$match" => criteria.selector},
{ "$project" => YourModel.only(:tags_array).options.fields},
{ "$unwind" => "$tags_array"},
{ "$group" => { "_id" => "$tags_array",
"count" => { "$sum" => 1 }
}}
])
p results # print [{"_id"=>"bee", "count"=>1}, {"_id"=>"ant", "count"=>1}, {"_id"=>"food", "count"=>2}] and you can add a sorting at the end of the pipeline if you want them by counts: { "$sort" => {"count" => -1,"_id" => 1}} |
Post.limit(10).tags_with_weight and Post.tags_with_weight returns the same results. Having filtered tags_with_weight would be realy nice.
thanks
The text was updated successfully, but these errors were encountered: