Class: LucidWorks::Datasource

Inherits:
Base
  • Object
show all
Defined in:
lib/lucid_works/datasource.rb,
lib/lucid_works/datasource/job.rb,
lib/lucid_works/datasource/index.rb,
lib/lucid_works/datasource/status.rb,
lib/lucid_works/datasource/history.rb,
lib/lucid_works/datasource/schedule.rb,
lib/lucid_works/datasource/crawldata.rb

Defined Under Namespace

Classes: Crawldata, History, Index, Job, Schedule, Status

Constant Summary collapse

TYPES =
%w{ external file ftp hdfs kfs lucidworkslogs web s3 s3n smb solrxml jdbc sharepoint }
SYSTEM_TYPES =
%w{ lucidworkslogs }
BOUNDS =
%w{ tree none }
CRAWLERS =
{
  # Later we may change these to be arrays if we decide to support more than one choice
  # e.g. :web => ['lucid.aperture', 'nutch'], :file => ['lucid.aperture', 'lucid.fs']
  :file           => 'lucid.aperture',
  :lucidworkslogs => 'lucid.logs',
  :external       => 'lucid.external',
  :web            => 'lucid.aperture',
  :solrxml        => 'lucid.solrxml',
  :jdbc           => 'lucid.jdbc',
  :sharepoint     => 'lucid.gcm',
  :ftp            => 'lucid.fs',
  :hdfs           => 'lucid.fs',
  :kfs            => 'lucid.fs',
  :smb            => 'lucid.fs',
  :s3n            => 'lucid.fs',
  :s3             => 'lucid.fs'
}.with_indifferent_access

Constants included from Utils::BoolConverter

Utils::BoolConverter::FALSE_VALUES, Utils::BoolConverter::TRUE_VALUES

Instance Attribute Summary

Attributes inherited from Base

#attributes, #id, #parent, #persisted, #raw_response, #response_data

Instance Method Summary collapse

Methods inherited from Base

all, #collection_url, collection_url, create, #destroy, extract_parent_from_options, find, first, human_attribute_value, #human_attribute_value, #initialize, #inspect, last, #member_url, #persisted?, #read_attribute_for_validation, #save, schema, singleton_name, to_select, #update_attributes

Methods included from SimpleNaming

#model_name

Methods included from Utils::BoolConverter

#to_bool

Constructor Details

This class inherits a constructor from LucidWorks::Base

Instance Method Details

#commit_within_minObject

Fake attributes to ease UI implementation



101
102
103
# File 'lib/lucid_works/datasource.rb', line 101

def commit_within_min
  commit_within.blank? ? nil : commit_within / 1.second.milliseconds / 1.minute.seconds
end

#commit_within_min=(mins) ⇒ Object



104
105
106
# File 'lib/lucid_works/datasource.rb', line 104

def commit_within_min=(mins)
  self.commit_within = mins.blank? ? nil : mins.to_i.minutes.milliseconds
end

#crawlable?Boolean

Returns:

  • (Boolean)


135
136
137
138
# File 'lib/lucid_works/datasource.rb', line 135

def crawlable?
  # Don't let user schedule crawl of external datasources
  !%w{ external }.include?(type)
end

#delete_after_daysObject



107
108
109
# File 'lib/lucid_works/datasource.rb', line 107

def delete_after_days
  delete_after.blank? ? nil : deleteAfter / 1.second.milliseconds / 1.day.seconds
end

#delete_after_days=(days) ⇒ Object



110
111
112
# File 'lib/lucid_works/datasource.rb', line 110

def delete_after_days=(days)
  self.delete_after = days.blank? ? nil : days.to_i.days.milliseconds
end

#destroyable?Boolean

Returns:

  • (Boolean)


130
131
132
133
# File 'lib/lucid_works/datasource.rb', line 130

def destroyable?
  # Don't let user destroy data sources of system collections
  !collection.system?
end

#document_countObject



114
115
116
117
118
119
# File 'lib/lucid_works/datasource.rb', line 114

def document_count
  collection.rsolr_get(:select,
                       :wt => :ruby,
                       :q => (type == 'lucidworkslogs' ? "*:*" : "data_source:#{id}"),
                       :rows => 0)['response']['numFound']
end

#editable?Boolean

Don’t let user edit data sources of system collections

Returns:

  • (Boolean)


126
127
128
# File 'lib/lucid_works/datasource.rb', line 126

def editable?
  !collection.system?
end

#empty!Object



121
122
123
# File 'lib/lucid_works/datasource.rb', line 121

def empty!
  build_index.destroy
end

#progressObject



152
153
154
155
156
157
158
# File 'lib/lucid_works/datasource.rb', line 152

def progress
  return nil if status.stopped?
  return nil unless histories.size > 0
  percent_done = status.elapsed_time.to_f / histories.last.duration
  percent_done = nil if percent_done > 1.0
  percent_done
end

#start_crawl!Object



140
141
142
# File 'lib/lucid_works/datasource.rb', line 140

def start_crawl!
  build_job.save
end

#stop_crawl!Object



144
145
146
# File 'lib/lucid_works/datasource.rb', line 144

def stop_crawl!
  build_job.destroy
end

#t_typeObject



148
149
150
# File 'lib/lucid_works/datasource.rb', line 148

def t_type
  I18n.t(type, :scope => 'activemodel.models.lucid_works.datasource.type')
end