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
Source
# File lib/scoped_search/query_builder.rb 612 def order_by(order, &block) 613 sql = super(order, &block) 614 if sql 615 field, _ = find_field_for_order_by(order, &block) 616 sql += sql.include?('DESC') ? ' NULLS LAST ' : ' NULLS FIRST ' if !field.nil? && field.column.null 617 end 618 sql 619 end
Calls superclass method
ScopedSearch::QueryBuilder#order_by
Source
# File lib/scoped_search/query_builder.rb 597 def sql_operator(operator, field) 598 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? 599 return '@@' if [:like, :unlike].include?(operator) && field.full_text_search 600 case operator 601 when :like then 'ILIKE' 602 when :unlike then 'NOT ILIKE' 603 else super(operator, field) 604 end 605 end
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
Source
# File lib/scoped_search/query_builder.rb 584 def sql_test(field, operator, value, lhs, &block) 585 if [:like, :unlike].include?(operator) && field.full_text_search 586 yield(:parameter, value) 587 negation = (operator == :unlike) ? "NOT " : "" 588 locale = (field.full_text_search == true) ? 'english' : field.full_text_search 589 return "#{negation}to_tsvector('#{locale}', #{field.to_sql(operator, &block)}) #{self.sql_operator(operator, field)} to_tsquery('#{locale}', ?)" 590 else 591 super 592 end 593 end
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
Source
# File lib/scoped_search/query_builder.rb 608 def to_not_sql(rhs, definition, &block) 609 "NOT COALESCE(#{rhs.to_sql(self, definition, &block)}, false)" 610 end
Returns a NOT (…) SQL fragment that negates the current AST
node’s children