Module: Xapit::Membership::AdditionalMethods::ClassMethods
- Defined in:
- lib/xapit/membership.rb
Instance Method Summary collapse
-
#search(*args) ⇒ Object
Used to perform a search on a model.
-
#xapit_adapter ⇒ Object
The Xapit::AbstractAdapter used to perform database queries on.
-
#xapit_facet_blueprint(attribute) ⇒ Object
Finds a Xapit::FacetBlueprint for the given attribute.
-
#xapit_index_blueprint ⇒ Object
The Xapit::IndexBlueprint object used for this class.
Instance Method Details
#search(*args) ⇒ Object
Used to perform a search on a model.
# perform a simple full text search
@articles = Article.search("phone")
# add pagination if you're using will_paginate
@articles = Article.search("phone", :per_page => 10, :page => params[:page])
# search based on indexed fields
@articles = Article.search("phone", :conditions => { :category_id => params[:category_id] })
# search for multiple negative conditions (doesn't match 3, 5, or 8)
@articles = Article.search(:not_conditions => { :category_id => [3, 5, 8] })
# search for range of conditions by number
@articles = Article.search(:conditions => { :released_at => 2.years.ago..Time.now })
# manually sort based on any number of indexed fields, sort defaults to most relevant
@articles = Article.search("phone", :order => [:category_id, :id], :descending => true)
# basic boolean matching is supported
@articles = Article.search("phone or fax not email")
# no need to specify first query string when searching all records
@articles = Article.search(:conditions => { :category_id => params[:category_id] })
92 93 94 |
# File 'lib/xapit/membership.rb', line 92 def search(*args) Collection.new(self, *args) end |
#xapit_adapter ⇒ Object
The Xapit::AbstractAdapter used to perform database queries on.
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/xapit/membership.rb', line 102 def xapit_adapter @xapit_adapter ||= begin adapter_class = AbstractAdapter.subclasses.detect { |a| a.for_class?(self) } if adapter_class adapter_class.new(self) else raise "Unable to find Xapit adapter for class #{self.name}" end end end |
#xapit_facet_blueprint(attribute) ⇒ Object
Finds a Xapit::FacetBlueprint for the given attribute.
114 115 116 117 118 |
# File 'lib/xapit/membership.rb', line 114 def xapit_facet_blueprint(attribute) result = xapit_index_blueprint.facets.detect { |f| f.attribute.to_s == attribute.to_s } raise "Unable to find facet blueprint for #{attribute} on #{name}" if result.nil? result end |
#xapit_index_blueprint ⇒ Object
The Xapit::IndexBlueprint object used for this class.
97 98 99 |
# File 'lib/xapit/membership.rb', line 97 def xapit_index_blueprint @xapit_index_blueprint end |