nazrin 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +12 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +76 -0
- data/Rakefile +5 -0
- data/lib/generators/nazrin/config_generator.rb +13 -0
- data/lib/generators/nazrin/templates/nazrin_config.rb +10 -0
- data/lib/nazrin.rb +10 -0
- data/lib/nazrin/active_record/data_accessor.rb +98 -0
- data/lib/nazrin/active_record/searchable.rb +93 -0
- data/lib/nazrin/config.rb +22 -0
- data/lib/nazrin/document_client.rb +38 -0
- data/lib/nazrin/paginated_array.rb +63 -0
- data/lib/nazrin/search_client.rb +118 -0
- data/lib/nazrin/version.rb +3 -0
- data/nazrin.gemspec +31 -0
- metadata +203 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6d03528ffd79f464894276ab31d21064a1b5a520
|
4
|
+
data.tar.gz: 642b162721c1ce29d9dc0740f07561a68903d94c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4b63c8362a8abe722710d0457d0e05be037914b81815f1806cfef6fe81a218194ce983563fafa8cf57feb6809ef119b79b5905b9af3db71905f9810f41054d7e
|
7
|
+
data.tar.gz: c4d54360ba11ba6cb82491834781295cf9412967de7aa0f2a8d8fea17ca44e1a98851d3441355898231ca52b8089f81a90b8802821b527cfbc35ba255f8eef44
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Tomohiro Suwa
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# Nazrin
|
2
|
+
[](https://travis-ci.org/tsuwatch/nazrin)
|
3
|
+
[](https://coveralls.io/github/tsuwatch/nazrin?branch=readme)
|
4
|
+
[](https://codeclimate.com/github/tsuwatch/nazrin)
|
5
|
+
|
6
|
+
Nazrin is a Ruby wrapper for Amazon CloudSearch, with optional ActiveRecord support for easy integration with your Rails application.
|
7
|
+
|
8
|
+
*Nazrin has the ability of the extent which find what you're looking for...*
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'nazrin'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install nazrin
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
### in Ruby on Rails
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
$ bundle exec rails g nazrin:config
|
32
|
+
|
33
|
+
Nazrin.config do |config|
|
34
|
+
config.debug_mode = false
|
35
|
+
config.search_endpoint = ''
|
36
|
+
config.document_endpoint = ''
|
37
|
+
config.region = ''
|
38
|
+
config.access_key_id = ''
|
39
|
+
config.secret_access_key = ''
|
40
|
+
# currently support kaminari gem
|
41
|
+
config.pagination = 'kaminari'
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
class Post
|
47
|
+
include Nazrin::ActiveRecord::Searchable
|
48
|
+
|
49
|
+
searchable do
|
50
|
+
fields [:content]
|
51
|
+
field(:created_at) { created_at.utc.iso8601 }
|
52
|
+
end
|
53
|
+
|
54
|
+
after_create :update_in_index
|
55
|
+
after_destroy :delete_from_index
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
Post.search.size(1).start(0).query("(and 'content')").query_parser('structured').execute
|
61
|
+
=> [#<Post id: 1, content: "content">]
|
62
|
+
```
|
63
|
+
|
64
|
+
## Development
|
65
|
+
|
66
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
67
|
+
|
68
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
1. Fork it ( https://github.com/[my-github-username]/nazrin/fork )
|
73
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
74
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
75
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
76
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Nazrin
|
2
|
+
module Generators
|
3
|
+
class ConfigGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path(
|
5
|
+
File.join(File.dirname(__FILE__), 'templates'))
|
6
|
+
desc 'Generate config'
|
7
|
+
|
8
|
+
def config
|
9
|
+
template 'nazrin_config.rb', 'config/initializers/nazrin_config.rb'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Nazrin.configure do |config|
|
2
|
+
config.debug_mode = false
|
3
|
+
config.search_endpoint = ''
|
4
|
+
config.document_endpoint = ''
|
5
|
+
config.region = ''
|
6
|
+
config.access_key_id = ''
|
7
|
+
config.secret_access_key = ''
|
8
|
+
# currently support kaminari
|
9
|
+
# config.pagination = 'kaminari'
|
10
|
+
end
|
data/lib/nazrin.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
module Nazrin
|
2
|
+
end
|
3
|
+
|
4
|
+
require 'nazrin/active_record/searchable'
|
5
|
+
require 'nazrin/active_record/data_accessor'
|
6
|
+
require 'nazrin/config'
|
7
|
+
require 'nazrin/search_client'
|
8
|
+
require 'nazrin/document_client'
|
9
|
+
require 'nazrin/paginated_array'
|
10
|
+
require 'nazrin/version'
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Nazrin
|
2
|
+
module ActiveRecord
|
3
|
+
class DataAccessor
|
4
|
+
MAX_LIMIT = 10_000
|
5
|
+
|
6
|
+
def initialize(model, options)
|
7
|
+
@model = model
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
# a list of all matching AR model objects
|
12
|
+
def results(client)
|
13
|
+
@client = client
|
14
|
+
|
15
|
+
res = @client.search
|
16
|
+
collections = load_all(res.data.hits.hit.map(&:id))
|
17
|
+
if @client.parameters[:size] && @client.parameters[:start]
|
18
|
+
round_correct_page
|
19
|
+
|
20
|
+
Nazrin.paginated_array(
|
21
|
+
collections,
|
22
|
+
current_page: @current_page,
|
23
|
+
per_page: @client.parameters[:size],
|
24
|
+
total_count: res.data.hits.found,
|
25
|
+
last_page: @last_page)
|
26
|
+
else
|
27
|
+
collections
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# load from activerecord
|
32
|
+
def load_all(ids)
|
33
|
+
records_table = {}
|
34
|
+
@options.each do |k, v|
|
35
|
+
@model = @model.send(k, v)
|
36
|
+
end
|
37
|
+
@model.where(id: ids).each do |record|
|
38
|
+
records_table[record.id] = record
|
39
|
+
end
|
40
|
+
ids.map do |id|
|
41
|
+
records_table.select { |k, _| k == id.to_i }[id.to_i]
|
42
|
+
end.reject(&:nil?)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def round_correct_page
|
48
|
+
res = search_for_set_correct_page
|
49
|
+
total_count = res.data.hits.found
|
50
|
+
if over_max_limit_request?
|
51
|
+
if total_count > MAX_LIMIT
|
52
|
+
@current_page = @last_page = get_last_page(MAX_LIMIT)
|
53
|
+
else
|
54
|
+
@current_page = @last_page = get_last_page(total_count)
|
55
|
+
end
|
56
|
+
@client.start(get_start_position(@current_page))
|
57
|
+
elsif res.data.hits.found > 0 && !res.data.hits.hit.present?
|
58
|
+
@current_page = @last_page = get_last_page(total_count)
|
59
|
+
@client.start(get_start_position(@current_page))
|
60
|
+
else
|
61
|
+
@current_page = (
|
62
|
+
@client.parameters[:start] / @client.parameters[:size].to_f
|
63
|
+
).ceil + 1
|
64
|
+
@last_page = get_last_page(total_count)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def search_for_set_correct_page
|
69
|
+
if over_max_limit_request?
|
70
|
+
tmp_start = @client.parameters[:start]
|
71
|
+
res = @client.start(0).search
|
72
|
+
@client.start(tmp_start)
|
73
|
+
else
|
74
|
+
res = @client.search
|
75
|
+
end
|
76
|
+
res
|
77
|
+
end
|
78
|
+
|
79
|
+
def over_max_limit_request?
|
80
|
+
return false unless @client.parameters[:start].present?
|
81
|
+
return false unless @client.parameters[:size].present?
|
82
|
+
if @client.parameters[:start] + @client.parameters[:size] > MAX_LIMIT
|
83
|
+
true
|
84
|
+
else
|
85
|
+
false
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def get_last_page(total_count)
|
90
|
+
(total_count / @client.parameters[:size].to_f).ceil
|
91
|
+
end
|
92
|
+
|
93
|
+
def get_start_position(current_page)
|
94
|
+
(current_page - 1) * @client.parameters[:size]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Nazrin
|
2
|
+
module ActiveRecord
|
3
|
+
module Searchable
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
alias_method :delete_from_index, :nazrin_delete_from_index unless method_defined? :delete_from_index
|
8
|
+
alias_method :add_to_index, :nazrin_add_to_index unless method_defined? :add_to_index
|
9
|
+
alias_method :update_in_index, :nazrin_update_in_index unless method_defined? :update_in_index
|
10
|
+
end
|
11
|
+
|
12
|
+
def nazrin_delete_from_index
|
13
|
+
self.class.nazrin_delete_document(self)
|
14
|
+
end
|
15
|
+
|
16
|
+
def nazrin_add_to_index
|
17
|
+
self.class.nazrin_add_document(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
def nazrin_update_in_index
|
21
|
+
self.class.nazrin_update_document(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
module ClassMethods
|
25
|
+
def self.extended(base)
|
26
|
+
class << base
|
27
|
+
alias_method :search, :nazrin_search unless method_defined? :search
|
28
|
+
alias_method :searchable, :nazrin_searchable unless method_defined? :searchable
|
29
|
+
alias_method :fields, :nazrin_fields unless method_defined? :fields
|
30
|
+
alias_method :field, :nazrin_field unless method_defined? :field
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def nazrin_search(options = {})
|
35
|
+
client = Nazrin::SearchClient.new
|
36
|
+
client.data_accessor = Nazrin::ActiveRecord::DataAccessor.new(
|
37
|
+
self, options)
|
38
|
+
client
|
39
|
+
end
|
40
|
+
|
41
|
+
def nazrin_searchable(&block)
|
42
|
+
class_variable_set(
|
43
|
+
:@@nazrin_doc_client,
|
44
|
+
Nazrin::DocumentClient.new)
|
45
|
+
class_variable_set(:@@nazrin_search_field_data, {})
|
46
|
+
block.call
|
47
|
+
end
|
48
|
+
|
49
|
+
def nazrin_fields(fields)
|
50
|
+
field_data = class_variable_get(:@@nazrin_search_field_data)
|
51
|
+
fields.each do |field|
|
52
|
+
field_data[field] = proc { public_send(field) }
|
53
|
+
end
|
54
|
+
class_variable_set(:@@nazrin_search_field_data, field_data)
|
55
|
+
end
|
56
|
+
|
57
|
+
def nazrin_field(field, &block)
|
58
|
+
field_data = class_variable_get(:@@nazrin_search_field_data)
|
59
|
+
field_data[field] = block
|
60
|
+
class_variable_set(:@@nazrin_search_field_data, field_data)
|
61
|
+
end
|
62
|
+
|
63
|
+
def nazrin_doc_client
|
64
|
+
class_variable_get(:@@nazrin_doc_client)
|
65
|
+
end
|
66
|
+
|
67
|
+
def nazrin_eval_field_data(obj)
|
68
|
+
data = {}
|
69
|
+
class_variable_get(
|
70
|
+
:@@nazrin_search_field_data).each do |field, block|
|
71
|
+
data[field] = obj.instance_eval(&block)
|
72
|
+
data[field] = data[field].remove(
|
73
|
+
/[[:cntrl:]]/) if data[field].is_a?(String)
|
74
|
+
end
|
75
|
+
data
|
76
|
+
end
|
77
|
+
|
78
|
+
def nazrin_add_document(obj)
|
79
|
+
nazrin_doc_client.add_document(
|
80
|
+
obj.send(:id), nazrin_eval_field_data(obj))
|
81
|
+
end
|
82
|
+
|
83
|
+
def nazrin_update_document(obj)
|
84
|
+
nazrin_add_document(obj)
|
85
|
+
end
|
86
|
+
|
87
|
+
def nazrin_delete_document(obj)
|
88
|
+
nazrin_doc_client.delete_document(obj.send(:id))
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'active_support/configurable'
|
2
|
+
|
3
|
+
module Nazrin
|
4
|
+
def self.config
|
5
|
+
@config ||= Nazrin::Configuration.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.configure
|
9
|
+
yield config if block_given?
|
10
|
+
end
|
11
|
+
|
12
|
+
class Configuration
|
13
|
+
include ActiveSupport::Configurable
|
14
|
+
config_accessor :debug_mode
|
15
|
+
config_accessor :search_endpoint
|
16
|
+
config_accessor :document_endpoint
|
17
|
+
config_accessor :region
|
18
|
+
config_accessor :access_key_id
|
19
|
+
config_accessor :secret_access_key
|
20
|
+
config_accessor :pagination
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Nazrin
|
2
|
+
class DocumentClient
|
3
|
+
attr_reader :client
|
4
|
+
|
5
|
+
def initialize
|
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)
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_document(id, field_data)
|
14
|
+
return nil if Nazrin.config.debug_mode
|
15
|
+
client.upload_documents(
|
16
|
+
documents: [
|
17
|
+
{
|
18
|
+
type: 'add',
|
19
|
+
id: id,
|
20
|
+
fields: field_data
|
21
|
+
}
|
22
|
+
].to_json,
|
23
|
+
content_type: 'application/json')
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete_document(id)
|
27
|
+
return nil if Nazrin.config.debug_mode
|
28
|
+
client.upload_documents(
|
29
|
+
documents: [
|
30
|
+
{
|
31
|
+
type: 'delete',
|
32
|
+
id: id
|
33
|
+
}
|
34
|
+
].to_json,
|
35
|
+
content_type: 'application/json')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Nazrin
|
2
|
+
class PaginatedArray < Array
|
3
|
+
attr_reader :current_page, :per_page, :total_count
|
4
|
+
|
5
|
+
def initialize(collections, page, per_page, total_count)
|
6
|
+
@current_page = page
|
7
|
+
@per_page = per_page
|
8
|
+
@total_count = total_count
|
9
|
+
replace collections
|
10
|
+
end
|
11
|
+
|
12
|
+
# first page of the collections?
|
13
|
+
def first_page?
|
14
|
+
current_page == 1
|
15
|
+
end
|
16
|
+
|
17
|
+
# last page of the collections?
|
18
|
+
def last_page?
|
19
|
+
current_page >= total_pages
|
20
|
+
end
|
21
|
+
|
22
|
+
# total number of pages
|
23
|
+
def total_pages
|
24
|
+
(total_count.to_f / per_page).ceil
|
25
|
+
end
|
26
|
+
|
27
|
+
# previous page number in the collections
|
28
|
+
def previous_page
|
29
|
+
current_page - 1 unless first_page? || out_of_bounds?
|
30
|
+
end
|
31
|
+
|
32
|
+
# next page number in the collections
|
33
|
+
def next_page
|
34
|
+
current_page + 1 unless last_page? || out_of_bounds?
|
35
|
+
end
|
36
|
+
|
37
|
+
# out of bounds of the collections?
|
38
|
+
def out_of_bounds?
|
39
|
+
current_page > total_pages
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# create paginated collection
|
44
|
+
def self.paginated_array(collections, options = {})
|
45
|
+
if Nazrin.config.pagination == 'kaminari'
|
46
|
+
begin
|
47
|
+
require 'kaminari'
|
48
|
+
rescue LoadError
|
49
|
+
abort "Missing dependency 'kaminari' for pagination"
|
50
|
+
end
|
51
|
+
Kaminari.config.max_pages = options[:last_page]
|
52
|
+
Kaminari.paginate_array(collections, total_count: options[:total_count])
|
53
|
+
.page(options[:current_page])
|
54
|
+
.per(options[:per_page])
|
55
|
+
else
|
56
|
+
Nazrin::PaginatedArray.new(
|
57
|
+
collections,
|
58
|
+
options[:current_page],
|
59
|
+
options[:per_page],
|
60
|
+
options[:total_count])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
module Nazrin
|
2
|
+
class SearchClient
|
3
|
+
attr_accessor :data_accessor
|
4
|
+
attr_reader :parameters
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@client = Aws::CloudSearchDomain::Client.new(
|
8
|
+
endpoint: Nazrin.config.search_endpoint,
|
9
|
+
region: Nazrin.config.region,
|
10
|
+
access_key_id: Nazrin.config.access_key_id,
|
11
|
+
secret_access_key: Nazrin.config.secret_access_key)
|
12
|
+
@parameters = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
# query
|
16
|
+
# @param [String] query query string
|
17
|
+
def query(query)
|
18
|
+
@parameters[:query] = query
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
# return fields
|
23
|
+
# @param [Array<String>] fields ex) ['title']
|
24
|
+
def return(fields)
|
25
|
+
@parameters[:return] = fields.join(',')
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
# set the number to get
|
30
|
+
# @param [Integer] size the number to get
|
31
|
+
def size(size)
|
32
|
+
@parameters[:size] = size
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
# set the parser to be used
|
37
|
+
# @param [String] parser 'simple', 'structured', 'lucene', dismax'
|
38
|
+
def query_parser(query_parser)
|
39
|
+
@parameters[:query_parser] = query_parser
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
# set the search start position
|
44
|
+
# @param [Integer] start start position
|
45
|
+
def start(start)
|
46
|
+
@parameters[:start] = start
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
# set the cursor
|
51
|
+
# @param [String] cursor cursor
|
52
|
+
def cursor(cursor)
|
53
|
+
@parameters[:cursor] = cursor
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
57
|
+
# sort
|
58
|
+
# @param [Array<String>] sorts ex) ['year desc']
|
59
|
+
def sort(sorts)
|
60
|
+
@parameters[:sort] = sorts.join(',')
|
61
|
+
self
|
62
|
+
end
|
63
|
+
|
64
|
+
# partial
|
65
|
+
# @param [Boolean] partial true or false
|
66
|
+
def partial(partial)
|
67
|
+
@parameters[:partial] = partial
|
68
|
+
self
|
69
|
+
end
|
70
|
+
|
71
|
+
# query filtering
|
72
|
+
# @param [String] filter_query "tags:'aaa'"
|
73
|
+
def filter_query(filter_query)
|
74
|
+
@parameters[:filter_query] = filter_query
|
75
|
+
self
|
76
|
+
end
|
77
|
+
|
78
|
+
# query options
|
79
|
+
# @param [String] query_options ex) target field "{fields:['title']}"
|
80
|
+
def query_options(query_options)
|
81
|
+
@parameters[:query_options] = query_options
|
82
|
+
self
|
83
|
+
end
|
84
|
+
|
85
|
+
# highlight
|
86
|
+
# @param [String] highlight "{'tags':{}}"
|
87
|
+
def highlight(highlight)
|
88
|
+
@parameters[:highlight] = highlight
|
89
|
+
self
|
90
|
+
end
|
91
|
+
|
92
|
+
# facet
|
93
|
+
# @param [String] facet ex) "{'year':{'sort':'bucket'}}"
|
94
|
+
def facet(facet)
|
95
|
+
@parameters[:facet] = facet
|
96
|
+
self
|
97
|
+
end
|
98
|
+
|
99
|
+
# define any expression
|
100
|
+
# @param [String] expr ex) "{'EXPRESSIONNAME':'EXPRESSION'}"
|
101
|
+
def expr(expr)
|
102
|
+
@parameters[:expr] = expr
|
103
|
+
self
|
104
|
+
end
|
105
|
+
|
106
|
+
def search
|
107
|
+
@client.search(@parameters)
|
108
|
+
end
|
109
|
+
|
110
|
+
def execute
|
111
|
+
if data_accessor
|
112
|
+
data_accessor.results(self)
|
113
|
+
else
|
114
|
+
search
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
data/nazrin.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nazrin/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'nazrin'
|
8
|
+
spec.version = Nazrin::VERSION
|
9
|
+
spec.authors = ['Tomohiro Suwa']
|
10
|
+
spec.email = ['neoen.gsn@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Nazrin is a Amazon CloudSearch client'
|
13
|
+
spec.description = 'Nazrin is a Amazon CloudSearch client'
|
14
|
+
spec.homepage = 'https://github.com/tsuwatch/nazrin'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_dependency 'aws-sdk', '~> 2'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.9'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rubocop'
|
25
|
+
spec.add_development_dependency 'kaminari'
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
spec.add_development_dependency 'coveralls'
|
28
|
+
spec.add_development_dependency 'sqlite3'
|
29
|
+
spec.add_development_dependency 'activerecord'
|
30
|
+
spec.add_development_dependency 'database_cleaner'
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nazrin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomohiro Suwa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: kaminari
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coveralls
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sqlite3
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: activerecord
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: database_cleaner
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: Nazrin is a Amazon CloudSearch client
|
154
|
+
email:
|
155
|
+
- neoen.gsn@gmail.com
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- ".gitignore"
|
161
|
+
- ".rspec"
|
162
|
+
- ".rubocop.yml"
|
163
|
+
- ".travis.yml"
|
164
|
+
- Gemfile
|
165
|
+
- LICENSE.txt
|
166
|
+
- README.md
|
167
|
+
- Rakefile
|
168
|
+
- lib/generators/nazrin/config_generator.rb
|
169
|
+
- lib/generators/nazrin/templates/nazrin_config.rb
|
170
|
+
- lib/nazrin.rb
|
171
|
+
- lib/nazrin/active_record/data_accessor.rb
|
172
|
+
- lib/nazrin/active_record/searchable.rb
|
173
|
+
- lib/nazrin/config.rb
|
174
|
+
- lib/nazrin/document_client.rb
|
175
|
+
- lib/nazrin/paginated_array.rb
|
176
|
+
- lib/nazrin/search_client.rb
|
177
|
+
- lib/nazrin/version.rb
|
178
|
+
- nazrin.gemspec
|
179
|
+
homepage: https://github.com/tsuwatch/nazrin
|
180
|
+
licenses:
|
181
|
+
- MIT
|
182
|
+
metadata: {}
|
183
|
+
post_install_message:
|
184
|
+
rdoc_options: []
|
185
|
+
require_paths:
|
186
|
+
- lib
|
187
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
188
|
+
requirements:
|
189
|
+
- - ">="
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: '0'
|
192
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - ">="
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '0'
|
197
|
+
requirements: []
|
198
|
+
rubyforge_project:
|
199
|
+
rubygems_version: 2.4.5.1
|
200
|
+
signing_key:
|
201
|
+
specification_version: 4
|
202
|
+
summary: Nazrin is a Amazon CloudSearch client
|
203
|
+
test_files: []
|