class ScopedSearch::QueryBuilder::PostgreSQLAdapter

The PostgreSQLAdapter make sure that searches are case sensitive when using the like/unlike operators, by using the PostrgeSQL-specific ILIKE operator instead of LIKE.

Public Instance Methods

order_by(order, &block) click to toggle source
Calls superclass method ScopedSearch::QueryBuilder#order_by
    # File lib/scoped_search/query_builder.rb
583 def order_by(order, &block)
584   sql = super(order, &block)
585   if sql
586     field, _ = find_field_for_order_by(order, &block)
587     sql += sql.include?('DESC') ? ' NULLS LAST ' : ' NULLS FIRST ' if !field.nil? && field.column.null
588   end
589   sql
590 end
sql_operator(operator, field) click to toggle source

Switches out the default LIKE operator in the default sql_operator method for ILIKE or @@ if full text searching is enabled.

Calls superclass method ScopedSearch::QueryBuilder#sql_operator
    # File lib/scoped_search/query_builder.rb
568 def sql_operator(operator, field)
569   raise ScopedSearch::QueryNotSupported, "the operator '#{operator}' is not supported for field type '#{field.type}'" if !field.virtual? and [:like, :unlike].include?(operator) and !field.textual?
570   return '@@' if [:like, :unlike].include?(operator) && field.full_text_search
571   case operator
572     when :like   then 'ILIKE'
573     when :unlike then 'NOT ILIKE'
574     else super(operator, field)
575   end
576 end
sql_test(field, operator, value, lhs) { |:parameter, value| ... } click to toggle source

Switches out the default query generation of the sql_test method if full text searching is enabled and a text search is being performed.

Calls superclass method ScopedSearch::QueryBuilder#sql_test
    # File lib/scoped_search/query_builder.rb
555 def sql_test(field, operator, value, lhs, &block)
556   if [:like, :unlike].include?(operator) && field.full_text_search
557     yield(:parameter, value)
558     negation = (operator == :unlike) ? "NOT " : ""
559     locale = (field.full_text_search == true) ? 'english' : field.full_text_search
560     return "#{negation}to_tsvector('#{locale}', #{field.to_sql(operator, &block)}) #{self.sql_operator(operator, field)} to_tsquery('#{locale}', ?)"
561   else
562     super
563   end
564 end
to_not_sql(rhs, definition, &block) click to toggle source

Returns a NOT (…) SQL fragment that negates the current AST node's children

    # File lib/scoped_search/query_builder.rb
579 def to_not_sql(rhs, definition, &block)
580   "NOT COALESCE(#{rhs.to_sql(self, definition, &block)}, false)"
581 end