Class: Krikri::SearchIndex

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

Overview

TODO:

rewrite to use generalized ‘EntityConsumer` interface & avoid `#update_from_activity`, which is tighly bound to `Activity` rather than `Enumerator<#entities>`.

Search index base class that gets extended by QA and Production index classes

Direct Known Subclasses

ProdSearchIndex, QASearchIndex

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ SearchIndex

Returns a new instance of SearchIndex.



14
15
16
# File 'lib/krikri/search_index.rb', line 14

def initialize(opts)
  @bulk_update_size = opts.delete(:bulk_update_size) { 1000 }
end

Instance Method Details

#add(_) ⇒ Object

Add a single JSON document to the search index. Implemented in a child class.

Parameters:

  • _ (Hash)

    Hash that can be serialized to JSON with #to_json



23
24
25
# File 'lib/krikri/search_index.rb', line 23

def add(_)
  fail NotImplementedError
end

#bulk_add(_) ⇒ Object

Add a number of JSON documents to the search index at once. Implemented in a child class.

Parameters:

  • _ (Array)

    Hashes that can be serialized to JSON with #to_json



32
33
34
# File 'lib/krikri/search_index.rb', line 32

def bulk_add(_)
  fail NotImplementedError
end

#update_from_activity(activity) ⇒ Object

Shim that determines, for a particular type of index, which strategy to use, adding a single document, or adding them in bulk. Intended to be overridden as necessary.

See Also:



43
44
45
# File 'lib/krikri/search_index.rb', line 43

def update_from_activity(activity)
  incremental_update_from_activity(activity)
end