Class: SearchQuery

Inherits:
Object
  • Object
show all
Includes:
DataspecUtils, DateParser, FacetsQuery, FieldQuery, HighlightQuery, ParamParser
Defined in:
app/models/search_query.rb

Instance Method Summary collapse

Methods included from DataspecUtils

#checkIfX, #getFieldDetails, #sortFields

Methods included from ParamParser

#find_field_param_match, #get_param_includes, #params_include?, #process_param_by_type, #process_params, #search_all_fields, #unprocess_item_name

Methods included from GeneralUtils

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

Methods included from DateParser

#handle_empty_dates, #parse_date, #process_date_params

Methods included from HighlightQuery

#highlightLength, #specify_fields_to_highlight

Methods included from FieldQuery

#build_search_query, #combine_search_and_facet_queries, #get_field_type

Methods included from FacetsQuery

#build_facet_filters, #get_all_categories

Constructor Details

#initialize(params, start) ⇒ SearchQuery

Returns a new instance of SearchQuery


9
10
11
12
13
# File 'app/models/search_query.rb', line 9

def initialize(params, start)
  @params = params
  @start = start
  load_everything
end

Instance Method Details

#build_queryObject

Calls methods to process params and put together query


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/search_query.rb', line 16

def build_query
  # Initial processing of query and facet parameters
  @input, @model_to_search, @dataspec_to_search = process_params
  @filter_by = @params.select { |i| i.include? "_facet" }
  
  @fieldnames = [@input[:field]]
  queryhash = {}
  highlighthash = Hash.new
  
  # Form specific query for parameters passed
  queryhash = build_search_query 
  filterhash = build_facet_filters
  fullhash = combine_search_and_facet_queries(queryhash, filterhash)
  
  # Get information needed to display results nicely
  fieldhash = @all_facets # CHECK ON ALL SEARCH AND ONE INDEX SEARCH
  #fieldhash = get_all_categories ONLY WORKS FOR ALL FACETS
  highlighthash = specify_fields_to_highlight(queryhash, highlighthash)
  
  query = {from: @start, size: 30, query: fullhash, facets: fieldhash,
             highlight: { pre_tags: ["<b class='is_highlighted'>"], post_tags: ["</b>"], fields: highlighthash}}
  
  return query, @model_to_search
end