module PgSearch::ScopeOptions::PgSearchRankTableAliasing

def pg_search_rank_table_alias(include_counter = false)

def pg_search_rank_table_alias(include_counter = false)
  components = [arel_table.name]
  if include_counter
    count = pg_search_scope_application_count_plus_plus
    components << count if count > 0
  end
  Configuration.alias(components)
end

def pg_search_scope_application_count

def pg_search_scope_application_count
  @pg_search_scope_application_count ||= 0
end

def pg_search_scope_application_count_plus_plus

def pg_search_scope_application_count_plus_plus
  count = pg_search_scope_application_count
  self.pg_search_scope_application_count = pg_search_scope_application_count + 1
  count
end