elasticsearch-persistence 6.0.0.pre → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +48 -24
  3. data/examples/notes/application.rb +3 -4
  4. data/lib/elasticsearch/persistence/repository/response/results.rb +9 -8
  5. data/lib/elasticsearch/persistence/repository/search.rb +18 -17
  6. data/lib/elasticsearch/persistence/version.rb +1 -1
  7. data/spec/repository/response/results_spec.rb +23 -0
  8. metadata +4 -26
  9. data/examples/music/album.rb +0 -54
  10. data/examples/music/artist.rb +0 -70
  11. data/examples/music/artists/_form.html.erb +0 -8
  12. data/examples/music/artists/artists_controller.rb +0 -67
  13. data/examples/music/artists/artists_controller_test.rb +0 -53
  14. data/examples/music/artists/index.html.erb +0 -60
  15. data/examples/music/artists/show.html.erb +0 -54
  16. data/examples/music/assets/application.css +0 -257
  17. data/examples/music/assets/autocomplete.css +0 -48
  18. data/examples/music/assets/blank_artist.png +0 -0
  19. data/examples/music/assets/blank_cover.png +0 -0
  20. data/examples/music/assets/form.css +0 -113
  21. data/examples/music/index_manager.rb +0 -73
  22. data/examples/music/search/index.html.erb +0 -95
  23. data/examples/music/search/search_controller.rb +0 -41
  24. data/examples/music/search/search_controller_test.rb +0 -12
  25. data/examples/music/search/search_helper.rb +0 -15
  26. data/examples/music/suggester.rb +0 -69
  27. data/examples/music/template.rb +0 -430
  28. data/examples/music/vendor/assets/jquery-ui-1.10.4.custom.min.css +0 -7
  29. data/examples/music/vendor/assets/jquery-ui-1.10.4.custom.min.js +0 -6
  30. data/examples/music/vendor/assets/stylesheets/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
