Class: HasHelpers::Query::Sql

Inherits:
Object
  • Object
show all
Includes:
Provider
Defined in:
app/lib/has_helpers/query/sql.rb

Constant Summary

Constants included from Provider

Provider::PAGINATION_ATTRS

Class Method Summary collapse

Methods included from Provider

all, from_short_name, included, owner_relation_from_scope, #query_options, relation_exists?, #search

Class Method Details

.available_ts_search_configsObject



23
24
25
# File 'app/lib/has_helpers/query/sql.rb', line 23

def self.available_ts_search_configs
  @available_ts_search_configs = ::ActiveRecord::Base.connection.execute("SELECT cfgname FROM pg_ts_config").map { |r| r["cfgname"] }
end

.scope_to_organization?(_klass) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'app/lib/has_helpers/query/sql.rb', line 15

def self.scope_to_organization?(_klass)
  true
end

.sql(vector, query) ⇒ Object



8
9
10
11
12
13
# File 'app/lib/has_helpers/query/sql.rb', line 8

def self.sql(vector, query)
  [
    "to_tsvector('#{ ts_search_config("english_nostop") }', #{ vector }) @@ to_tsquery('#{ ts_search_config("english_nostop") }', ?)",
    query.strip.tr("'", " ").split(/\s/).map { |qpart| "'#{qpart}':*" }.join(" & ")
  ]
end

.ts_search_config(name) ⇒ Object



19
20
21
# File 'app/lib/has_helpers/query/sql.rb', line 19

def self.ts_search_config(name)
  available_ts_search_configs.find { |c| c == name } || "english" # I'm pretty sure "english" will be always available, at least on any of the OneHQ Postgres instances.
end