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")
# field conditions in query string
@articles = Article.search("priority:3")
# no need to specify first query string when searching all records
@articles = Article.search(:conditions => { :category_id => params[:category_id] })
# search partial terms with asterisk (only supported at end of term)
@articles = Article.search("sab*", :conditions => { :name => "Din*" })
# search multiple conditions with OR by passing an array
@articles = Article.search(:conditions => [{ :category_id => 1 }, { :priority => 2 }])
101 102 103 |
# File 'lib/xapit/membership.rb', line 101 def search(*args) Collection.new(self, *args) end |
#xapit_adapter ⇒ Object
The Xapit::AbstractAdapter used to perform database queries on.
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/xapit/membership.rb', line 111 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.
123 124 125 126 127 |
# File 'lib/xapit/membership.rb', line 123 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.
106 107 108 |
# File 'lib/xapit/membership.rb', line 106 def xapit_index_blueprint @xapit_index_blueprint end |