Module: Repertoire::Faceting::Facets::BasicFacet

Includes:
Arel, AbstractFacet
Defined in:
lib/repertoire-faceting/facets/basic_facet.rb

Overview

Implementation of AbstractFacet for non-nested, single-valued facets. By default, all facets that have a single group column will follow this behavior.

See Repertoire::Faceting::Model::ClassMethods for usage.

Instance Attribute Summary

Attributes included from AbstractFacet

#facet_name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AbstractFacet

#drop_index, #facet_indexed?, #refresh_index, #stat_table

Class Method Details

.claim?(relation) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/repertoire-faceting/facets/basic_facet.rb', line 14

def self.claim?(relation)
  relation.group_values.size == 1
end

Instance Method Details

#create_indexObject



34
35
36
37
38
39
40
# File 'lib/repertoire-faceting/facets/basic_facet.rb', line 34

def create_index
  col = group_values.first
  rel = only(:where, :joins, :group)
  sql = rel.select(["#{col} AS #{facet_name}", "facet.signature(#{table_name}.#{faceting_id})", "now() AS updated_at"]).to_sql

  connection.create_materialized_view(facet_index_name, sql)
end

#drill(state) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/repertoire-faceting/facets/basic_facet.rb', line 26

def drill(state)
  return read_index(state, false)            if facet_indexed?
  col = group_values.first
  rel = only(:where, :joins, :group)
  rel = rel.where(in_clause(col, state))     unless state.empty?
  rel.select(["#{col} AS #{facet_name}", "facet.signature(#{table_name}.#{faceting_id})"]).arel
end

#signature(state) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/repertoire-faceting/facets/basic_facet.rb', line 18

def signature(state)
  return read_index(state, true)             if facet_indexed?
  col = group_values.first
  rel = only(:where, :joins)
  rel = rel.where(in_clause(col, state))     unless state.empty?
  rel.select("facet.signature(#{table_name}.#{faceting_id})").arel
end