Class: Krikri::ProdSearchIndex

Inherits:
SearchIndex show all
Defined in:
lib/krikri/search_index.rb

Overview

Production ElasticSearch search index class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SearchIndex

#add

Constructor Details

#initialize(opts = Krikri::Settings.elasticsearch.to_h) ⇒ ProdSearchIndex

Options used by this class:

- index_name [String]  The name of the ElasticSearch index

Other options are passed along to Elasticsearch::Client.

Parameters:

  • opts (Hash) (defaults to: Krikri::Settings.elasticsearch.to_h)


286
287
288
289
290
# File 'lib/krikri/search_index.rb', line 286

def initialize(opts = Krikri::Settings.elasticsearch.to_h)
  super(opts)
  @index_name = opts.delete(:index_name) { 'dpla_alias' }
  @elasticsearch = Elasticsearch::Client.new(opts)
end

Instance Attribute Details

#elasticsearchObject (readonly)

Returns the value of attribute elasticsearch.



277
278
279
# File 'lib/krikri/search_index.rb', line 277

def elasticsearch
  @elasticsearch
end

#index_nameObject (readonly)

Returns the value of attribute index_name.



277
278
279
# File 'lib/krikri/search_index.rb', line 277

def index_name
  @index_name
end

Instance Method Details

#bulk_add(docs) ⇒ Object

Add a number of JSON documents to the search index at once.

Parameters:

  • docs (Array)

    Array of hashes that can be serialized with #to_json



295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/krikri/search_index.rb', line 295

def bulk_add(docs)
  body = docs.map do |doc|
    {
      index: {
        _index: @index_name,
        _type: doc[:ingestType],
        _id:  doc[:id],
        data: doc
      }
    }
  end
  @elasticsearch.bulk body: body
end

#hash_for_index_schema(aggregation) ⇒ Object

See Also:

  • SearchIndex#hash_for_index_schema


319
320
321
322
323
324
# File 'lib/krikri/search_index.rb', line 319

def hash_for_index_schema(aggregation)
  graph = aggregation.to_jsonld['@graph'][0]
  # TODO: munge graph to MAPv3
  #       update search_index_spec.rb when that's done.
  graph
end

#update_from_activity(activity) ⇒ Object



311
312
313
314
315
# File 'lib/krikri/search_index.rb', line 311

def update_from_activity(activity)
  fail "#{activity} is not an Activity" \
    unless activity.class == Krikri::Activity
  bulk_update_from_activity(activity)
end