Module: FacetsQuery

Includes:
DataspecUtils, GeneralUtils
Included in:
ApplicationController, DocsController, IndexManager, SearchQuery
Defined in:
app/queries/facets_query.rb

Instance Method Summary collapse

Methods included from DataspecUtils

#checkIfX, #getFieldDetails, #sortFields

Methods included from GeneralUtils

#genLink, #getHR, #get_date_index, #get_search_param, #paramMatch?

Instance Method Details

#build_facet_filtersObject

Creates the part of the query for filtering by category


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/queries/facets_query.rb', line 18

def build_facet_filters
  hasharr = Array.new
  @filter_by.each do |k, v|
    # Handles categories where multiple values are being filtered for 
    if v.is_a? Array
      v.each { |j| hasharr.push({ term: { k => j}})}

    # If only one category per field is being filtered for 
    else
      hasharr.push({ term: { k => v}})
    end
  end
  filterhash = { "and" => hasharr }
end

#get_all_categories(dataspec) ⇒ Object

Specify which categories/facets to get info for on the sidebar- all of them


6
7
8
9
10
11
12
13
14
15
# File 'app/queries/facets_query.rb', line 6

def get_all_categories(dataspec)
  fieldhash = Hash.new
  
  # Generate queries to get each facet
  dataspec.facet_fields.each do |field|
    fieldhash[field.to_sym] = {terms: {field: field+"_facet", size: 500}}
  end
  
  return fieldhash
end