search-kit 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/config/locales/en.yml +112 -3
  4. data/lib/search_kit.rb +5 -6
  5. data/lib/search_kit/cli.rb +45 -10
  6. data/lib/search_kit/cli/documents.rb +75 -0
  7. data/lib/search_kit/cli/events.rb +88 -0
  8. data/lib/search_kit/cli/indices.rb +96 -0
  9. data/lib/search_kit/cli/search.rb +60 -0
  10. data/lib/search_kit/cli/subscribers.rb +45 -0
  11. data/lib/search_kit/clients.rb +12 -0
  12. data/lib/search_kit/clients/documents.rb +71 -0
  13. data/lib/search_kit/clients/events.rb +77 -0
  14. data/lib/search_kit/clients/indices.rb +70 -0
  15. data/lib/search_kit/clients/keys.rb +78 -0
  16. data/lib/search_kit/clients/populate.rb +72 -0
  17. data/lib/search_kit/clients/scaffold.rb +36 -0
  18. data/lib/search_kit/clients/search.rb +33 -0
  19. data/lib/search_kit/clients/subscribers.rb +54 -0
  20. data/lib/search_kit/configuration.rb +0 -1
  21. data/lib/search_kit/errors.rb +4 -1
  22. data/lib/search_kit/messages.rb +41 -0
  23. data/lib/search_kit/messages/messaging.rb +64 -0
  24. data/lib/search_kit/models.rb +14 -0
  25. data/lib/search_kit/models/document.rb +30 -0
  26. data/lib/search_kit/models/documents.rb +31 -0
  27. data/lib/search_kit/models/event.rb +18 -0
  28. data/lib/search_kit/models/events.rb +31 -0
  29. data/lib/search_kit/models/key.rb +26 -0
  30. data/lib/search_kit/models/keys.rb +38 -0
  31. data/lib/search_kit/models/search.rb +17 -0
  32. data/lib/search_kit/models/subscriber.rb +26 -0
  33. data/lib/search_kit/polling.rb +30 -0
  34. data/lib/search_kit/polling/process.rb +40 -0
  35. data/lib/search_kit/thor.rb +12 -0
  36. data/lib/search_kit/version.rb +1 -1
  37. data/search-kit.gemspec +2 -0
  38. metadata +58 -20
  39. data/lib/search_kit/documents.rb +0 -59
  40. data/lib/search_kit/documents/cli.rb +0 -70
  41. data/lib/search_kit/events.rb +0 -59
  42. data/lib/search_kit/events/cli.rb +0 -52
  43. data/lib/search_kit/events/cli/complete.rb +0 -34
  44. data/lib/search_kit/events/cli/list.rb +0 -48
  45. data/lib/search_kit/events/cli/pending.rb +0 -48
  46. data/lib/search_kit/events/cli/publish.rb +0 -42
  47. data/lib/search_kit/events/cli/status.rb +0 -43
  48. data/lib/search_kit/events/poll.rb +0 -32
  49. data/lib/search_kit/events/poll/process.rb +0 -42
  50. data/lib/search_kit/events/publish.rb +0 -48
  51. data/lib/search_kit/indices.rb +0 -58
  52. data/lib/search_kit/indices/cli.rb +0 -65
  53. data/lib/search_kit/messaging.rb +0 -44
  54. data/lib/search_kit/search.rb +0 -30
  55. data/lib/search_kit/search/cli.rb +0 -49
  56. data/lib/search_kit/search/cli/actions.rb +0 -104
