waistband 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -23
- data/lib/waistband/query.rb +35 -2
- data/lib/waistband/version.rb +1 -1
- metadata +17 -7
- checksums.yaml +0 -15
- data/lib/waistband/query_helpers.rb +0 -46
data/README.md
CHANGED
@@ -12,9 +12,7 @@ brew install elasticsearch
|
|
12
12
|
|
13
13
|
Add this line to your application's Gemfile:
|
14
14
|
|
15
|
-
gem 'waistband'
|
16
|
-
|
17
|
-
Be sure to check out the [releases page](https://github.com/taskrabbit/waistband/releases) to get the latest tag.
|
15
|
+
gem 'waistband'
|
18
16
|
|
19
17
|
And then execute:
|
20
18
|
|
@@ -140,14 +138,16 @@ index.read('my_data')
|
|
140
138
|
|
141
139
|
### Searching
|
142
140
|
|
143
|
-
For searching,
|
141
|
+
For searching, you construct a query from your index:
|
144
142
|
|
145
143
|
```ruby
|
146
144
|
index = Waistband::Index.new('search')
|
147
|
-
query = index.query(
|
148
|
-
query
|
149
|
-
|
150
|
-
|
145
|
+
query = index.query(page_size: 5).prepare({
|
146
|
+
query: {
|
147
|
+
term: { hidden: false }
|
148
|
+
},
|
149
|
+
sort: { created_at: {order: 'desc' } }
|
150
|
+
})
|
151
151
|
|
152
152
|
query.results # => returns an array of Waistband::QueryResult
|
153
153
|
|
@@ -166,21 +166,6 @@ query.results
|
|
166
166
|
|
167
167
|
For paginating the results, you can use the `#paginated_results` method, which requires the [Kaminari](https://github.com/amatsuda/kaminari), gem. If you use another gem, you can just override the method, etc.
|
168
168
|
|
169
|
-
### Model
|
170
|
-
|
171
|
-
The gem offers a `Waistband::Model` that you can use to store model type data into the Elastic Search index. You just inherit from the class and define the following class methods:
|
172
|
-
|
173
|
-
```ruby
|
174
|
-
class Thing < Waistband::Model
|
175
|
-
with_index :my_index_name
|
176
|
-
|
177
|
-
columns :user_id, :content, :admin_visible
|
178
|
-
defaults admin_visible: false
|
179
|
-
|
180
|
-
validates :user_id, :content
|
181
|
-
end
|
182
|
-
```
|
183
|
-
|
184
169
|
For more information and extra methods, take a peek into the class docs.
|
185
170
|
|
186
171
|
## Contributing
|
data/lib/waistband/query.rb
CHANGED
@@ -3,8 +3,6 @@ require 'active_support/core_ext/hash/indifferent_access'
|
|
3
3
|
module Waistband
|
4
4
|
class Query
|
5
5
|
|
6
|
-
include ::Waistband::QueryHelpers
|
7
|
-
|
8
6
|
attr_accessor :page, :page_size
|
9
7
|
|
10
8
|
def initialize(index, options = {})
|
@@ -19,6 +17,25 @@ module Waistband
|
|
19
17
|
self
|
20
18
|
end
|
21
19
|
|
20
|
+
def paginated_results
|
21
|
+
return Kaminari.paginate_array(results, total_count: total_results).page(@page).per(@page_size) if defined?(Kaminari)
|
22
|
+
raise "Please include the `kaminari` gem to use this method!"
|
23
|
+
end
|
24
|
+
|
25
|
+
def results
|
26
|
+
hits.map do |hit|
|
27
|
+
Waistband::QueryResult.new(hit)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def hits
|
32
|
+
execute!['hits']['hits'] rescue []
|
33
|
+
end
|
34
|
+
|
35
|
+
def total_results
|
36
|
+
execute!['hits']['total'] rescue 0
|
37
|
+
end
|
38
|
+
|
22
39
|
private
|
23
40
|
|
24
41
|
def to_hash
|
@@ -28,6 +45,22 @@ module Waistband
|
|
28
45
|
@hash
|
29
46
|
end
|
30
47
|
|
48
|
+
def url
|
49
|
+
index.search_url
|
50
|
+
end
|
51
|
+
|
52
|
+
def index
|
53
|
+
Waistband::Index.new(@index)
|
54
|
+
end
|
55
|
+
|
56
|
+
def execute!
|
57
|
+
JSON.parse(RestClient::Request.execute(method: :get, url: url, payload: to_hash.to_json))
|
58
|
+
end
|
59
|
+
|
60
|
+
def from
|
61
|
+
@page_size * (@page - 1)
|
62
|
+
end
|
63
|
+
|
31
64
|
# /private
|
32
65
|
|
33
66
|
end
|
data/lib/waistband/version.rb
CHANGED
metadata
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: waistband
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.4
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- David Jairala
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2014-01-29 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: activesupport
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
@@ -20,6 +22,7 @@ dependencies:
|
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ! '>='
|
25
28
|
- !ruby/object:Gem::Version
|
@@ -27,6 +30,7 @@ dependencies:
|
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: rest-client
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
35
|
- - ~>
|
32
36
|
- !ruby/object:Gem::Version
|
@@ -34,6 +38,7 @@ dependencies:
|
|
34
38
|
type: :runtime
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
43
|
- - ~>
|
39
44
|
- !ruby/object:Gem::Version
|
@@ -41,6 +46,7 @@ dependencies:
|
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: json
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
51
|
- - ~>
|
46
52
|
- !ruby/object:Gem::Version
|
@@ -48,6 +54,7 @@ dependencies:
|
|
48
54
|
type: :runtime
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
59
|
- - ~>
|
53
60
|
- !ruby/object:Gem::Version
|
@@ -55,6 +62,7 @@ dependencies:
|
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
63
|
name: bundler
|
57
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
58
66
|
requirements:
|
59
67
|
- - ~>
|
60
68
|
- !ruby/object:Gem::Version
|
@@ -62,6 +70,7 @@ dependencies:
|
|
62
70
|
type: :development
|
63
71
|
prerelease: false
|
64
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
65
74
|
requirements:
|
66
75
|
- - ~>
|
67
76
|
- !ruby/object:Gem::Version
|
@@ -69,6 +78,7 @@ dependencies:
|
|
69
78
|
- !ruby/object:Gem::Dependency
|
70
79
|
name: rake
|
71
80
|
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
72
82
|
requirements:
|
73
83
|
- - ! '>='
|
74
84
|
- !ruby/object:Gem::Version
|
@@ -76,6 +86,7 @@ dependencies:
|
|
76
86
|
type: :development
|
77
87
|
prerelease: false
|
78
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
79
90
|
requirements:
|
80
91
|
- - ! '>='
|
81
92
|
- !ruby/object:Gem::Version
|
@@ -100,7 +111,6 @@ files:
|
|
100
111
|
- lib/waistband/connection.rb
|
101
112
|
- lib/waistband/index.rb
|
102
113
|
- lib/waistband/query.rb
|
103
|
-
- lib/waistband/query_helpers.rb
|
104
114
|
- lib/waistband/query_result.rb
|
105
115
|
- lib/waistband/quick_error.rb
|
106
116
|
- lib/waistband/stringified_array.rb
|
@@ -123,26 +133,27 @@ files:
|
|
123
133
|
homepage: https://github.com/taskrabbit/waistband
|
124
134
|
licenses:
|
125
135
|
- MIT
|
126
|
-
metadata: {}
|
127
136
|
post_install_message:
|
128
137
|
rdoc_options: []
|
129
138
|
require_paths:
|
130
139
|
- lib
|
131
140
|
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
132
142
|
requirements:
|
133
143
|
- - ! '>='
|
134
144
|
- !ruby/object:Gem::Version
|
135
145
|
version: 1.9.3
|
136
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
137
148
|
requirements:
|
138
149
|
- - ! '>='
|
139
150
|
- !ruby/object:Gem::Version
|
140
151
|
version: '0'
|
141
152
|
requirements: []
|
142
153
|
rubyforge_project:
|
143
|
-
rubygems_version:
|
154
|
+
rubygems_version: 1.8.25
|
144
155
|
signing_key:
|
145
|
-
specification_version:
|
156
|
+
specification_version: 3
|
146
157
|
summary: Elastic Search all the things!
|
147
158
|
test_files:
|
148
159
|
- spec/config/waistband/waistband.yml
|
@@ -158,4 +169,3 @@ test_files:
|
|
158
169
|
- spec/lib/stringified_hash_spec.rb
|
159
170
|
- spec/spec_helper.rb
|
160
171
|
- spec/support/index_helper.rb
|
161
|
-
has_rdoc:
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
YjQ5YjAyNjA1NGIyZGE4ZTZjNDg0MjhkNGU3OWY1NmIwZTYxMTIxZQ==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MTU2YjFhN2YyY2QwMzljNWQ4NTJmYTNjNGJlZjE5NDA2YjcxMjU1NA==
|
7
|
-
!binary "U0hBNTEy":
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
YWVhNTE5MDM5ZGY3OGM2MTE0ZWU5MzY0Njc2ZjcxZGI2MjE0NWViNDNmZjI4
|
10
|
-
MTgyN2Q2ZGQ5Yzk1Y2I3NjRlYWNhYTc2NmI2NjEzMmQwMTMwZDBmODk2YjI4
|
11
|
-
ZjJiZDJkMDc5OWNhNGQwZDU0MDMwMTEzNDczZGQ3Yjc2Yjg4MGY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MTRkMDdkYzRlMzFiZGU1OGExY2FjN2QyYmRhNTFkYjBjNzU0ZDg1NWM0MWVl
|
14
|
-
YWE3NWU0NWRkODI5ZjIyNTViZjAxZjAzNjJjMjFjZDlkM2M1OWI2M2YxMWU0
|
15
|
-
NjA4MmMyOGM2ZWUyMTBjZWYzMTg0MTc0Yjg3MDQ1ZTFmOWQyNjU=
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'rest-client'
|
2
|
-
|
3
|
-
module Waistband
|
4
|
-
module QueryHelpers
|
5
|
-
|
6
|
-
def paginated_results
|
7
|
-
return Kaminari.paginate_array(results, total_count: total_results).page(@page).per(@page_size) if defined?(Kaminari)
|
8
|
-
raise "Please include the `kaminari` gem to use this method!"
|
9
|
-
end
|
10
|
-
|
11
|
-
def results
|
12
|
-
hits.map do |hit|
|
13
|
-
Waistband::QueryResult.new(hit)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def hits
|
18
|
-
execute!['hits']['hits'] rescue []
|
19
|
-
end
|
20
|
-
|
21
|
-
def total_results
|
22
|
-
execute!['hits']['total'] rescue 0
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def url
|
28
|
-
index.search_url
|
29
|
-
end
|
30
|
-
|
31
|
-
def index
|
32
|
-
Waistband::Index.new(@index)
|
33
|
-
end
|
34
|
-
|
35
|
-
def execute!
|
36
|
-
JSON.parse(RestClient::Request.execute(method: :get, url: url, payload: to_hash.to_json))
|
37
|
-
end
|
38
|
-
|
39
|
-
def from
|
40
|
-
@page_size * (@page - 1)
|
41
|
-
end
|
42
|
-
|
43
|
-
# /private
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|