Method: PgSearchable::Model::Builder.tsquery_expression

Defined in:
lib/pg-searchable/model.rb

.tsquery_expression(term, negated:, prefix:) ⇒ Object

After this, the SQL expression evaluates to a string containing the term surrounded by single-quotes. If :prefix is true, then the term will have :* appended to the end. If :negated is true, then the term will have ! prepended to the front.



101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/pg-searchable/model.rb', line 101

def self.tsquery_expression(term, negated:, prefix:)
  terms = [
    (Arel::Nodes.build_quoted('!') if negated),
    Arel::Nodes.build_quoted("' "),
    Arel::Nodes.build_quoted(term),
    Arel::Nodes.build_quoted(" '"),
    (Arel::Nodes.build_quoted(":*") if prefix)
  ].compact
  
  terms.inject do |memo, term|
    Arel::Nodes::InfixOperation.new("||", memo, Arel::Nodes.build_quoted(term))
  end
end