Class | ScopedSearch::QueryBuilder::PostgreSQLAdapter |
In: |
lib/scoped_search/query_builder.rb
|
Parent: | ScopedSearch::QueryBuilder |
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.
# File lib/scoped_search/query_builder.rb, line 494 494: def order_by(order, &block) 495: sql = super(order, &block) 496: sql += sql.include?('DESC') ? ' NULLS LAST ' : ' NULLS FIRST ' if sql 497: sql 498: end
Switches out the default LIKE operator in the default sql_operator method for ILIKE or @@ if full text searching is enabled.
# File lib/scoped_search/query_builder.rb, line 479 479: def sql_operator(operator, field) 480: raise ScopedSearch::QueryNotSupported, "the operator '#{operator}' is not supported for field type '#{field.type}'" if [:like, :unlike].include?(operator) and !field.textual? 481: return '@@' if [:like, :unlike].include?(operator) and field.full_text_search 482: case operator 483: when :like then 'ILIKE' 484: when :unlike then 'NOT ILIKE' 485: else super(operator, field) 486: end 487: 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.
# File lib/scoped_search/query_builder.rb, line 466 466: def sql_test(field, operator, value, lhs, &block) 467: if [:like, :unlike].include?(operator) and field.full_text_search 468: yield(:parameter, value) 469: negation = (operator == :unlike) ? "NOT " : "" 470: locale = (field.full_text_search == true) ? 'english' : field.full_text_search 471: return "#{negation}to_tsvector('#{locale}', #{field.to_sql(operator, &block)}) #{self.sql_operator(operator, field)} to_tsquery('#{locale}', ?)" 472: else 473: super 474: end 475: end