Module: ParamParser

Includes:
GeneralUtils
Included in:
SearchQuery
Defined in:
app/parsers/param_parser.rb

Instance Method Summary collapse

Methods included from GeneralUtils

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

Instance Method Details

#find_field_param_match(param_item, dataspec) ⇒ Object

Finds params that match for a given dataspec



67
68
69
70
71
72
73
74
# File 'app/parsers/param_parser.rb', line 67

def find_field_param_match(param_item, dataspec)
  dataspec.searchable_fields.each do |field|
    # Find field that matches in dataspec and process
    if paramMatch?(getFieldDetails(field, dataspec.field_info), param_item)
      return process_param_by_type(field, dataspec)
    end
  end
end

#get_param_includes(phrase) ⇒ Object

Gets the first param that includes the phrase



55
56
57
58
59
# File 'app/parsers/param_parser.rb', line 55

def get_param_includes(phrase)
  @params.each do |param|
    return param[0] if param[0].include?(phrase)
  end
end

#params_include?(phrase) ⇒ Boolean

Checks if any params include a particular phrase

Returns:

  • (Boolean)


46
47
48
49
50
51
52
# File 'app/parsers/param_parser.rb', line 46

def params_include?(phrase)
  @params.each do |param|
    return true if param[0].include?(phrase)
  end

  return false
end

#process_param_by_type(search_item, dataspec) ⇒ Object

Split each field into field name and search terms for query processing



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/parsers/param_parser.rb', line 83

def process_param_by_type(search_item, dataspec)
  # Get field details and name to search
  item_info = getFieldDetails(search_item, dataspec.field_info)
  fieldname = search_item.to_sym

  # Check if it is a date and handle input differently if so      
  if item_info["Type"] == "Date"
    processed_params = process_date_params(fieldname, item_info, @params)

  # If not a date                                                              
  else
    processed_params = {
      field: fieldname,
      searchterm: @params[unprocess_item_name(search_item, dataspec)]
    }
  end
  
  # Return params and model to search
  return processed_params, [get_model(dataspec.index_name)]
end

#process_paramsObject

Processes parameters for search query generation



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/parsers/param_parser.rb', line 5

def process_params
  processed_params = Hash.new
  model_to_search = @models
  
  # Search all fields
  if @params[:q]
    processed_params = search_all_fields(:q)
    
  # Search allfields on specific index
  elsif params_include?("all_sindex_")
    # Set processed params
    processed_params = search_all_fields(get_param_includes("all_sindex_").to_sym)
    
    # Get dataspec and model for index
    _, dataspec_to_search = get_search_param(@params)
    model_to_search = [get_model(dataspec_to_search.index_name)]

  # Search date params
  elsif params_include?("startrange_") || params_include?("endrange_") 
    dataspec_to_search, processed_params = process_date_params
    model_to_search = [get_model(dataspec_to_search.index_name)]
    
    
  # Search individual fields
  else
    begin
      # Get correct dataspec and item
      param_item, dataspec_to_search = get_search_param(@params)
    
      # Get params and model to search
      processed_params, model_to_search = find_field_param_match(param_item, dataspec_to_search)
    rescue
      # If it fails, it's probably because there's a facet
    end
  end
  
  processed_params == {} if processed_params.empty?
  return processed_params, model_to_search, dataspec_to_search
end

#search_all_fields(field) ⇒ Object

Sets field and searchterm for searching all fields, all indexes



62
63
64
# File 'app/parsers/param_parser.rb', line 62

def search_all_fields(field)
  return {field: "_all", searchterm: @params[field]}
end

#unprocess_item_name(search_item, dataspec) ⇒ Object

Gets name that would show up in params



77
78
79
# File 'app/parsers/param_parser.rb', line 77

def unprocess_item_name(search_item, dataspec)
  return (search_item.to_s+"_sindex_"+dataspec.index_name).to_sym
end