README.md in mongoid_search-0.1.2 vs README.md in mongoid_search-0.2.0
- old
+ new
@@ -22,21 +22,29 @@
include Mongoid::Search
field :brand
field :name
references_many :tags
+ refereced_in :category
- search_in :brand, :name, :tags => :name
+ search_in :brand, :name, :tags => :name, :category => :name
end
class Tag
include Mongoid::Document
field :name
referenced_in :product
end
+
+ class Category
+ include Mongoid::Document
+ field :name
+ references_many :products
+ end
+
Now when you save a product, you get a _keywords field automatically:
p = Product.new :brand => "Apple", :name => "iPhone"
p.tags << Tag.new(:name => "Amazing")
p.tags << Tag.new(:name => "Awesome")
@@ -56,19 +64,37 @@
=> 1
Options
-------
-:match:
- :any - match any occurrence
- :all - match all ocurrences
- Default is :any.
+match:
+ _:any_ - match any occurrence
+ _:all_ - match all ocurrences
+ Default is _:any_.
search_in :brand, :name, { :tags => :name }, { :match => :any }
Product.search("apple motorola").size
=> 1
search_in :brand, :name, { :tags => :name }, { :match => :all }
Product.search("apple motorola").size
=> 0
+
+allow_empty_search:
+ _true_ - match any occurrence
+ _false_ - match all ocurrences
+ Default is _false_.
+
+ search_in :brand, :name, { :tags => :name }, { :allow_empty_search => true }
+
+ Product.search("").size
+ => 1
+
+TODO
+----
+
+* Strip html with sanitize (https://github.com/rgrove/sanitize)
+* Test relevant search
+* Move all configurations to a configuration file. Maybe /config/mongoid_search.yml.
+