Class: Dina::BaseSearch

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/dina/search/base_search.rb

Direct Known Subclasses

Search, SearchAutocomplete, SearchCount, SearchMapping

Class Method Summary collapse

Methods inherited from BaseModel

custom_headers, find_by_group, #initialize, properties, site

Constructor Details

This class inherits a constructor from Dina::BaseModel

Class Method Details

.endpointObject



12
13
14
# File 'lib/dina/search/base_search.rb', line 12

def self.endpoint
  Dina.config.endpoint_url
end

.endpoint_pathObject



16
17
18
# File 'lib/dina/search/base_search.rb', line 16

def self.endpoint_path
  "search-api/search-ws/"
end

.execute(params, method: :get, payload: {}) ⇒ Hash

Executes a search

Parameters:

  • params (Hash)

    the parameters to be included in the endpoint URL

  • method (Symbol) (defaults to: :get)

    the request type as :get or :post

  • payload (Hash) (defaults to: {})

    the elasticsearch query

Returns:

  • (Hash)

    the search response with symbolized keys



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dina/search/base_search.rb', line 37

def self.execute(params, method: :get, payload: {})
  begin
    response = RestClient::Request.execute(
      method: method,
      url: endpoint + "/" + endpoint_path + "?" + params.to_query,
      payload: payload.to_json,
      headers: {
        accept: 'application/json',
        content_type: 'application/json',
        authorization: Dina.header
      },
      verify_ssl: verify_ssl
    )
    JSON.parse(response, symbolize_names: true)
  rescue RestClient::ExceptionWithResponse => e
    e.response
  end
end

.index_name(index:) ⇒ String

Sets the search index name

Parameters:

  • index (String)

    the search index; options are “agent”, “material_sample”, “object_store”

Returns:

  • (String)

    the internally-recognized search index name



25
26
27
28
# File 'lib/dina/search/base_search.rb', line 25

def self.index_name(index:)
  return nil if !index
  "dina_#{index}_index"
end

.verify_sslObject



4
5
6
7
8
9
10
# File 'lib/dina/search/base_search.rb', line 4

def self.verify_ssl
  begin
    connection_options[:ssl][:verify]
  rescue
    true
  end
end