Module: AdminData::Search

Included in:
SearchController
Defined in:
lib/admin_data/search.rb

Defined Under Namespace

Classes: Dbbase, OracleSpecific, PostgresqlSpecific, Term

Instance Method Summary collapse

Instance Method Details

#build_advance_search_condition(klass, options) ⇒ Object


175
176
177
178
179
180
181
182
183
184
185
# File 'lib/admin_data/search.rb', line 175

def build_advance_search_condition(klass, options)
  values        = ( options.blank? ? [] : options.values )
  terms         = values.collect {|value| Term.new(klass, value, 'advance_search') }
  valid_terms   = terms.select{ |t| t.valid? }
  errors        = (terms - valid_terms).collect { |t| t.error }
  return {:errors => errors} if errors.any?

  r = klass.unscoped
  valid_terms.each { |t|  r = r.where(t.attribute_condition) }
  { :cond => r }
end

#build_quick_search_condition(klass, search_term) ⇒ Object


165
166
167
168
169
170
171
172
173
# File 'lib/admin_data/search.rb', line 165

def build_quick_search_condition( klass, search_term )
  return nil if search_term.blank?
  str_columns = klass.columns.select { |column| column.type.to_s =~ /(string|text)/i }
  conditions = str_columns.collect do |column|
    t = Term.new(klass, {:col1 => column.name, :col2 => 'contains', :col3 => search_term}, 'quick_search')
    t.attribute_condition
  end
  AdminData::Util.or_merge_conditions(klass, *conditions)
end