dina 0.4.0.0 → 0.4.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4cae0ee74ed1a0967bb360af211c2ab37676dfdb39b54a377ec39b539e0f4301
4
- data.tar.gz: 45ee9d1cda7f37da9fb5384690751dac5e5cc0fe30153cddf8306e11a20f7151
3
+ metadata.gz: 22dfd46dbbd51273c78e8b7375019e89cc503b13af20cf9abd17961c68809a56
4
+ data.tar.gz: f757ac80f3722120a738c40eae3bef2826ec8e3aac48af0645a94e34c091e1b7
5
5
  SHA512:
6
- metadata.gz: 60a62ece7262ab086b88002497bd55f1ea04059b94468134b7c93d35a3349deff0c3ed58c45f634dd07a3149e4895da1525c215aef1895258beb62cf5af0aba5
7
- data.tar.gz: dba63bace34688530c56cb56af702af39fe36bcb7ba86bf664b1192a7186ca51207ef9cef2deed311993671127772deb4f149f99fd90619ad56408dc379882a7
6
+ metadata.gz: 9a72ed340fed58472d60fe7b6c47e7e3fe339378d076c4636f53cb0d32d402b0e8a408c5123bcb79683824bcb6d3d9e55ca9f308d6bbaf820fd88769b8bf4db1
7
+ data.tar.gz: 98c98900dcfeeeb17ac1bad224c99ff80d56a060cf9096af16b4eb48e44584617eeaa82d2b4d7e29817256698ee36272c37d3cc65652b4e6b275e9caf91f7c65
@@ -35,6 +35,26 @@ module Dina
35
35
  where("email": email).all
36
36
  end
37
37
 
38
+ def self.search_by_name(name)
39
+ payload = {
40
+ query: {
41
+ multi_match: {
42
+ query: name,
43
+ type: :cross_fields,
44
+ fields: [
45
+ "data.attributes.familyNames^3",
46
+ "data.attributes.givenNames",
47
+ "data.attributes.displayName^5",
48
+ "data.attributes.aliases",
49
+ "data.attributes.displayName.autocomplete"
50
+ ]
51
+ }
52
+ }
53
+ }
54
+ hits = Dina::Search.execute(index: "agent", payload: payload)[:hits]
55
+ hits.map{|a| self.find(a[:_source][:data][:id]).first }
56
+ end
57
+
38
58
  private
39
59
 
40
60
  def on_before_save
@@ -2,26 +2,42 @@ module Dina
2
2
  class BaseSearch
3
3
 
4
4
  def self.endpoint
5
- Settings.server.endpoint
5
+ Dina::Authentication.endpoint_url
6
6
  end
7
7
 
8
8
  def self.endpoint_path
9
9
  "search-api/search-ws/"
10
10
  end
11
11
 
12
+ # Sets the search index name
13
+ #
14
+ # @param index [String] the search index; options are "agent", "material_sample", "object_store"
15
+ #
16
+ # @return [String] the internally-recognized search index name
12
17
  def self.index_name(index:)
13
18
  return nil if !index
14
19
  "dina_#{index}_index"
15
20
  end
16
21
 
22
+ # Executes a search
23
+ #
24
+ # @param params [Hash] the parameters to be included in the endpoint URL
25
+ # @param method [Symbol] the request type as :get or :post
26
+ # @param payload [Hash] the elasticsearch query
27
+ #
28
+ # @return [Hash] the search response with symbolized keys
17
29
  def self.execute(params, method: :get, payload: {})
18
30
  begin
19
31
  response = RestClient::Request.execute(
20
- method: method,
21
- url: endpoint + endpoint_path + "?" + params.to_query,
22
- payload: payload.to_json,
23
- headers: { accept: 'application/json', content_type: 'application/json' }
24
- )
32
+ method: method,
33
+ url: endpoint + endpoint_path + "?" + params.to_query,
34
+ payload: payload.to_json,
35
+ headers: {
36
+ accept: 'application/json',
37
+ content_type: 'application/json',
38
+ authorization: Dina::Authentication.header
39
+ }
40
+ )
25
41
  JSON.parse(response, symbolize_names: true)
