Module: Blacklight::Solr::Response::Facets

Included in:
Blacklight::Solr::Response
Defined in:
lib/blacklight/solr/response/facets.rb

Defined Under Namespace

Classes: FacetField, FacetItem, NullFacetField

Instance Method Summary collapse

Instance Method Details

#aggregationsObject

Get all the Solr facet data (fields, queries, pivots) as a hash keyed by both the Solr field name and/or by the blacklight field name



112
113
114
# File 'lib/blacklight/solr/response/facets.rb', line 112

def aggregations
  @aggregations ||= default_aggregations.merge(facet_field_aggregations).merge(facet_query_aggregations).merge(facet_pivot_aggregations).merge(json_facet_aggregations)
end

#facet_countsObject



116
117
118
# File 'lib/blacklight/solr/response/facets.rb', line 116

def facet_counts
  @facet_counts ||= self['facet_counts'] || {}
end

#facet_fieldsObject

Returns the hash of all the facet_fields (ie: { ‘instock_b’ => [‘true’, 123, ‘false’, 20] }



121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/blacklight/solr/response/facets.rb', line 121

def facet_fields
  @facet_fields ||= begin
    val = facet_counts['facet_fields'] || {}

    # this is some old solr (1.4? earlier?) serialization of facet fields
    if val.is_a? Array
      val.to_h
    else
      val
    end
  end
end

#facet_pivotObject

Returns all of the facet queries



140
141
142
# File 'lib/blacklight/solr/response/facets.rb', line 140

def facet_pivot
  @facet_pivot ||= facet_counts['facet_pivot'] || {}
end

#facet_queriesObject

Returns all of the facet queries



135
136
137
# File 'lib/blacklight/solr/response/facets.rb', line 135

def facet_queries
  @facet_queries ||= facet_counts['facet_queries'] || {}
end

#merge_facet(name:, value:, hits: nil) ⇒ Object

Merge or add new facet count values to existing response



145
146
147
148
149
150
151
# File 'lib/blacklight/solr/response/facets.rb', line 145

def merge_facet(name:, value:, hits: nil)
  if dig('facet_counts', 'facet_fields', name)
    self['facet_counts']['facet_fields'][name] << value << hits
  else
    self['facet_counts']['facet_fields'][name] = [value, hits]
  end
end