@@ -1,54 +0,0 @@
1
- class Meta
2
- include Virtus.model
3
-
4
- attribute :rating
5
- attribute :have
6
- attribute :want
7
- attribute :formats
8
- end
9
-
10
- class Album
11
- include Elasticsearch::Persistence::Model
12
-
13
- index_name [Rails.application.engine_name, Rails.env].join('-')
14
-
15
-
16
- mapping _parent: { type: 'artist' } do
17
- end
18
-
19
- attribute :artist
20
- attribute :artist_id, String, mapping: { index: 'not_analyzed' }
21
- attribute :label, Hash, mapping: { type: 'object' }
22
-
23
- attribute :title
24
- attribute :released, Date
25
- attribute :notes
26
- attribute :uri
27
-
28
- attribute :tracklist, Array, mapping: { type: 'object' }
29
-
30
- attribute :styles
31
- attribute :meta, Meta, mapping: { type: 'object' }
32
-
33
- attribute :suggest, Hashie::Mash, mapping: {
34
- type: 'object',
35
- properties: {
36
- title: {
37
- type: 'object',
38
- properties: {
39
- input: { type: 'completion' },
40
- output: { type: 'keyword', index: false },
41
- payload: { type: 'object', enabled: false }
42
- }
43
- },
44
- track: {
45
- type: 'object',
46
- properties: {
47
- input: { type: 'completion' },
48
- output: { type: 'keyword', index: false },
49
- payload: { type: 'object', enabled: false }
50
- }
51
- }
52
- }
53
- }
54
- end
@@ -1,70 +0,0 @@
1
- class Artist
2
- include Elasticsearch::Persistence::Model
3
-
4
- index_name [Rails.application.engine_name, Rails.env].join('-')
5
-
6
- analyzed_and_raw = { fields: {
7
- name: { type: 'text', analyzer: 'snowball' },
8
- raw: { type: 'keyword' }
9
- } }
10
-
11
- attribute :name, String, mapping: analyzed_and_raw
12
-
13
- attribute :profile
14
- attribute :date, Date
15
-
16
- attribute :members, String, default: [], mapping: analyzed_and_raw
17
- attribute :members_combined, String, default: [], mapping: { analyzer: 'snowball' }
18
-
19
- attribute :urls, String, default: []
20
- attribute :album_count, Integer, default: 0
21
-
22
- attribute :suggest, Hashie::Mash, mapping: {
23
- type: 'object',
24
- properties: {
25
- name: {
26
- type: 'object',
27
- properties: {
28
- input: { type: 'completion' },
29
- output: { type: 'keyword', index: false },
30
- payload: { type: 'object', enabled: false }
31
- }
32
- },
33
- member: {
34
- type: 'object',
35
- properties: {
36
- input: { type: 'completion' },
37
- output: { type: 'keyword', index: false },
38
- payload: { type: 'object', enabled: false }
39
- }
40
- }
41
- }
42
- }
43
-
44
- validates :name, presence: true
45
-
46
- def albums
47
- Album.search(
48
- { query: {
49
- has_parent: {
50
- type: 'artist',
51
- query: {
52
- bool: {
53
- filter: {
54
- ids: { values: [ self.id ] }
55
- }
56
- }
57
- }
58
- }
59
- },
60
- sort: 'released',
61
- size: 100
62
- },
63
- { type: 'album' }
64
- )
65
- end
66
-
67
- def to_param
68
- [id, name.parameterize].join('-')
69
- end
70
- end
@@ -1,8 +0,0 @@
1
- <%= simple_form_for @artist do |f| %>
2
- <%= f.input :name %>
3
- <%= f.input :profile, as: :text %>
4
- <%= f.input :date, as: :date %>
5
- <%= f.input :members, hint: 'Separate names by comma', input_html: { value: f.object.members.join(', ') } %>
6
-
7
- <%= f.button :submit %>
8
- <% end %>
@@ -1,67 +0,0 @@
1
- class ArtistsController < ApplicationController
2
- before_action :set_artist, only: [:show, :edit, :update, :destroy]
3
-
4
- rescue_from Elasticsearch::Persistence::Repository::DocumentNotFound do
5
- render file: "public/404.html", status: 404, layout: false
6
- end
7
-
8
- def index
9
- @artists = Artist.all sort: 'name.raw', _source: ['name', 'album_count']
10
- end
11
-
12
- def show
13
- @albums = @artist.albums
14
- end
15
-
16
- def new
17
- @artist = Artist.new
18
- end
19
-
20
- def edit
21
- end
22
-
23
- def create
24
- @artist = Artist.new(artist_params)
25
-
26
- respond_to do |format|
27
- if @artist.save refresh: true
28
- format.html { redirect_to @artist, notice: 'Artist was successfully created.' }
29
- format.json { render :show, status: :created, location: @artist }
30
- else
31
- format.html { render :new }
32
- format.json { render json: @artist.errors, status: :unprocessable_entity }
33
- end
34
- end
35
- end
36
-
37
- def update
38
- respond_to do |format|
39
- if @artist.update(artist_params, refresh: true)
40
- format.html { redirect_to @artist, notice: 'Artist was successfully updated.' }
41
- format.json { render :show, status: :ok, location: @artist }
42
- else
43
- format.html { render :edit }
44
- format.json { render json: @artist.errors, status: :unprocessable_entity }
45
- end
46
- end
47
- end
48
-
49
- def destroy
50
- @artist.destroy refresh: true
51
- respond_to do |format|
52
- format.html { redirect_to artists_url, notice: 'Artist was successfully destroyed.' }
53
- format.json { head :no_content }
54
- end
55
- end
56
-
57
- private
58
- def set_artist
59
- @artist = Artist.find(params[:id].split('-').first)
60
- end
61
-
62
- def artist_params
63
- a = params.require(:artist)
64
- a[:members] = a[:members].split(/,\s?/) unless a[:members].is_a?(Array) || a[:members].blank?
65
- return a
66
- end
67
- end
@@ -1,53 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ArtistsControllerTest < ActionController::TestCase
4
- setup do
5
- IndexManager.create_index force: true
6
- @artist = Artist.create(id: 1, name: 'TEST')
7
- Artist.gateway.refresh_index!
8
- end
9
-
10
- test "should get index" do
11
- get :index
12
- assert_response :success
13
- assert_not_nil assigns(:artists)
14
- end
15
-
16
- test "should get new" do
17
- get :new
18
- assert_response :success
19
- end
20
-
21
- test "should create artist" do
22
- assert_difference('Artist.count') do
23
- post :create, artist: { name: @artist.name }
24
- Artist.gateway.refresh_index!
25
- end
26
-
27
- assert_redirected_to artist_path(assigns(:artist))
28
- end
29
-
30
- test "should show artist" do
31
- get :show, id: @artist
32
- assert_response :success
33
- end
34
-
35
- test "should get edit" do
36
- get :edit, id: @artist
37
- assert_response :success
38
- end
39
-
40
- test "should update artist" do
41
- patch :update, id: @artist, artist: { name: @artist.name }
42
- assert_redirected_to artist_path(assigns(:artist))
43
- end
44
-
45
- test "should destroy artist" do
46
- assert_difference('Artist.count', -1) do
47
- delete :destroy, id: @artist
48
- Artist.gateway.refresh_index!
49
- end
50
-
51
- assert_redirected_to artists_path
52
- end
53
- end
@@ -1,60 +0,0 @@
1
- <header>
2
- <h1>
3
- Artists
4
- <%= button_to 'New Artist', new_artist_path, method: 'get', tabindex: 5 %>
5
- </h1>
6
- </header>
7
-
8
- <section id="searchbox">
9
- <%= form_tag search_path, method: 'get' do %>
10
- <input type="text" name="q" value="<%= params[:q] %>" id="q" autofocus="autofocus" placeholder="start typing to search..." tabindex="0" />
11
- <% end %>
12
- </section>
13
-
14
- <section class="artists">
15
- <% @artists.each do |artist| %>
16
- <%= div_for artist, class: 'result clearfix' do %>
17
- <h2>
18
- <%= image_tag "http://ruby.elastic.co.s3-website-us-east-1.amazonaws.com/demo/music/bands/#{artist.id}.jpeg", height: '50px', class: 'band' %>
19
- <%= link_to artist do %>
20
- <span class="name"><%= artist.name %></span>
21
- <small><%= pluralize artist.album_count, 'album' %></small>
22
- <% end %>
23
- </h2>
24
- <div class="actions clearfix">
25
- <%= button_to 'Edit', edit_artist_path(artist), method: 'get' %>
26
- <%= button_to 'Destroy', artist, method: :delete, data: { confirm: 'Are you sure?' } %>
27
- </div>
28
- <% end %>
29
- <% end %>
30
- </section>
31
-
32
- <% if @artists.empty? %>
33
- <section class="no-results">
34
- <p>The search hasn't returned any results...</p>
35
- </section>
36
- <% end %>
37
-
38
- <script>
39
- $.widget( "custom.suggest", $.ui.autocomplete, {
40
- _renderMenu: function( ul, items ) {
41
- $.each( items, function( index, item ) {
42
- var category = ul.append( "<li class='ui-autocomplete-category'>" + item.label + "</li>" );
43
-
44
- $.each( item.value, function( index, item ) {
45
- var li = $('<li class="ui-autocomplete-item"><a href="<%= Rails.application.config.relative_url_root %>'+ item.url +'">'+ item.text +'</a></li>').data('ui-autocomplete-item', item )
46
- category.append(li)
47
- } )
48
- });
49
- }
50
- });
51
-
52
- $( "#q" ).suggest({
53
- source: '<%= suggest_path %>',
54
- select: function(event, ui) {
55
- document.location.href = '<%= Rails.application.config.relative_url_root %>'+ui.item.url
56
- }
57
- });
58
- </script>
59
-
60
- <script>$('img.band').error(function(){ $(this).attr('src', '/images/blank_artist.png'); });</script>
@@ -1,54 +0,0 @@
1
- <div class="artist">
2
- <header>
3
- <h1>
4
- <span class="back"><%= link_to "〈".html_safe, artists_path, title: "Back" %></span>
5
- <%= image_tag "http://ruby.elastic.co.s3-website-us-east-1.amazonaws.com/demo/music/bands/#{@artist.id}.jpeg", height: '50px', class: 'band' %>
6
- <%= @artist.name %>
7
- <%= button_to 'Edit', edit_artist_path(@artist), method: 'get' %>
8
- </h1>
9
- </header>
10
-
11
- <p id="notice"><%= notice %></p>
12
-
13
- <section class="artist-info">
14
- <span><%= @artist.members.to_sentence last_word_connector: ' and ' %></span> |
15
- <span><%= pluralize @albums.size, 'album' %></span>
16
- <p class="artist-profile"><%= @artist.profile %></p>
17
- </section>
18
-
19
- <section class="albums">
20
- <% @albums.each do |album| %>
21
- <%= div_for album, class: 'clearfix' do %>
22
- <h3>
23
- <span class="title"><%= album.title %></span>
24
- <div class="info">
25
- <small><%= album.meta.formats.join(', ') %></small>
26
- <small><%= album.released %></small>
27
- </div>
28
- </h3>
29
-
30
- <div class="cover">
31
- <%= image_tag "http://ruby.elastic.co.s3-website-us-east-1.amazonaws.com/demo/music/covers/#{album.id}.jpeg", width: '100px', class: 'cover' %>
32
- </div>
33
-
34
- <div class="content">
35
- <% album.tracklist.in_groups_of(album.tracklist.size/2+1).each_with_index do |half, g| %>
36
- <ul class=<%= cycle 'first', 'second' %> start="<%= g < 1 ? 1 : album.tracklist.size/2+2 %>">
37
- <% half.compact.each_with_index do |track, i| %>
38
- <li>
39
- <i class="counter"><%= g < 1 ? i+1 : i+(g*album.tracklist.size/2+2) %></i>
40
- <%= track['title'] %>
41
- <small><%= track['duration'] %></small>
42
- </li>
43
- <% end %>
44
- </ul>
45
- <% end %>
46
- </div>
47
- <% end %>
48
-
49
- <% end %>
50
-
51
- <script>$('img').error(function(){ $(this).attr('src', '/images/blank_cover.png'); });</script>
52
- <script>$(document.location.hash).effect('highlight', 1500)</script>
53
- </section>
54
- </div>
@@ -1,257 +0,0 @@
1
- /*
2
- *= require_tree .
3
- *= require_self
4
- *= require ui-lightness/jquery-ui-1.10.4.custom.min.css
5
- */
6
-
7
- .clearfix {
8
- *zoom: 1;
9
- }
10
-
11
- .clearfix:before,
12
- .clearfix:after {
13
- display: table;
14
- line-height: 0;
15
- content: "";
16
- }
17
-
18
- .clearfix:after {
19
- clear: both;
20
- }
21
-
22
- body {
23
- font-family: 'Helvetica Neue', Helvetica, sans-serif !important;
24
- margin: 2em 4em;
25
- }
26
-
27
- header {
28
- margin: 0;
29
- padding: 0 0 1em 0;
30
- border-bottom: 1px solid #666;
31
- }
32
-
33
- header h1 {
34
- color: #999;
35
- font-weight: 100;
36
- text-transform: uppercase;
37
- margin: 0; padding: 0;
38
- }
39
-
40
- header a {
41
- color: #0b6aff;
42
- text-decoration: none;
43
- }
44
-
45
- header .back {
46
- font-size: 100%;
47
- margin: 0 0.5em 0 -0.5em;
48
- }
49
-
50
- h1 form {
51
- float: right;
52
- }
53
-
54
- #searchbox {
55
- border-bottom: 1px solid #666;
56
- }
57
-
58
- #searchbox input {
59
- color: #444;
60
- font-size: 100%;
61
- font-weight: 100;
62
- border: none;
63
- padding: 1em 0 1em 0;
64
- width: 100%;
65
- }
66
-
67
- #searchbox input:focus {
68
- outline-width: 0;
69
- }
70
-
71
- .actions form {
72
- float: right;
73
- position: relative;
74
- top: 0.2em;
75
- }
76
-
77
- .no-results {
78
- font-weight: 200;
79
- font-size: 200%;
80
- }
81
-
82
- .result,
83
- .artist {
84
- padding: 1em 0 1em 0;
85
- margin: 0;
86
- border-bottom: 1px solid #999;
87
- }
88
-
89
- .result:hover,
90
- .artist:hover {
91
- background: #f9f9f9;
92
- }
93
-
94
- .result h2,
95
- .artist h2 {
96
- color: #444;
97
- margin: 0;
98
- padding: 0;
99
- }
100
-
101
- .artist h2 {
102
- float: left;
103
- margin-left: 50px;
104
- }
105
-
106
- .artist.search.result h2 {
107
- float: none;
108
- }
109
-
110
- .artist h1 .back {
111
- margin-right: 65px;
112
- }
113
-
114
- .artist h1 img.band {
115
- left: 120px;
116
- top: 50px;
117
- }
118
-
119
- .result h2 a,
120
- .artist h2 a {
121
- color: #444;
122
- }
123
-
124
- .result h2 small,
125
- .artist h2 small {
126
- font-size: 70%;
127
- font-weight: 100;
128
- margin-left: 0.5em;
129
- }
130
-
131
- .result h2 a,
132
- .artist h2 a {
133
- text-decoration: none;
134
- }
135
-
136
- .result h2 a:hover name,
137
- .artist h2 a:hover .name {
138
- text-decoration: underline;
139
- }
140
-
141
- .result .highlight.small {
142
- font-size: 90%;
143
- font-weight: 200;
144
- padding: 0;
145
- margin: 0.25em 0 0.25em 50px;
146
- }
147
-
148
- .result .small .label {
149
- color: #999;
150
- font-size: 80%;
151
- /*min-width: 5em;*/
152
- display: inline-block;
153
- }
154
-
155
- .artist-info {
156
- color: #5f5f5f;
157
- text-transform: uppercase;
158
- font-weight: 200;
159
- border-bottom: 1px solid #666;
160
- padding: 0 0 1em 0;
161
- margin: 0 0 1em 0;
162
- }
163
-
164
- .artist-profile {
165
- color: #999;
166
- font-size: 95%;
167
- font-weight: 100;
168
- text-transform: none;
169
- padding: 0;
170
- margin: 0.25em 0 0 0;
171
- }
172
-
173
- .artist img.band {
174
- position: absolute;
175
- left: 85px;
176
- margin-top: 14px;
177
- transform: translate(-50%,-50%);
178
- clip-path: circle(20px at center);
179
- }
180
-
181
- .album {
182
- margin: 0 0 4em 0;
183
- }
184
-
185
- .album.search.result {
186
- margin: 0;
187
- }
188
-
189
- .album .cover {
190
- float: left;
191
- width: 150px;
192
- }
193
-
194
- .album.search.result .cover {
195
- width: 40px;
196
- margin-right: 10px;
197
- }
198
-
199
- .album .cover img {
200
- border: 1px solid rgba(0,0,0,0.15);
201
- box-shadow: 0px 0px 1px 0px rgba(0,0,0,0.05);
202
- }
203
-
204
- .album .content {
205
- float: left;
206
- margin-left: 25px;
207
- }
208
-
209
- .album .content ul {
210
- float: left;
211
- margin: 0 2em 0 0;
212
- padding: 0;
213
- min-width: 18em;
214
- }
215
-
216
- .album .content ul li {
217
- line-height: 1.5em;
218
- padding: 0.5em 0 0.5em 0;
219
- border-bottom:1px solid #f8f8f8;
220
- list-style: none;
221
- }
222
-
223
- .album .content ul li .counter {
224
- color: #999;
225
- font-style: normal;
226
- font-size: 80%;
227
- font-weight: 100;
228
- margin-right: 0.5em;
229
- }
230
-
231
- .album h3 {
232
- margin: 0; padding: 0;
233
- border-bottom: 2px solid #e0e0e0;
234
- padding: 0 0 0.5em 0;
235
- margin: 0 0 1em 0;
236
- }
237
-
238
- .album h3 .title {
239
- text-transform: uppercase;
240
- font-weight: 200;
241
- }
242
-
243
- .album small {
244
- color: #a3a3a3;
245
- font-weight: 200;
246
- }
247
-
248
- .album .info {
249
- float: right;
250
- }
251
-
252
- em[class^=hl] {
253
- font-style: normal;
254
- background: #e6efff;
255
- padding: 0.15em 0.35em;
256
- border-radius: 5px;
257
- }