26
42
  rescue RestClient::ExceptionWithResponse => e
27
43
  e.response
@@ -7,8 +7,13 @@ module Dina
7
7
  "search-api/search-ws/search"
8
8
  end
9
9
 
10
- # index values: "agent", "material_sample", "object_store"
11
- # payload is a hash in the form of an Elasticsearch body
10
+ # Executes a search
11
+ #
12
+ # @param index [String] the index, accepted value is one of "agent", "material_sample", "object_store"
13
+ # @param payload [Hash] the payload hash as an Elasticsearch-formatted body
14
+ # => { query: { match_all: {} }
15
+ #
16
+ # @return [Hash] the search result with symbolized keys
12
17
  def self.execute(index:, payload: { query: { match_all: {} } })
13
18
  params = {
14
19
  indexName: index_name(index: index)
@@ -7,11 +7,19 @@ module Dina
7
7
  "search-api/search-ws/auto-complete"
8
8
  end
9
9
 
10
- # index values: "agent", "material_sample", "object_store"
11
- # known autocomplete fields:
10
+ # Executes an autocomplete search
11
+ #
12
+ # Known field values (dependent on chosen index):
12
13
  # agent: data.attributes.displayName
13
14
  # material_sample: included.attributes.dwcRecordedBy, included.attributes.verbatimDeterminer
14
15
  # object_store: none
16
+ #
17
+ # @param term [String] the search term
18
+ # @param index [String] the index, accepted value is one of "agent", "material_sample", "object_store"
19
+ # @param field [String]
20
+ # @param group [String] the DINA group name
21
+ #
22
+ # @return [Hash] the search result with symbolized keys
15
23
  def self.execute(term:, index:, field: nil, group: nil)
16
24
  params = {
17
25
  prefix: term,
@@ -7,9 +7,14 @@ module Dina
7
7
  "search-api/search-ws/count"
8
8
  end
9
9
 
10
- # index values: "agent", "material_sample", "object_store"
11
- # Payload is a has like: {query: {bool: {filter: {term: {"data.attributes.group": "dao"}}}}}
12
- def self.execute(index:, payload: {})
10
+ # Executes an count search
11
+ #
12
+ # @param index [String] the index, accepted value is one of "agent", "material_sample", "object_store"
13
+ # @param payload [Hash] the Elasticsearch query hash
14
+ # => Example: {query: {bool: {filter: {term: {"data.attributes.group": "dao"}}}}}
15
+ #
16
+ # @return [Integer] the count of items in the index according to the query/filter
17
+ def self.execute(index:, payload: { query: { match_all: {} }})
13
18
  params = {
14
19
  indexName: index_name(index: index)
15
20
  }
@@ -7,7 +7,11 @@ module Dina
7
7
  "search-api/search-ws/mapping"
8
8
  end
9
9
 
10
- # index values: "agent", "material_sample", "object_store"
10
+ # Return the search mapping document
11
+ #
12
+ # @param index [String] the index, accepted value is one of "agent", "material_sample", "object_store"
13
+ #
14
+ # @return [Hash] the mapping document as a hash with symbolized keys
11
15
  def self.execute(index:)
12
16
  params = {
13
17
  indexName: index_name(index: index)
data/lib/dina/version.rb CHANGED
@@ -3,7 +3,7 @@ module Dina
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 4
6
- PATCH = 0
6
+ PATCH = 1
7
7
  BUILD = 0
8
8
 
9
9
  def self.version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dina
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.0
4
+ version: 0.4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David P. Shorthouse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-30 00:00:00.000000000 Z
11
+ date: 2022-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_api_client
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rest-client
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.1.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.1.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rake
71
85
  requirement: !ruby/object:Gem::Requirement