Class: ScopedSearch::QueryBuilder::PostgreSQLAdapter
- Inherits:
-
ScopedSearch::QueryBuilder
- Object
- ScopedSearch::QueryBuilder
- ScopedSearch::QueryBuilder::PostgreSQLAdapter
- Defined in:
- lib/scoped_search/query_builder.rb
Overview
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.
Constant Summary
Constants inherited from ScopedSearch::QueryBuilder
Instance Attribute Summary
Attributes inherited from ScopedSearch::QueryBuilder
Instance Method Summary collapse
- #order_by(order, &block) ⇒ Object
-
#sql_operator(operator, field) ⇒ Object
Switches out the default LIKE operator in the default sql_operator method for ILIKE or @@ if full text searching is enabled.
-
#sql_test(field, operator, value, lhs, &block) ⇒ Object
Switches out the default query generation of the sql_test method if full text searching is enabled and a text search is being performed.
-
#to_not_sql(rhs, definition, &block) ⇒ Object
Returns a NOT (...) SQL fragment that negates the current AST node's children.
Methods inherited from ScopedSearch::QueryBuilder
#build_find_params, build_query, class_for, #datetime_test, #find_field_for_order_by, #find_has_many_through_association, #has_many_through_join, #initialize, #map_value, #nested_has_many, #preprocess_parameters, #set_test, #translate_value, #value_placeholders, #with_polymorphism?
Constructor Details
This class inherits a constructor from ScopedSearch::QueryBuilder
Instance Method Details
#order_by(order, &block) ⇒ Object
615 616 617 618 619 620 621 622 |
# File 'lib/scoped_search/query_builder.rb', line 615 def order_by(order, &block) sql = super(order, &block) if sql field, _ = find_field_for_order_by(order, &block) sql += sql.include?('DESC') ? ' NULLS LAST ' : ' NULLS FIRST ' if !field.nil? && field.column.null end sql end |
#sql_operator(operator, field) ⇒ Object
Switches out the default LIKE operator in the default sql_operator method for ILIKE or @@ if full text searching is enabled.
600 601 602 603 604 605 606 607 608 |
# File 'lib/scoped_search/query_builder.rb', line 600 def sql_operator(operator, field) 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? return '@@' if [:like, :unlike].include?(operator) && field.full_text_search case operator when :like then 'ILIKE' when :unlike then 'NOT ILIKE' else super(operator, field) end end |
#sql_test(field, operator, value, lhs, &block) ⇒ Object
Switches out the default query generation of the sql_test method if full text searching is enabled and a text search is being performed.
587 588 589 590 591 592 593 594 595 596 |
# File 'lib/scoped_search/query_builder.rb', line 587 def sql_test(field, operator, value, lhs, &block) if [:like, :unlike].include?(operator) && field.full_text_search yield(:parameter, value) negation = (operator == :unlike) ? "NOT " : "" locale = (field.full_text_search == true) ? 'english' : field.full_text_search return "#{negation}to_tsvector('#{locale}', #{field.to_sql(operator, &block)}) #{self.sql_operator(operator, field)} to_tsquery('#{locale}', ?)" else super end end |
#to_not_sql(rhs, definition, &block) ⇒ Object
Returns a NOT (...) SQL fragment that negates the current AST node's children
611 612 613 |
# File 'lib/scoped_search/query_builder.rb', line 611 def to_not_sql(rhs, definition, &block) "NOT COALESCE(#{rhs.to_sql(self, definition, &block)}, false)" end |