Module: ActsAsXapian::ArrayExt
- Defined in:
- lib/acts_as_xapian/core_ext/array.rb
Instance Method Summary collapse
-
#find_similar(options = {}) ⇒ Object
Runs a ActsAsXapian::Similar search passing back the returned models instead of the search object.
-
#search_similar(options = {}) ⇒ Object
Creates a ActsAsXapian::Similar search passing through the options to the search.
Instance Method Details
#find_similar(options = {}) ⇒ Object
Runs a ActsAsXapian::Similar search passing back the returned models instead of the search object. Takes all the same options as search_similar
16 17 18 |
# File 'lib/acts_as_xapian/core_ext/array.rb', line 16 def find_similar( = {}) search_similar().results.map {|x| x[:model] } end |
#search_similar(options = {}) ⇒ Object
Creates a ActsAsXapian::Similar search passing through the options to the search
The model classes to search are automatically generated off the classes of the entries in the array. If you want more control over which models to search, specify option :models and it will override the default behavior
8 9 10 11 12 |
# File 'lib/acts_as_xapian/core_ext/array.rb', line 8 def search_similar( = {}) raise "All entries must be xapian models" unless all? {|i| i.class.respond_to?(:xapian?) && i.class.xapian? } models = .delete(:models) ActsAsXapian::Similar.new(models || map {|i| i.class }.uniq, self, ) end |