vendor/plugins/active_scaffold/lib/active_scaffold/finder.rb
# Takes a collection of search terms (the tokens) and creates SQL that
# searches all specified ActiveScaffold columns. A row will match if each
# token is found in at least one of the columns.
Takes a collection of search terms (the tokens) and creates SQL that
searches all specified ActiveScaffold columns. A row will match if each
token is found in at least one of the columns.
Takes a collection of search terms ( the tokens ) and creates SQL that searches all specified ActiveScaffold columns . A row will match if each token is found in at least one of the columns .
def create_conditions_for_columns(tokens, columns, text_search = :full)
        return unless columns.length > 0
        like_pattern = like_pattern(text_search)
        tokens = [tokens] if tokens.is_a? String
        where_clauses = []
        columns.each do |column|
          where_clauses << ((column.column.nil? || column.column.text?) ? "LOWER(#{column.search_sql}) LIKE ?" : "#{column.search_sql} = ?")
        end
        phrase = "(#{where_clauses.join(' OR ')})"
        sql = ([phrase] * tokens.length).join(' AND ')
        tokens = tokens.collect do |value|
          columns.collect {|column| (column.column.nil? || column.column.text?) ? like_pattern.sub('?', value.downcase) : column.column.type_cast(value)}
        end.flatten
        [sql, *tokens]
      end
def create_conditions_for_columns ( tokens , columns , text_search = :full ) return unless columns . length > 0 like_pattern = like_pattern ( text_search ) tokens = [ tokens ] if tokens . is_a? String where_clauses = [ ] columns . each do | column | where_clauses << ( ( column . column . nil? || column . column . text? ) ? "LOWER(#{column.search_sql}) LIKE ?" : "#{column.search_sql} = ?" ) end phrase = "(#{where_clauses.join(' OR ')})" sql = ( [ phrase ] * tokens . length ) . join ( ' AND ' ) tokens = tokens . collect do | value | columns . collect { | column | ( column . column . nil? || column . column . text? ) ? like_pattern . sub ( '?' , value . downcase ) : column . column . type_cast ( value ) } end . flatten [ sql , * tokens ] end
Takes a collection of search terms (the tokens) and creates SQL that
searches all specified ActiveScaffold columns.
Takes a collection of search terms ( the tokens ) and creates SQL that searches all specified ActiveScaffold columns .
# if there aren't any columns, then just return a nil condition
tokens
<not_specific>
columns
<not_specific>
text_search
<not_specific>