Module: SearchCraft::TextSearch

Included in:
Builder
Defined in:
lib/searchcraft/text_search.rb

Instance Method Summary collapse

Instance Method Details

#coalesce(columns) ⇒ Object

COALESCE(display_name, name)



28
29
30
# File 'lib/searchcraft/text_search.rb', line 28

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

#setweight_arel(*columns, weight: "C", language: "english") ⇒ Object

setweight(to_tsvector(‘english’, COALESCE(display_name, name, ”), ‘C’)



3
4
5
6
7
8
9
10
11
# File 'lib/searchcraft/text_search.rb', line 3

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_arel(*columns, language: "english") ⇒ Object

to_tsvector(‘english’, COALESCE(display_name, name, ”))



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/searchcraft/text_search.rb', line 14

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