Class: MartSearch::FileSystemDataSource

Inherits:
DataSource
  • Object
show all
Defined in:
lib/martsearch/data_source_file_system.rb

Overview

Custom DataSource class for reading files off the local filesystem.

Author:

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from DataSource

#name

Methods included from Utils

#build_http_client, #convert_array_to_hash

Constructor Details

- (FileSystemDataSource) initialize(conf)

A new instance of FileSystemDataSource

Parameters:

  • conf (Hash)

    configuration hash



13
14
15
16
17
18
19
20
# File 'lib/martsearch/data_source_file_system.rb', line 13

def initialize( conf )
  super
  @fs_location = "#{MARTSEARCH_PATH}#{@conf[:location]}"
  
  unless File.exists?(@fs_location) and File.directory?(@fs_location)
    raise MartSearch::InvalidConfigError, "#{@fs_location} does not exist, or is not a directory!"
  end
end

Instance Attribute Details

- (Object) fs_location (readonly)

The location on the file system of this dataset.



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

def fs_location
  @fs_location
end

Instance Method Details

- (Object) data_origin_url(query, conf)

Function to provide a link URL to the original datasource given a dataset query.



81
82
83
# File 'lib/martsearch/data_source_file_system.rb', line 81

def data_origin_url( query, conf )
  nil
end

- (Object) fetch_all_terms_for_indexing(conf)

Function to query a biomart datasource and return all of the data ready for indexing.

- THIS FEATURE HAS NOT BEEN IMPLEMENTED FOR THIS CLASS.

Raises:

  • (NotImplementedError)

    This feature has not been implemented for this class

See Also:



34
35
36
# File 'lib/martsearch/data_source_file_system.rb', line 34

def fetch_all_terms_for_indexing( conf )
  raise NotImplementedError, "This feature has not been implemented for the FileSystemDataSource class."
end

- (Boolean) is_alive?

Simple heartbeat function to check that the datasource is online.

Returns:

  • (Boolean)

See Also:



25
26
27
# File 'lib/martsearch/data_source_file_system.rb', line 25

def is_alive?
  true
end

- (Object) search(query, conf)

Function to search a biomart datasource given an appropriate configuration.

Raises:

See Also:



42
43
44
45
46
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
73
74
75
# File 'lib/martsearch/data_source_file_system.rb', line 42

def search( query, conf )
  MartSearch::Controller.instance().logger.debug("[MartSearch::FileSystemDataSource] '#{self.name}' ::search - running search( '#{query}', conf )")
  unless conf[:file_globs]
    raise MartSearch::DataSourceError, "You have not specifed any 'glob' patterns!"
  end
  
  results   = []
  file_list = []
  pwd       = Dir.pwd
  
  begin
    Dir.chdir(@fs_location)
    conf[:file_globs].each do |glob_str|
      Dir.glob(glob_str).each do |file|
        file_list.push( file )
      end
    end
  rescue => error
    Dir.chdir(pwd)
    raise MartSearch::DataSourceError, "Error querying file system: #{error}"
  end
  
  Dir.chdir(pwd)
  
  file_list.each do |file|
    query.each do |string|
      if file.include?(string)
        results.push({ conf[:joined_index_field].to_sym => string, :file => file })
      end
    end
  end
  
  return results.uniq
end