@@ -1,65 +0,0 @@
1
- require 'thor'
2
-
3
- module SearchKit
4
- class Indices
5
- class CLI < Thor
6
- include Messaging
7
-
8
- namespace :indices
9
-
10
- desc "show slug", "View an index"
11
- def show(slug)
12
- response = client.show(slug)
13
- info response.to_json
14
- rescue Errors::IndexNotFound
15
- warning "No index for that slug found"
16
- rescue Faraday::ConnectionFailed
17
- warning "No running service found"
18
- end
19
-
20
- desc "create NAME", "Create an index"
21
- def create(name)
22
- response = client.create(name)
23
- info response.to_json
24
- rescue Errors::BadRequest
25
- warning "Bad create request"
26
- rescue Errors::Unprocessable
27
- warning "Options given unprocessable"
28
- rescue Faraday::ConnectionFailed
29
- warning "No running service found"
30
- end
31
-
32
- desc "update SLUG", "Update an index"
33
- option :name
34
- def update(slug)
35
- response = client.update(slug, options)
36
- info response.to_json
37
- rescue Errors::BadRequest
38
- warning "Bad update request"
39
- rescue Errors::IndexNotFound
40
- warning "No index for that slug found"
41
- rescue Errors::Unprocessable
42
- warning "Options given unprocessable"
43
- rescue Faraday::ConnectionFailed
44
- warning "No running service found"
45
- end
46
-
47
- desc "archive SLUG", "Archive an index"
48
- def archive(slug)
49
- response = client.delete(slug)
50
- info response.to_json
51
- rescue Errors::IndexNotFound
52
- warning "No index for that slug found"
53
- rescue Faraday::ConnectionFailed
54
- warning "No running service found"
55
- end
56
-
57
- private
58
-
59
- def client
60
- @client ||= Indices.new
61
- end
62
-
63
- end
64
- end
65
- end
@@ -1,44 +0,0 @@
1
- require 'ansi'
2
-
3
- module SearchKit
4
- # The goal of the Messaging module is to provide an easy to include internal
5
- # interface which will allow a SearchKit gem to dutifully log and provide
6
- # output of what it's up to and how it may be doing.
7
- #
8
- module Messaging
9
- def info(message)
10
- Message.new(message).info
11
- end
12
-
13
- def warning(message)
14
- Message.new(message).warn
15
- end
16
-
17
- private
18
-
19
- # Most of the logic for the Messaging module exists in this (not so)
20
- # private class. This lets more complex handling of message logic enter
21
- # into the module gracefully, for example silence or logging level.
22
- #
23
- class Message
24
- attr_reader :env, :feedback, :message
25
-
26
- def initialize(message)
27
- @env = SearchKit.config.app_env.to_s.ansi(:magenta)
28
- @feedback = SearchKit.config.verbose
29
- @message = message
30
- end
31
-
32
- def warn
33
- Kernel.warn("--> [ #{env} ]: #{message.ansi(:red)}") if feedback
34
- SearchKit.logger.warn message
35
- end
36
-
37
- def info
38
- Kernel.puts("--> [ #{env} ]: #{message.ansi(:cyan)}") if feedback
39
- SearchKit.logger.info message
40
- end
41
- end
42
-
43
- end
44
- end
@@ -1,30 +0,0 @@
1
- require 'faraday'
2
- require 'json'
3
- require 'uri'
4
-
5
- module SearchKit
6
- class Search
7
- autoload :CLI, 'search_kit/search/cli'
8
-
9
- attr_reader :connection
10
-
11
- def initialize
12
- uri = [SearchKit.config.app_uri, "search"].join("/")
13
- @connection = Faraday.new(uri)
14
- end
15
-
16
- def search(slug, options)
17
- params = { data: { type: "searches", attributes: options } }
18
- response = connection.post(slug, params)
19
-
20
- body = JSON.parse(response.body, symbolize_names: true)
21
-
22
- fail Errors::BadRequest if response.status == 400
23
- fail Errors::IndexNotFound if response.status == 404
24
- fail Errors::Unprocessable if response.status == 422
25
-
26
- body
27
- end
28
-
29
- end
30
- end
@@ -1,49 +0,0 @@
1
- require 'thor'
2
-
3
- module SearchKit
4
- class Search
5
- class CLI < Thor
6
- autoload :Actions, 'search_kit/search/cli/actions'
7
-
8
- include Messaging
9
-
10
- namespace :search
11
-
12
- desc "search SLUG PHRASE", "Search an index".ansi(:cyan, :bold)
13
- option :filters, aliases: ['-f'], type: :hash, required: false
14
- option :display, aliases: ['-d'], type: :array, required: false
15
- def search(slug, phrase)
16
- search = Actions::Search.perform(
17
- client: client,
18
- phrase: phrase,
19
- slug: slug
20
- )
21
-
22
- info "Searching `#{slug}` for titles matching `#{phrase}`:"
23
- info " - Found #{search.results} titles in #{search.time}ms"
24
-
25
- display = options.fetch('display', [])
26
-
27
- search.documents.each do |document|
28
- if display.any?
29
- fields = display.map { |field| document.get(field) }
30
- info " -- #{fields.join(' | ')} | score: #{document.score}"
31
- else
32
- info " -- #{document.id} | score: #{document.score}"
33
- end
34
- end
35
- end
36
-
37
- no_commands do
38
- alias_method :s, :search
39
- end
40
-
41
- private
42
-
43
- def client
44
- @client ||= Client.new
45
- end
46
-
47
- end
48
- end
49
- end
@@ -1,104 +0,0 @@
1
- require 'thor'
2
-
3
- module SearchKit
4
- class Search
5
- class CLI < Thor
6
- module Actions
7
- class Search
8
- def self.perform(options = {})
9
- new(options).perform
10
- end
11
-
12
- include Messaging
13
-
14
- attr_reader :client, :slug, :phrase
15
-
16
- def initialize(options = {})
17
- @client = options.fetch(:client)
18
- @slug = options.fetch(:slug)
19
- @phrase = options.fetch(:phrase, nil)
20
- end
21
-
22
- def perform
23
- SearchResult.new(search_response)
24
- rescue Errors::IndexNotFound
25
- warning "No resource for `#{slug}` found"
26
- rescue Errors::BadRequest
27
- warning "Some request parameters were not supplied"
28
- rescue Errors::Unprocessable
29
- warning "Search request unprocessable"
30
- rescue Faraday::ConnectionFailed
31
- warning "No running service found"
32
- end
33
-
34
- private
35
-
36
- def search_response
37
- client.search(slug, phrase: phrase)
38
- end
39
-
40
- class SearchResult
41
- attr_reader :attributes
42
-
43
- def initialize(response)
44
- @attributes = response.fetch(:data, {}).fetch(:attributes, {})
45
- end
46
-
47
- def documents
48
- list = attributes.fetch(:documents, [])
49
- Documents.new(list)
50
- end
51
-
52
- def time
53
- attributes.fetch(:time)
54
- end
55
-
56
- def results
57
- attributes.fetch(:results)
58
- end
59
-
60
- class Documents
61
- class Document
62
- class AttributeNotFound < StandardError; end
63
-
64
- attr_reader :attributes
65
-
66
- def initialize(document_data)
67
- @attributes = document_data.fetch(:attributes, {})
68
- end
69
-
70
- def id
71
- get(:id)
72
- end
73
-
74
- def get(field)
75
- attributes.fetch(field.to_sym)
76
- rescue KeyError
77
- fail AttributeNotFound, field
78
- end
79
-
80
- def score
81
- get(:score)
82
- end
83
- end
84
-
85
- include Enumerable
86
-
87
- attr_reader :contents
88
-
89
- def initialize(raw_list = [])
90
- @contents = raw_list.map { |item| Document.new(item) }
91
- end
92
-
93
- def each(&block)
94
- contents.each(&block)
95
- end
96
- end
97
-
98
- end
99
-
100
- end
101
- end
102
- end
103
- end
104
- end