From 42feddd24dedd66b2b6776f9694d1b5b8bf6903d Mon Sep 17 00:00:00 2001 From: Jos Leegstra Date: Fri, 23 Mar 2012 21:35:28 +0100 Subject: [PATCH 1/4] added autocomplete function --- lib/mongoid/taggable.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/mongoid/taggable.rb b/lib/mongoid/taggable.rb index c415876..b3baf64 100644 --- a/lib/mongoid/taggable.rb +++ b/lib/mongoid/taggable.rb @@ -60,6 +60,10 @@ def tags_with_weight tags_index_collection.master.find.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! @do_tags_index = false end From ca5fa71643ee9157144ce551dedc967de36087cc Mon Sep 17 00:00:00 2001 From: Jos Leegstra Date: Mon, 26 Mar 2012 20:57:44 +0200 Subject: [PATCH 2/4] limit added --- lib/mongoid/taggable.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mongoid/taggable.rb b/lib/mongoid/taggable.rb index b3baf64..fe1919f 100644 --- a/lib/mongoid/taggable.rb +++ b/lib/mongoid/taggable.rb @@ -56,8 +56,8 @@ def tags # 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) From 1c9ad5d7bd3ec331bf5aade465f0740c217d083d Mon Sep 17 00:00:00 2001 From: Jos Leegstra Date: Tue, 15 May 2012 14:20:08 +0200 Subject: [PATCH 3/4] detroy_tags! method added --- lib/mongoid/taggable.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/mongoid/taggable.rb b/lib/mongoid/taggable.rb index fe1919f..805f127 100644 --- a/lib/mongoid/taggable.rb +++ b/lib/mongoid/taggable.rb @@ -54,6 +54,10 @@ def tags tags_index_collection.master.find.to_a.map{ |r| r["_id"] } end + def destroy_tags! + tags_index_collection.master.all.delete + end + # retrieve the list of tags with weight (i.e. count), this is useful for # creating tag clouds def tags_with_weight(max = 10) From b5340ecc1ad00d1a594a79ad0bcbf5eabb88b4ef Mon Sep 17 00:00:00 2001 From: Jos Leegstra Date: Tue, 15 May 2012 14:29:59 +0200 Subject: [PATCH 4/4] remove all tags added --- lib/mongoid/taggable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mongoid/taggable.rb b/lib/mongoid/taggable.rb index 805f127..6f1076f 100644 --- a/lib/mongoid/taggable.rb +++ b/lib/mongoid/taggable.rb @@ -55,7 +55,7 @@ def tags end def destroy_tags! - tags_index_collection.master.all.delete + tags_index_collection.master.remove({}) end # retrieve the list of tags with weight (i.e. count), this is useful for