Class: IndexManager

Inherits:
Object
  • Object
show all
Extended by:
ClassGen, DateFuncs, DeduplicateData, FacetsQuery, GenerateId, ImportSupport, MiscProcess, MultiDataset, ProcessData
Includes:
ENAnalyzer, MiscProcess
Defined in:
lib/index_manager.rb

Class Method Summary collapse

Methods included from FacetsQuery

build_facet_filters, get_all_categories

Methods included from DataspecUtils

#checkIfX, #getFieldDetails, #sortFields

Methods included from GeneralUtils

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

Methods included from ClassGen

gen_class

Methods included from MultiDataset

create_all_models, create_model, dataspecs_by_name, get_all_facets, get_all_field_info, get_all_searchable_fields, get_all_truncated_fields, get_dataspec, get_model, loadAllDatasets, load_everything, run_all, use_all_or_some

Methods included from MiscProcess

gen_class_name, make_facet_version, process_pic, set_name

Methods included from ImportSupport

appendCategories, getDatasetName, getDatasource, getNameCategories, importFileInDir, importFromFile, importFromURL, openFile

Methods included from ProcessData

createFromFile, createItem, processItem

Methods included from DeduplicateData

bothNotNil?, deduplicate, exactMatch?, fieldValsMatch?, isEmpty?, isNonIntNum?, matchAsInt?, removeIgnore, simplyDoesntMatch?

Methods included from DateFuncs

blank_if_match, handle_foreign_dates, handle_present_dates, handle_unknown_dates, handle_year_only, isDate?, normalize_date, process_date

Methods included from GenerateId

addIndex, appendSecondary, cleanID, getID, removeIDPart

Methods included from ENAnalyzer

analyzerSettings

Class Method Details

.create_index(dataspec, model_name, options = {}) ⇒ Object

Index creation


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/index_manager.rb', line 26

def self.create_index(dataspec, model_name, options={})
  # Make client, get settings, set name
  doc_class = ClassGen.gen_class(model_name, dataspec)
  client = doc_class.gateway.client

  # Delete index if it already exists
  client.indices.delete index: dataspec.index_name rescue nil if options[:force]

  settings = ENAnalyzer.analyzerSettings
  mappings = doc_class.mappings.to_hash

  # Create index with appropriate settings and mappings
  client.indices.create index: dataspec.index_name,
  body: {
    settings: settings.to_hash,
    mappings: mappings.to_hash }

  return doc_class
end

.import_data(options = {}) ⇒ Object

Import data from different formats


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/index_manager.rb', line 47

def self.import_data(options={})
  # Load all datasets and make indexes for them
  @importer = JSON.parse(File.read("app/dataspec/importer.json")).first
  load_everything

  @dataspecs.each do |dataspec|
    doc_class = create_index(dataspec, gen_class_name(dataspec), force: true)

    # Import from file, link, or dir
    case dataspec.data_path_type
    when "File"
      importFromFile
    when "url"
      importFromURL
    when "Directory"
      Dir.glob(dataspec.data_path+"/**/*.json") do |file|
        if !file.include? dataspec.ignore_ext
          begin
            importFileInDir(file, dataspec, doc_class)
          rescue
          end
        end
      end
    end
  end
end