Class: LucidWorks::Collection

Inherits:
Base
  • Object
show all
Defined in:
lib/lucid_works/collection.rb,
lib/lucid_works/collection/info.rb,
lib/lucid_works/collection/click.rb,
lib/lucid_works/collection/index.rb,
lib/lucid_works/collection/settings.rb

Defined Under Namespace

Classes: Click, Index, Info, Settings

Constant Summary collapse

LOGS_COLLECTION_NAME =
'LucidWorksLogs'

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, #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

#admin_urlObject

URL of Solr’s build-in admin page



128
129
130
# File 'lib/lucid_works/collection.rb', line 128

def admin_url
  "#{server.server_uri}/solr/#{name}/admin/"
end

#available_templatesObject



150
151
152
# File 'lib/lucid_works/collection.rb', line 150

def available_templates
  JSON.parse(RestClient.get(server.uri + "/collectiontemplates"))
end

#build_elevation(attributes = {}) ⇒ Object



95
96
97
# File 'lib/lucid_works/collection.rb', line 95

def build_elevation(attributes = {})
  Elevation.new(attributes.merge(:collection => self))
end

#build_synonym(attributes = {}) ⇒ Object



79
80
81
# File 'lib/lucid_works/collection.rb', line 79

def build_synonym(attributes = {})
  Synonym.new(attributes.merge(:collection => self))
end

#commitObject



43
44
45
# File 'lib/lucid_works/collection.rb', line 43

def commit
  solr.commit
end

#componentsObject



146
147
148
# File 'lib/lucid_works/collection.rb', line 146

def components
  JSON.parse(RestClient.get(uri + "/components/all.json?handlerName=%2Flucid"))
end

#destroyable?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/lucid_works/collection.rb', line 30

def destroyable?
  true
end

#document_countObject



69
70
71
# File 'lib/lucid_works/collection.rb', line 69

def document_count
  solr.get('select', :params => {:wt => :ruby, :q => "*:*", :rows => 0})['response']['numFound']
end

#elevationsObject



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/lucid_works/collection.rb', line 83

def elevations
  elevations = []
  settings.elevations.each do |query, elevation_entries|
    elevation_entries.each do |entry|
      elevations << Elevation.new(
        :doc_id => entry['doc'], :collection => self, :query => query, :excluded => entry['exclude'], :persisted => true
      )
    end
  end
  elevations
end

#empty!Object



39
40
41
# File 'lib/lucid_works/collection.rb', line 39

def empty!
  build_index.destroy(:params => {:key => 'iaccepttherisk'})
end

#jdbcdriver_classesObject



142
143
144
# File 'lib/lucid_works/collection.rb', line 142

def jdbcdriver_classes
  JSON.parse RestClient.get(uri + "/jdbcdrivers/classes")
end

#jdbcdriversObject

We have to handle the jdbcdrivers model in a custom way, as a GET on …/jdbcdrivers returns a list of strings, but then you can actually do a DELETE on …/jdbcdrivers/name. For the DELETE reason we do use a LucidWorks::Base model, but we have to create them by hand.



135
136
137
138
139
140
# File 'lib/lucid_works/collection.rb', line 135

def jdbcdrivers
  driverlist = JSON.parse RestClient.get(self.uri + '/jdbcdrivers')
  driverlist.map do |drivername|
    Jdbcdriver.new(:name => drivername, :collection => self)
  end
end

#prime_activitiesObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/lucid_works/collection.rb', line 99

def prime_activities
  self.activities!.sort!{|a,b|a.id <=> b.id}
  num_created = 0
  activities_to_return = ::LucidWorks::Activity::TYPES.map do |type|
    if act = self.activities.detect{|act| act.type == type}
      act
    else
      num_created += 1
      start_time = Time.now.change(:min => 0) + num_created.hours
      self.create_activity(:type => type, :active => false, :start_time => start_time, :period => 1.days.seconds.to_i)
    end
  end
  self.activities! if num_created > 0
  activities_to_return
end

#request_handler(name) ⇒ Object



154
155
156
# File 'lib/lucid_works/collection.rb', line 154

def request_handler(name)
  RequestHandler.new(self, name)
end

#search(solr_params, options = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/lucid_works/collection.rb', line 47

def search(solr_params, options = {})
  ActiveSupport::Notifications.instrument('solr.lucid_works') do |payload|
    path = options[:path] || 'select'
    begin
      result = if options[:page] && options[:per_page]
        # Constructing the request here instead of using result.request[:uri] to avoid losing it on RSolr::Error::Http errors
        payload[:request] = solr.build_paginated_request(options[:page], options[:per_page], path, :params => solr_params)[:uri].to_s
        solr.paginate(options[:page], options[:per_page], path, :params => solr_params)
      else
        # Constructing the request here instead of using result.request[:uri] to avoid losing it on RSolr::Error::Http errors
        payload[:request] = solr.build_request(path, :params => solr_params)[:uri].to_s
        solr.get(path, :params => solr_params)
      end
      payload[:status] = result.response[:status]
      result
    rescue RSolr::Error::Http => error
      payload[:status] = error.response[:status]
      raise
    end
  end
end

#synonymsObject



73
74
75
76
77
# File 'lib/lucid_works/collection.rb', line 73

def synonyms
  settings.synonym_list.each_with_index.map do |mapping, index|
    Synonym.new(:id => index, :collection => self, :mapping => mapping, :persisted => true)
  end
end

#system?Boolean

is this a ‘system’ collection

Returns:

  • (Boolean)


35
36
37
# File 'lib/lucid_works/collection.rb', line 35

def system?
  name == LOGS_COLLECTION_NAME
end

#update_caches_attributes(attributes) ⇒ Object



23
24
25
26
27
28
# File 'lib/lucid_works/collection.rb', line 23

def update_caches_attributes(attributes)
  attributes = attributes.with_indifferent_access
  caches.each {|cache| cache.attributes = attributes[cache.name] if attributes.include?(cache.name) }
  return false unless caches.all? &:valid?
  caches.all? &:save
end