Skip to content
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

added autocomplete function #23

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/mongoid/taggable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,18 @@ def tags
tags_index_collection.master.find.to_a.map{ |r| r["_id"] }
end

def destroy_tags!
tags_index_collection.master.remove({})
end

# retrieve the list of tags with weight (i.e. count), this is useful for
# creating tag clouds
def tags_with_weight
tags_index_collection.master.find.to_a.map{ |r| [r["_id"], r["value"]] }
def tags_with_weight(max = 10)
tags_index_collection.master.find.limit(max).to_a.map{ |r| [r["_id"], r["value"]] }
end

def tags_autocomplete(criteria)
tags_index_collection.master.find({:_id => /^#{criteria}/}).to_a.map{ |r| [r["_id"], r["value"]] }
end

def disable_tags_index!
Expand Down