Module: MultiDataset

Includes:
GeneralUtils, MiscProcess
Included in:
ApplicationController, DocsController, ENAnalyzer, IndexManager, SearchController
Defined in:
app/helpers/multi_dataset.rb

Instance Method Summary collapse

Methods included from GeneralUtils

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

Methods included from MiscProcess

#gen_class_name, #make_facet_version, #process_pic, #set_name

Instance Method Details

#create_all_modelsObject

Create all models


112
113
114
115
116
117
# File 'app/helpers/multi_dataset.rb', line 112

def create_all_models
  @models = Array.new
  @dataspecs.each do |dataspec|
    @models.push(create_model(dataspec, gen_class_name(dataspec)))
  end
end

#create_model(dataspec, model_name) ⇒ Object

Create model


104
105
106
107
108
109
# File 'app/helpers/multi_dataset.rb', line 104

def create_model(dataspec, model_name)
  doc_class = ClassGen.gen_class(model_name, dataspec)
  settings = ENAnalyzer.analyzerSettings
  mappings = doc_class.mappings.to_hash
  return doc_class
end

#dataspecs_by_nameObject

Get all index names


55
56
57
58
59
60
# File 'app/helpers/multi_dataset.rb', line 55

def dataspecs_by_name
  @dataspecs_index_name = Hash.new
  run_all do |dataspec, model|
    @dataspecs_index_name[dataspec.index_name] = dataspec
  end
end

#get_all_facetsObject

Get all the facets


71
72
73
74
75
76
77
# File 'app/helpers/multi_dataset.rb', line 71

def get_all_facets
  @all_facets = Hash.new
  run_all do |dataspec, model|
    facet_fields = get_all_categories(dataspec)
    @all_facets.merge!(facet_fields)
  end
end

#get_all_field_infoObject

Get all field info


80
81
82
83
84
85
# File 'app/helpers/multi_dataset.rb', line 80

def get_all_field_info
  @all_field_info = Array.new
  run_all do |dataspec, model|
    @all_field_info += dataspec.field_info
  end
end

#get_all_searchable_fieldsObject

Get all searchable fields


96
97
98
99
100
101
# File 'app/helpers/multi_dataset.rb', line 96

def get_all_searchable_fields
  @all_searchable_fields = Array.new
  run_all do |dataspec, model|
    @all_searchable_fields += dataspec.searchable_fields
  end
end

#get_all_truncated_fieldsObject

Get all truncated fields


88
89
90
91
92
93
# File 'app/helpers/multi_dataset.rb', line 88

def get_all_truncated_fields
  @all_truncated_fields = Array.new
  run_all do |dataspec, model|
    @all_truncated_fields += dataspec.truncated_fields
  end
end

#get_dataspec(doc) ⇒ Object

Get the dataspec for an item


63
64
65
66
67
68
# File 'app/helpers/multi_dataset.rb', line 63

def get_dataspec(doc)
  doc_index = doc["_index"]
  @dataspecs.each do |dataspec|
    return dataspec if doc_index == dataspec.index_name
  end
end

#get_model(index_name) ⇒ Object

Gets the correct model


48
49
50
51
52
# File 'app/helpers/multi_dataset.rb', line 48

def get_model(index_name)
  run_all do |dataspec, model|
    return model if dataspec.index_name == index_name
  end
end

#load_everythingObject

Load everything


6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/multi_dataset.rb', line 6

def load_everything
  # Load dataspecs and create models
  @instance = InstanceSpec.new
  loadAllDatasets
  create_all_models

  # Load general vars (mult datasets grouped)
  get_all_facets
  get_all_field_info
  get_all_searchable_fields
  get_all_truncated_fields
  dataspecs_by_name
end

#loadAllDatasetsObject

Saves all dataspec values in @dataspecs


21
22
23
24
25
26
27
28
# File 'app/helpers/multi_dataset.rb', line 21

def loadAllDatasets
  @dataspecs = Array.new

  # Load all dataspecs into array
  @instance.dataspec_paths.each do |dataspec_dir|
    @dataspecs.push(DataspecContent.new(dataspec_dir))
  end
end

#run_all(&block) ⇒ Object

Run block of code on all


31
32
33
34
35
36
# File 'app/helpers/multi_dataset.rb', line 31

def run_all(&block)
  @models.each_with_index do |model, index|
    dataspec = @dataspecs[index]
    yield(dataspec, model)
  end
end

#use_all_or_some(check_field, all_field) ⇒ Object

Get an attribute from a particular dataspec or fall back to all


39
40
41
42
43
44
45
# File 'app/helpers/multi_dataset.rb', line 39

def use_all_or_some(check_field, all_field)
  if @dataspec_to_search
    return eval "@dataspec_to_search.#{check_field}"
  else
    return all_field
  end
end