module PG::FTS::Index

Public Class Methods

build(*indices, &executor) click to toggle source
# File lib/pg/fts/index.rb, line 103
def build(*indices, &executor)
  indices.each { |index| index.build(&executor) }
end
clear(*indices, &executor) click to toggle source
# File lib/pg/fts/index.rb, line 99
def clear(*indices, &executor)
  indices.each { |index| index.clear(&executor) }
end
create(*indices, &executor) click to toggle source
# File lib/pg/fts/index.rb, line 91
def create(*indices, &executor)
  indices.each { |index| index.create(&executor) }
end
drop(*indices, &executor) click to toggle source
# File lib/pg/fts/index.rb, line 95
def drop(*indices, &executor)
  indices.each { |index| index.drop(&executor) }
end
drop_all(&executor) click to toggle source
# File lib/pg/fts/index.rb, line 86
def drop_all(&executor)
  drop_all_triggers(&executor)
  drop_all_procedures(&executor)
end
drop_all_procedures() { |<<-gsub(/^ {6}/, '')| ... } click to toggle source
# File lib/pg/fts/index.rb, line 56
    def drop_all_procedures
      procedures = yield <<-SQL.gsub(/^ {6}/, '')
      SELECT routine_name AS name
      FROM information_schema.routines
      WHERE routine_name LIKE '%_tsv'
        AND routine_type = 'FUNCTION';
      SQL

      procedures.each do |procedure|
        yield <<-SQL.gsub(/^ {8}/, '')
        DROP FUNCTION IF EXISTS "#{procedure['name']}" ();
        SQL
      end
    end
drop_all_triggers() { |<<-gsub(/^ {6}/, '')| ... } click to toggle source
# File lib/pg/fts/index.rb, line 71
    def drop_all_triggers
      triggers = yield <<-SQL.gsub(/^ {6}/, '')
      SELECT tgname AS name, relname AS table
      FROM pg_trigger
      INNER JOIN pg_class ON pg_class.oid = tgrelid
      WHERE tgname like '%_tsv';
      SQL

      triggers.each do |trigger|
        yield <<-SQL.gsub(/^ {8}/, '')
        DROP TRIGGER IF EXISTS "#{trigger['name']}" ON "#{trigger['table']}";
        SQL
      end
    end
rebuild(*indices, &executor) click to toggle source
# File lib/pg/fts/index.rb, line 107
def rebuild(*indices, &executor)
  indices.each { |index| index.rebuild(&executor) }
end
recreate(*indices, &executor) click to toggle source
# File lib/pg/fts/index.rb, line 111
def recreate(*indices, &executor)
  drop_all(&executor)
  create(*indices, &executor)
end
reset(*indices, &executor) click to toggle source
# File lib/pg/fts/index.rb, line 116
def reset(*indices, &executor)
  recreate(*indices, &executor)
  PG::FTS.clear(&executor)
end

Public Instance Methods

build() { |build_query| ... } click to toggle source
# File lib/pg/fts/index.rb, line 46
def build
  yield(build_query)
end
clear() { |on_document_truncate_query| ... } click to toggle source
# File lib/pg/fts/index.rb, line 42
def clear
  yield(on_document_truncate_query)
end
create() { |send(name)| ... } click to toggle source
# File lib/pg/fts/index.rb, line 2
def create
  [:document, :source, :link].each do |type|
    [:insert, :update, :delete, :truncate].each do |op|
      [:procedure, :trigger].each do |item|
        name = "on_#{type}_#{op}_#{item}"
        yield(send(name)) if respond_to?(name)
      end
    end
  end
end
drop() { |drop_trigger_query(name, type)| ... } click to toggle source
# File lib/pg/fts/index.rb, line 31
def drop
  [:document, :source, :link].each do |type|
    [:insert, :update, :delete, :truncate].each do |op|
      name = "on_#{type}_#{op}_trigger"
      yield(drop_trigger_query(name, type)) if respond_to?(name)
      name = "on_#{type}_#{op}_procedure"
      yield(drop_procedure_query(name)) if respond_to?(name)
    end
  end
end
drop_procedure_query(name) click to toggle source
# File lib/pg/fts/index.rb, line 13
  def drop_procedure_query(name)
    <<-SQL.gsub(/^ {4}/, '')
    DROP FUNCTION IF EXISTS "#{send(name + '_name')}" ();
    SQL
  end
drop_trigger_query(name, type) click to toggle source
# File lib/pg/fts/index.rb, line 19
  def drop_trigger_query(name, type)
    t = case type
        when :document then document
        when :source then source
        when :link then link
        end

    <<-SQL.gsub(/^ {4}/, '')
    DROP TRIGGER IF EXISTS "#{send(name + '_name')}" ON "#{t}";
    SQL
  end
rebuild(&executor) click to toggle source
# File lib/pg/fts/index.rb, line 50
def rebuild(&executor)
  clear(&executor)
  build(&executor)
end