Class: MartSearch::DataSet

Inherits:
Object
  • Object
show all
Includes:
DataSetUtils
Defined in:
lib/martsearch/data_set.rb

Overview

DataSet class for modelling a search for data.

Author:

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from DataSetUtils

#allele_type, #fix_superscript_text_in_attribute

Constructor Details

- (DataSet) initialize(conf)



13
14
15
# File 'lib/martsearch/data_set.rb', line 13

def initialize( conf )
  @config = conf
end

Instance Attribute Details

- (Object) config (readonly)

Returns the value of attribute config



10
11
12
# File 'lib/martsearch/data_set.rb', line 10

def config
  @config
end

Instance Method Details

- (String) data_origin_url(query)

Function used to drive a MartSearch::DataSource object and retieve a URL to link back to the origin of the data for a given dataset.



77
78
79
80
81
82
83
# File 'lib/martsearch/data_set.rb', line 77

def data_origin_url( query )
  MartSearch::Controller.instance().logger.debug("[MartSearch::DataSet] '#{self.name}' ::data_origin_url - running data_origin_url( '#{query}' )")
  url = nil
  url = datasource.data_origin_url( query, @config[:searching] ) unless query.nil?
  MartSearch::Controller.instance().logger.debug("[MartSearch::DataSet] '#{self.name}' ::data_origin_url - running data_origin_url( '#{query}' ) - DONE")
  return url
end

- (MartSearch::DataSource) datasource

Helper function to supply our MartSearch::DataSource instance.



88
89
90
91
92
93
94
95
# File 'lib/martsearch/data_set.rb', line 88

def datasource
  ds = MartSearch::Controller.instance().config[:datasources][ @config[:datasource].to_sym ]
  if ds.nil?
    raise MartSearch::InvalidConfigError, "Unable to find a datasource called '#{@config[:datasource]}' for dataset '#{@config[:internal_name]}'!"
  else
    return ds
  end
end

- (String) joined_index_field

Helper function to return the 'joined_index_field' for this DataSet instance



20
21
22
# File 'lib/martsearch/data_set.rb', line 20

def joined_index_field
  @config[:searching][:joined_index_field]
end

- (String) name

Helper function to return the 'internal_name' for this DataSet instance



27
28
29
# File 'lib/martsearch/data_set.rb', line 27

def name
  @config[:internal_name]
end

- (Hash) search(query)

Function used to drive a MartSearch::DataSource object to perform a query for a given dataset. Returns a hash, keyed by the 'joined_attribute' where the values are an array of results objects associated with this key.

i.e.

{
  'Cbx1' => [object,object],
  'Cbx2' => [object,object]
}


43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/martsearch/data_set.rb', line 43

def search( query )
  MartSearch::Controller.instance().logger.debug("[MartSearch::DataSet] '#{self.name}' ::search - running search( '#{query}' )")
  if query.nil?
    # Don't perform a search on empty parameters - this is bad!
    return {}
  else
    results        = datasource.search( query, @config[:searching] )
    sorted_results = sort_results( results )
    
    MartSearch::Controller.instance().logger.debug("[MartSearch::DataSet] '#{self.name}' ::search - running search( '#{query}' ) - DONE")
    return sorted_results
  end
end

- (Hash) secondary_sort(search_data)

This method is abstract.

A secondary sort function that allows a dataset to interact with the data from all the other datasets prior to going to the templates or into a cache store. This can be used to house some cross-dataset processing that would otherwise be done in the template.

This function is empty as it's a placeholder for custom codeā€¦



67
68
69
70
# File 'lib/martsearch/data_set.rb', line 67

def secondary_sort( search_data )
  MartSearch::Controller.instance().logger.debug("[MartSearch::DataSet] '#{self.name}' ::secondary_sort - running secondary_sort()")
  search_data
end