nazrin 2.3.0 → 2.4.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
  SHA1:
3
- metadata.gz: 829ff9333c9acd832dcae6a046365f571967cff5
4
- data.tar.gz: 7f4038757c2fdbed6101f850a02f9113bfb51b86
3
+ metadata.gz: f98b0576f7417a5acab58c60adf492414ce08a2e
4
+ data.tar.gz: c745e6f9830896c0fdf08206e83fa9b9ce7a3e04
5
5
  SHA512:
6
- metadata.gz: dabb967d2fdad132f213ced5ad1d1a99e3a88013293155a08b3f0ccf00036c61b83447da27d5a5e18c61cd201930e1001178e53b4d9ba8b371c054f27654a01a
7
- data.tar.gz: 347aed59409a42e2a9ab253eaa1ffb21e461acb04b98782896e91193f65a3c966c322cd36af5f3e5416daea43f28254360525bd60b5b34272e15c7687dfb0273
6
+ metadata.gz: 68875e9dde8ec03648a17add6d131b7ca2093150ddade67cfe6c246f30154d9eb17ee558ae5629b0dc629d89d959f270921b0e2eda9c51692d19322626a4cdeb
7
+ data.tar.gz: e07771ba1ed25375d58b7692026472bc1fd62c4a9a3b72a6b2293150dbc2938635df145b0d1d64971f6eda9f91b65fe36dc3d097549b0ea90a9fc9e352b20eef
@@ -1,3 +1,17 @@
1
+ ## [2.4.0](https://github.com/tsuwatch/nazrin/compare/v2.3.0...v2.4.0)
2
+
3
+ ### Features:
4
+
5
+ * Support multile domains [#23](https://github.com/tsuwatch/nazrin/pull/23) - [@totem3](https://github.com/totem3)
6
+
7
+ * Allow logger setting of Aws::CloudSearchDomain::Client [#24](https://github.com/tsuwatch/nazrin/pull/24) - [@AMHOL](https://github.com/AMHOL)
8
+
9
+ ## [2.3.0](https://github.com/tsuwatch/nazrin/compare/v2.2.0...v2.3.0)
10
+
11
+ ### Features:
12
+
13
+ * Dropped support for `aws-sdk` v2 [#22](https://github.com/tsuwatch/nazrin/pull/22)
14
+
1
15
  ## [2.2.0](https://github.com/tsuwatch/nazrin/compare/v2.1.2...v2.2.0)
2
16
 
3
17
  ### Breaking changes:
data/README.md CHANGED
@@ -39,6 +39,7 @@ Nazrin.configure do |config|
39
39
  config.region = ''
40
40
  config.access_key_id = ''
41
41
  config.secret_access_key = ''
42
+ config.logger = nil
42
43
  end
43
44
  ```
44
45
 
@@ -46,6 +47,12 @@ end
46
47
  class Post < ActiveRecord::Base
47
48
  include Nazrin::Searchable
48
49
 
50
+ # You can override settings
51
+ searchable_configure do |config|
52
+ config.search_endpoint = 'http://example.com/override-search-endpoint'
53
+ config.document_endpoint = 'http://example.com/override-document-endpoint'
54
+ end
55
+
49
56
  searchable do
50
57
  fields [:content]
51
58
  field(:created_at) { created_at.utc.iso8601 }
@@ -1,6 +1,7 @@
1
1
  require 'aws-sdk-cloudsearchdomain'
2
2
 
3
3
  require 'nazrin/searchable'
4
+ require 'nazrin/searchable/config'
4
5
  require 'nazrin/data_accessor'
5
6
  require 'nazrin/config'
6
7
  require 'nazrin/search_client'
@@ -18,5 +18,6 @@ module Nazrin
18
18
  config_accessor :region
19
19
  config_accessor :access_key_id
20
20
  config_accessor :secret_access_key
21
+ config_accessor :logger
21
22
  end
22
23
  end
@@ -2,12 +2,13 @@ module Nazrin
2
2
  class DocumentClient
3
3
  attr_reader :client
4
4
 
5
- def initialize
5
+ def initialize(config=Nazrin.config)
6
6
  @client = Aws::CloudSearchDomain::Client.new(
7
- endpoint: Nazrin.config.document_endpoint,
8
- region: Nazrin.config.region,
9
- access_key_id: Nazrin.config.access_key_id,
10
- secret_access_key: Nazrin.config.secret_access_key)
7
+ endpoint: config.document_endpoint,
8
+ region: config.region,
9
+ access_key_id: config.access_key_id,
10
+ secret_access_key: config.secret_access_key,
11
+ logger: config.logger)
11
12
  end
12
13
 
13
14
  def add_document(id, field_data)
@@ -5,113 +5,115 @@ module Nazrin
5
5
  CLOUD_SEARCH_MAX_LIMIT = 10_000
6
6
 
7
7
  attr_accessor :data_accessor
8
+ attr_reader :client
8
9
  attr_reader :parameters
9
10
 
10
- def initialize
11
+ def initialize(config=Nazrin.config)
11
12
  # @see http://docs.aws.amazon.com/sdkforruby/api/Aws/CloudSearchDomain/Client.html aws-sdk
12
13
  @client = Aws::CloudSearchDomain::Client.new(
13
- endpoint: Nazrin.config.search_endpoint,
14
- region: Nazrin.config.region,
15
- access_key_id: Nazrin.config.access_key_id,
16
- secret_access_key: Nazrin.config.secret_access_key)
14
+ endpoint: config.search_endpoint,
15
+ region: config.region,
16
+ access_key_id: config.access_key_id,
17
+ secret_access_key: config.secret_access_key,
18
+ logger: config.logger)
17
19
  @parameters = {}
18
20
  end
19
21
 
20
22
  # query
21
23
  # @param [String] query query string
22
24
  def query(query)
23
- @parameters[:query] = query
25
+ parameters[:query] = query
24
26
  self
25
27
  end
26
28
 
27
29
  # return fields
28
30
  # @param [Array<String>] fields ex) ['title']
29
31
  def return(fields)
30
- @parameters[:return] = fields.join(',')
32
+ parameters[:return] = fields.join(',')
31
33
  self
32
34
  end
33
35
 
34
36
  # set the number to get
35
37
  # @param [Integer] size the number to get
36
38
  def size(size)
37
- @parameters[:size] = size
39
+ parameters[:size] = size
38
40
  self
39
41
  end
40
42
 
41
43
  # set the parser to be used
42
44
  # @param [String] parser 'simple', 'structured', 'lucene', dismax'
43
45
  def query_parser(query_parser)
44
- @parameters[:query_parser] = query_parser
46
+ parameters[:query_parser] = query_parser
45
47
  self
46
48
  end
47
49
 
48
50
  # set the search start position
49
51
  # @param [Integer] start start position
50
52
  def start(start)
51
- @parameters[:start] = start
53
+ parameters[:start] = start
52
54
  self
53
55
  end
54
56
 
55
57
  # set the cursor
56
58
  # @param [String] cursor cursor
57
59
  def cursor(cursor)
58
- @parameters[:cursor] = cursor
60
+ parameters[:cursor] = cursor
59
61
  self
60
62
  end
61
63
 
62
64
  # sort
63
65
  # @param [Array<String>] sorts ex) ['year desc']
64
66
  def sort(sorts)
65
- @parameters[:sort] = sorts.join(',')
67
+ parameters[:sort] = sorts.join(',')
66
68
  self
67
69
  end
68
70
 
69
71
  # partial
70
72
  # @param [Boolean] partial true or false
71
73
  def partial(partial)
72
- @parameters[:partial] = partial
74
+ parameters[:partial] = partial
73
75
  self
74
76
  end
75
77
 
76
78
  # query filtering
77
79
  # @param [String] filter_query "tags:'aaa'"
78
80
  def filter_query(filter_query)
79
- @parameters[:filter_query] = filter_query
81
+ parameters[:filter_query] = filter_query
80
82
  self
81
83
  end
82
84
 
83
85
  # query options
84
86
  # @param [String] query_options ex) target field "{fields:['title']}"
85
87
  def query_options(query_options)
86
- @parameters[:query_options] = query_options
88
+ parameters[:query_options] = query_options
87
89
  self
88
90
  end
89
91
 
90
92
  # highlight
91
93
  # @param [String] highlight "{'tags':{}}"
92
94
  def highlight(highlight)
93
- @parameters[:highlight] = highlight
95
+ parameters[:highlight] = highlight
94
96
  self
95
97
  end
96
98
 
97
99
  # facet
98
100
  # @param [String] facet ex) "{'year':{'sort':'bucket'}}"
99
101
  def facet(facet)
100
- @parameters[:facet] = facet
102
+ parameters[:facet] = facet
101
103
  self
102
104
  end
103
105
 
104
106
  # define any expression
105
107
  # @param [String] expr ex) "{'EXPRESSIONNAME':'EXPRESSION'}"
106
108
  def expr(expr)
107
- @parameters[:expr] = expr
109
+ parameters[:expr] = expr
108
110
  self
109
111
  end
110
112
 
111
113
  def search
112
114
  return fake_response if Nazrin.config.mode == 'sandbox'
113
115
  fail SearchClientError if deep_page?
114
- @client.search(@parameters)
116
+ client.search(parameters)
115
117
  end
116
118
 
117
119
  def execute
@@ -29,11 +29,12 @@ module Nazrin
29
29
  alias_method :searchable, :nazrin_searchable unless method_defined? :searchable
30
30
  alias_method :fields, :nazrin_fields unless method_defined? :fields
31
31
  alias_method :field, :nazrin_field unless method_defined? :field
32
+ alias_method :searchable_configure, :nazrin_searchable_configure unless method_defined? :searchable_configure
32
33
  end
33
34
  end
34
35
 
35
36
  def nazrin_search(options = {})
36
- client = Nazrin::SearchClient.new
37
+ client = Nazrin::SearchClient.new(nazrin_searchable_config)
37
38
  client.data_accessor = Nazrin::DataAccessor.for(self).new(self, options)
38
39
  client
39
40
  end
@@ -41,7 +42,7 @@ module Nazrin
41
42
  def nazrin_searchable(&block)
42
43
  class_variable_set(
43
44
  :@@nazrin_doc_client,
44
- Nazrin::DocumentClient.new)
45
+ Nazrin::DocumentClient.new(nazrin_searchable_config))
45
46
  class_variable_set(:@@nazrin_search_field_data, {})
46
47
  block.call
47
48
  end
@@ -87,6 +88,14 @@ module Nazrin
87
88
  def nazrin_delete_document(obj)
88
89
  nazrin_doc_client.delete_document(obj.send(:id))
89
90
  end
91
+
92
+ def nazrin_searchable_config
93
+ @nazrin_searchable_config ||= Nazrin::Searchable::Configuration.new
94
+ end
95
+
96
+ def nazrin_searchable_configure
97
+ yield nazrin_searchable_config
98
+ end
90
99
  end
91
100
  end
92
101
  end
@@ -0,0 +1,24 @@
1
+ module Nazrin
2
+ module Searchable
3
+ class Configuration
4
+ %i(
5
+ search_endpoint
6
+ document_endpoint
7
+ region
8
+ access_key_id
9
+ secret_access_key
10
+ logger
11
+ ).each do |attr|
12
+ class_eval <<-CODE, __FILE__, __LINE__ + 1
13
+ def #{attr}
14
+ @#{attr} || Nazrin.config.#{attr}
15
+ end
16
+
17
+ def #{attr}=(v)
18
+ @#{attr} = v
19
+ end
20
+ CODE
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Nazrin
2
- VERSION = '2.3.0'
2
+ VERSION = '2.4.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nazrin
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomohiro Suwa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-15 00:00:00.000000000 Z
11
+ date: 2018-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-core
@@ -207,6 +207,7 @@ files:
207
207
  - lib/nazrin/pagination_generator.rb
208
208
  - lib/nazrin/search_client.rb
209
209
  - lib/nazrin/searchable.rb
210
+ - lib/nazrin/searchable/config.rb
210
211
  - lib/nazrin/version.rb
211
212
  - nazrin.gemspec
212
213
  homepage: https://github.com/tsuwatch/nazrin