Sha256: 95379f73e77e903f89b50274340ca929e32c433d529f2db54170d872a03c5c0e

Contents?: true

Size: 796 Bytes

Versions: 5

Compression:

Stored size: 796 Bytes

Contents

module SearchCraft::TextSearch
  # setweight(to_tsvector('english', COALESCE(display_name, name, ''), 'C')
  def setweight_arel(*columns, weight: "C", language: "english")
    Arel::Nodes::NamedFunction.new(
      "setweight",
      [
        to_tsvector_arel(*columns, language: language),
        Arel.sql("'#{weight}'")
      ]
    )
  end

  # to_tsvector('english', COALESCE(display_name, name, ''))
  def to_tsvector_arel(*columns, language: "english")
    Arel::Nodes::NamedFunction.new(
      "to_tsvector",
      [
        Arel.sql("'#{language}'"),
        coalesce([
          *columns,
          Arel::Nodes::SqlLiteral.new("''")
        ])
      ]
    )
  end

  # COALESCE(display_name, name)
  def coalesce(columns)
    Arel::Nodes::NamedFunction.new "COALESCE", columns
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
searchcraft-0.5.2 lib/searchcraft/text_search.rb
searchcraft-0.5.1 lib/searchcraft/text_search.rb
searchcraft-0.5.0 lib/searchcraft/text_search.rb
searchcraft-0.4.2 lib/searchcraft/text_search.rb
searchcraft-0.4.1 lib/searchcraft/text_search.rb