Permalink
Browse files

Added searches_index_name in config block option, modified usage section

in README
  • Loading branch information...
1 parent ce8baea commit d8db4afda987efdbebbae3611ea7fff32d7b60e9 @aokon committed Oct 15, 2011
Showing with 34 additions and 3 deletions.
  1. +6 −2 README.rdoc
  2. +11 −1 lib/hunt.rb
  3. +17 −0 spec/hunt_spec.rb
View
@@ -18,9 +18,10 @@ Declare the plugin.
searches :title, :body, :tags
end
-You can configure Hunt using a Hunt.configure and passing block of options(at the moment there is only option for additional_words_to_ignore)
+You can configure Hunt using a Hunt.configure and passing block of options:
Hunt.configure do |config|
+ config.searches_index_name = :"searches.default"
config.additional_words_to_ignore ["bang", 'yabadabaduu']
end
@@ -30,7 +31,10 @@ If word contains non ascii chars, they'll be transliterated to ascii format usin
You can index the terms individually or with any other combination of keys.
Note.ensure_index :'searches.default' # or ...
- Note.ensure_index [[:user_id, Mongo::Ascending], [:'searches.default', Mongo::Ascending]]
+ Note.ensure_index [[:user_id, Mongo::ASCENDING], [:'searches.default', Mongo::ASCENDING]] # or use config block
+ Hunt.configure do |config|
+ config.searches_index_name = :"searches.default"
+ end
You also get a search class method that returns a scope.
View
@@ -5,6 +5,8 @@
module Hunt
extend ActiveSupport::Concern
+ @@searches_index_name = nil
+
class << self
def included(model)
model.before_save(:index_search_terms)
@@ -17,6 +19,14 @@ def configure(&block)
def additional_words_to_ignore(words)
Util.update_words_to_ignore(words) if words.any?
end
+
+ def searches_index_name=(value)
+ @@searches_index_name = value
+ end
+
+ def searches_index_name
+ @@searches_index_name
+ end
end
module ClassMethods
@@ -27,7 +37,7 @@ def search_keys
def searches(*keys)
# Using a hash to support multiple indexes per document at some point
key(:searches, Hash)
- ensure_index :'searches.default'
+ ensure_index(Hunt.searches_index_name) unless Hunt.searches_index_name.nil?
@search_keys = keys
end
View
@@ -28,6 +28,23 @@ class User
Note.new.should respond_to(:searches=)
end
+ it "adds index key as symbol if it was defined" do
+ searches_index_name = :"searches.default"
+ Hunt.configure do |config|
+ config.searches_index_name = searches_index_name
+ end
+ Hunt.searches_index_name.should == searches_index_name
+ end
+
+ it "adds index as array if it was defined" do
+ searches_index_name = [[:"searches.default", Mongo::ASCENDING], [:user_dir, Mongo::ASCENDING]]
+ Hunt.configure do |config|
+ config.searches_index_name = searches_index_name
+ end
+ Hunt.searches_index_name.should == searches_index_name
+
+ end
+
describe ".search" do
before(:each) do
Note.searches(:title)

0 comments on commit d8db4af

Please sign in to comment.