elasticsearch-persistence 6.0.0.pre → 6.0.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 +4 -4
- data/README.md +48 -24
- data/examples/notes/application.rb +3 -4
- data/lib/elasticsearch/persistence/repository/response/results.rb +9 -8
- data/lib/elasticsearch/persistence/repository/search.rb +18 -17
- data/lib/elasticsearch/persistence/version.rb +1 -1
- data/spec/repository/response/results_spec.rb +23 -0
- metadata +4 -26
- data/examples/music/album.rb +0 -54
- data/examples/music/artist.rb +0 -70
- data/examples/music/artists/_form.html.erb +0 -8
- data/examples/music/artists/artists_controller.rb +0 -67
- data/examples/music/artists/artists_controller_test.rb +0 -53
- data/examples/music/artists/index.html.erb +0 -60
- data/examples/music/artists/show.html.erb +0 -54
- data/examples/music/assets/application.css +0 -257
- data/examples/music/assets/autocomplete.css +0 -48
- data/examples/music/assets/blank_artist.png +0 -0
- data/examples/music/assets/blank_cover.png +0 -0
- data/examples/music/assets/form.css +0 -113
- data/examples/music/index_manager.rb +0 -73
- data/examples/music/search/index.html.erb +0 -95
- data/examples/music/search/search_controller.rb +0 -41
- data/examples/music/search/search_controller_test.rb +0 -12
- data/examples/music/search/search_helper.rb +0 -15
- data/examples/music/suggester.rb +0 -69
- data/examples/music/template.rb +0 -430
- data/examples/music/vendor/assets/jquery-ui-1.10.4.custom.min.css +0 -7
- data/examples/music/vendor/assets/jquery-ui-1.10.4.custom.min.js +0 -6
- data/examples/music/vendor/assets/stylesheets/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
@@ -1,48 +0,0 @@
|
|
1
|
-
.ui-autocomplete {
|
2
|
-
font-family: 'Helvetica Neue', Helvetica, sans-serif !important;
|
3
|
-
border: none !important;
|
4
|
-
border-radius: 0 !important;
|
5
|
-
background-color: #fff !important;
|
6
|
-
margin: 0 !important;
|
7
|
-
padding: 0 !important;
|
8
|
-
box-shadow: 0px 3px 3px 0px rgba(0,0,0,0.75);
|
9
|
-
}
|
10
|
-
|
11
|
-
.ui-autocomplete-category {
|
12
|
-
color: #fff;
|
13
|
-
background: #222;
|
14
|
-
font-size: 90%;
|
15
|
-
font-weight: 300;
|
16
|
-
text-transform: uppercase;
|
17
|
-
margin: 0 !important;
|
18
|
-
padding: 0.25em 0.5em 0.25em 0.5em;
|
19
|
-
}
|
20
|
-
|
21
|
-
.ui-autocomplete-item {
|
22
|
-
border-bottom: 1px solid #000;
|
23
|
-
margin: 0 !important;
|
24
|
-
padding: 0 !important;
|
25
|
-
}
|
26
|
-
|
27
|
-
.ui-autocomplete-item:hover,
|
28
|
-
.ui-autocomplete-item:focus {
|
29
|
-
color: #fff !important;
|
30
|
-
background: #0b6aff !important;
|
31
|
-
}
|
32
|
-
|
33
|
-
.ui-state-focus,
|
34
|
-
.ui-state-focus a,
|
35
|
-
.ui-state-active,
|
36
|
-
.ui-state-active a,
|
37
|
-
.ui-autocomplete-item:hover a {
|
38
|
-
color: #fff !important;
|
39
|
-
background: #0b6aff !important;
|
40
|
-
outline: none !important;
|
41
|
-
border: none !important;
|
42
|
-
border-radius: 0 !important;
|
43
|
-
}
|
44
|
-
|
45
|
-
a.ui-state-focus,
|
46
|
-
a.ui-state-active {
|
47
|
-
margin: 0px !important;
|
48
|
-
}
|
Binary file
|
Binary file
|
@@ -1,113 +0,0 @@
|
|
1
|
-
/* Based on https://github.com/plataformatec/simple_form/wiki/CSS-for-simple_form */
|
2
|
-
|
3
|
-
body.edit h1,
|
4
|
-
body.new h1 {
|
5
|
-
color: #999;
|
6
|
-
font-size: 100%;
|
7
|
-
text-transform: uppercase;
|
8
|
-
margin: 0 0 1em 5.5em;
|
9
|
-
}
|
10
|
-
|
11
|
-
body.edit a[href^="/artists"],
|
12
|
-
body.new a[href^="/artists"],
|
13
|
-
body.edit a[href^="/music/artists"],
|
14
|
-
body.new a[href^="/music/artists"] {
|
15
|
-
color: #222;
|
16
|
-
background: #ccc;
|
17
|
-
text-decoration: none;
|
18
|
-
border-radius: 0.3em;
|
19
|
-
padding: 0.25em 0.5em;
|
20
|
-
margin: 2em 0 0 5.5em;
|
21
|
-
display: inline-block;
|
22
|
-
}
|
23
|
-
|
24
|
-
body.edit a[href^="/artists"]:hover,
|
25
|
-
body.new a[href^="/artists"]:hover,
|
26
|
-
body.edit a[href^="/music/artists"]:hover,
|
27
|
-
body.new a[href^="/music/artists"]:hover {
|
28
|
-
color: #fff;
|
29
|
-
background: #333;
|
30
|
-
}
|
31
|
-
|
32
|
-
body.edit a[href^="/artists"]:last-child,
|
33
|
-
body.new a[href^="/artists"]:last-child,
|
34
|
-
body.edit a[href^="/music/artists"]:last-child,
|
35
|
-
body.new a[href^="/music/artists"]:last-child {
|
36
|
-
margin-left: 0;
|
37
|
-
}
|
38
|
-
|
39
|
-
.simple_form div.input {
|
40
|
-
margin-bottom: 1em;
|
41
|
-
clear: both;
|
42
|
-
}
|
43
|
-
|
44
|
-
.simple_form label {
|
45
|
-
color: #878787;
|
46
|
-
font-size: 80%;
|
47
|
-
text-transform: uppercase;
|
48
|
-
font-weight: 200;
|
49
|
-
float: left;
|
50
|
-
width: 5em;
|
51
|
-
text-align: right;
|
52
|
-
margin: 0.25em 1em;
|
53
|
-
}
|
54
|
-
|
55
|
-
div.boolean, .simple_form input[type='submit'] {
|
56
|
-
margin-left: 8.5em;
|
57
|
-
}
|
58
|
-
|
59
|
-
.field_with_errors input {
|
60
|
-
border: 2px solid #c70008 !important;
|
61
|
-
}
|
62
|
-
|
63
|
-
.simple_form .error {
|
64
|
-
color: #fff !important;
|
65
|
-
background: #c70008;
|
66
|
-
font-weight: bold;
|
67
|
-
clear: left;
|
68
|
-
display: block;
|
69
|
-
padding: 0.25em 0.5em;
|
70
|
-
margin-left: 5.6em;
|
71
|
-
width: 27.45em;
|
72
|
-
}
|
73
|
-
|
74
|
-
.simple_form .hint {
|
75
|
-
color: #878787;
|
76
|
-
font-size: 80%;
|
77
|
-
font-style: italic;
|
78
|
-
display: block;
|
79
|
-
margin: 0.25em 0 0 7em;
|
80
|
-
clear: left;
|
81
|
-
}
|
82
|
-
|
83
|
-
input {
|
84
|
-
margin: 0;
|
85
|
-
}
|
86
|
-
|
87
|
-
input.radio {
|
88
|
-
margin-right: 5px;
|
89
|
-
vertical-align: -3px;
|
90
|
-
}
|
91
|
-
|
92
|
-
input.check_boxes {
|
93
|
-
margin-left: 3px;
|
94
|
-
vertical-align: -3px;
|
95
|
-
}
|
96
|
-
|
97
|
-
label.collection_check_boxes {
|
98
|
-
float: none;
|
99
|
-
margin: 0;
|
100
|
-
vertical-align: -2px;
|
101
|
-
margin-left: 2px;
|
102
|
-
}
|
103
|
-
|
104
|
-
input.string,
|
105
|
-
textarea.text {
|
106
|
-
padding: 0.5em;
|
107
|
-
min-width: 40em;
|
108
|
-
border: 1px solid #ccc;
|
109
|
-
}
|
110
|
-
|
111
|
-
textarea.text {
|
112
|
-
min-height: 5em;
|
113
|
-
}
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
|
3
|
-
class IndexManager
|
4
|
-
def self.create_index(options={})
|
5
|
-
client = Artist.gateway.client
|
6
|
-
index_name = Artist.index_name
|
7
|
-
|
8
|
-
client.indices.delete index: index_name rescue nil if options[:force]
|
9
|
-
|
10
|
-
settings = Artist.settings.to_hash.merge(Album.settings.to_hash)
|
11
|
-
mappings = Artist.mappings.to_hash.merge(Album.mappings.to_hash)
|
12
|
-
|
13
|
-
client.indices.create index: index_name,
|
14
|
-
body: {
|
15
|
-
settings: settings.to_hash,
|
16
|
-
mappings: mappings.to_hash }
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.import_from_yaml(source, options={})
|
20
|
-
create_index force: true if options[:force]
|
21
|
-
|
22
|
-
input = open(source)
|
23
|
-
artists = YAML.load_documents input
|
24
|
-
|
25
|
-
artists.each do |artist|
|
26
|
-
Artist.create artist.update(
|
27
|
-
'album_count' => artist['releases'].size,
|
28
|
-
'members_combined' => artist['members'].join(', '),
|
29
|
-
'suggest' => {
|
30
|
-
'name' => {
|
31
|
-
'input' => { 'input' => artist['namevariations'].unshift(artist['name']).reject { |d| d.to_s.empty? } },
|
32
|
-
'output' => artist['name'],
|
33
|
-
'payload' => {
|
34
|
-
'url' => "/artists/#{artist['id']}"
|
35
|
-
}
|
36
|
-
},
|
37
|
-
'member' => {
|
38
|
-
'input' => { 'input' => artist['members'] },
|
39
|
-
'output' => artist['name'],
|
40
|
-
'payload' => {
|
41
|
-
'url' => "/artists/#{artist['id']}"
|
42
|
-
}
|
43
|
-
}
|
44
|
-
}
|
45
|
-
)
|
46
|
-
|
47
|
-
artist['releases'].each do |album|
|
48
|
-
album.update(
|
49
|
-
'suggest' => {
|
50
|
-
'title' => {
|
51
|
-
'input' => { 'input' => album['title'] },
|
52
|
-
'output' => album['title'],
|
53
|
-
'payload' => {
|
54
|
-
'url' => "/artists/#{artist['id']}#album_#{album['id']}"
|
55
|
-
}
|
56
|
-
},
|
57
|
-
'track' => {
|
58
|
-
'input' => { 'input' => album['tracklist'].map { |d| d['title'] }.reject { |d| d.to_s.empty? } },
|
59
|
-
'output' => album['title'],
|
60
|
-
'payload' => {
|
61
|
-
'url' => "/artists/#{artist['id']}#album_#{album['id']}"
|
62
|
-
}
|
63
|
-
}
|
64
|
-
}
|
65
|
-
)
|
66
|
-
album['notes'] = album['notes'].to_s.gsub(/<.+?>/, '').gsub(/ {2,}/, '')
|
67
|
-
album['released'] = nil if album['released'] < 1
|
68
|
-
|
69
|
-
Album.create album, id: album['id'], parent: artist['id']
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
<header>
|
2
|
-
<h1>
|
3
|
-
<span class="back"><%= link_to "〈".html_safe, :back, title: "Back" %></span>
|
4
|
-
Artists & Albums
|
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
|
-
<%= content_tag :div, class: 'artist search 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: '45px', class: 'band' %>
|
19
|
-
<%= link_to artist do %>
|
20
|
-
<span class="name"><%= highlighted(artist, :name) %></span>
|
21
|
-
<small><%= pluralize artist.album_count, 'album' %></small>
|
22
|
-
<% end %>
|
23
|
-
</h2>
|
24
|
-
<% if highlight = highlight(artist, :members_combined) %>
|
25
|
-
<p class="highlight small">
|
26
|
-
<span class="label">Members</span>
|
27
|
-
<%= highlight.first.html_safe %>
|
28
|
-
</p>
|
29
|
-
<% end %>
|
30
|
-
<% if highlight = highlight(artist, :profile) %>
|
31
|
-
<p class="highlight small">
|
32
|
-
<span class="label">Profile</span>
|
33
|
-
<%= highlight.join('…').html_safe %>
|
34
|
-
</p>
|
35
|
-
<% end %>
|
36
|
-
<% end %>
|
37
|
-
<% end %>
|
38
|
-
</section>
|
39
|
-
|
40
|
-
<section class="albums">
|
41
|
-
<% @albums.each do |album| %>
|
42
|
-
<%= content_tag :div, class: 'album search result clearfix' do %>
|
43
|
-
<h2>
|
44
|
-
<%= image_tag "http://ruby.elastic.co.s3-website-us-east-1.amazonaws.com/demo/music/covers/#{album.id}.jpeg", width: '45px', class: 'cover' %>
|
45
|
-
<%= link_to artist_path(album.artist_id, anchor: "album_#{album.id}") do %>
|
46
|
-
<span class="name"><%= highlighted(album, :title) %></span>
|
47
|
-
<small><%= album.artist %></small>
|
48
|
-
<small>(<%= [album.meta.formats.first, album.released].compact.join(' ') %>)</small>
|
49
|
-
<% end %>
|
50
|
-
</h2>
|
51
|
-
|
52
|
-
<% if highlight = highlight(album, 'tracklist.title') %>
|
53
|
-
<p class="highlight small">
|
54
|
-
<span class="label">Tracks</span>
|
55
|
-
<%= highlight.join('…').html_safe %>
|
56
|
-
</p>
|
57
|
-
<% end %>
|
58
|
-
|
59
|
-
<% if highlight = highlight(album, :notes) %>
|
60
|
-
<p class="highlight small">
|
61
|
-
<span class="label">Notes</span>
|
62
|
-
<%= highlight.map { |d| d.gsub(/^\.\s?/, '') }.join('…').html_safe %>
|
63
|
-
</p>
|
64
|
-
<% end %>
|
65
|
-
<% end %>
|
66
|
-
<% end %>
|
67
|
-
</section>
|
68
|
-
|
69
|
-
<% if @artists.empty? && @albums.empty? %>
|
70
|
-
<section class="no-results">
|
71
|
-
<p>The search hasn't returned any results...</p>
|
72
|
-
</section>
|
73
|
-
<% end %>
|
74
|
-
|
75
|
-
<script>
|
76
|
-
$.widget( "custom.suggest", $.ui.autocomplete, {
|
77
|
-
_renderMenu: function( ul, items ) {
|
78
|
-
$.each( items, function( index, item ) {
|
79
|
-
var category = ul.append( "<li class='ui-autocomplete-category'>" + item.label + "</li>" );
|
80
|
-
|
81
|
-
$.each( item.value, function( index, item ) {
|
82
|
-
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 )
|
83
|
-
category.append(li)
|
84
|
-
} )
|
85
|
-
});
|
86
|
-
}
|
87
|
-
});
|
88
|
-
|
89
|
-
$( "#q" ).suggest({
|
90
|
-
source: '<%= suggest_path %>',
|
91
|
-
select: function(event, ui) {
|
92
|
-
document.location.href = '<%= Rails.application.config.relative_url_root %>'+ui.item.url
|
93
|
-
}
|
94
|
-
});
|
95
|
-
</script>
|
@@ -1,41 +0,0 @@
|
|
1
|
-
class SearchController < ApplicationController
|
2
|
-
|
3
|
-
def index
|
4
|
-
tags = { pre_tags: '<em class="hl">', post_tags: '</em>' }
|
5
|
-
@artists = Artist.search \
|
6
|
-
query: {
|
7
|
-
multi_match: {
|
8
|
-
query: params[:q],
|
9
|
-
fields: ['name^10','members^2','profile']
|
10
|
-
}
|
11
|
-
},
|
12
|
-
highlight: {
|
13
|
-
tags_schema: 'styled',
|
14
|
-
fields: {
|
15
|
-
name: { number_of_fragments: 0 },
|
16
|
-
members_combined: { number_of_fragments: 0 },
|
17
|
-
profile: { fragment_size: 50 }
|
18
|
-
}
|
19
|
-
}
|
20
|
-
|
21
|
-
@albums = Album.search \
|
22
|
-
query: {
|
23
|
-
multi_match: {
|
24
|
-
query: params[:q],
|
25
|
-
fields: ['title^100','tracklist.title^10','notes^1']
|
26
|
-
}
|
27
|
-
},
|
28
|
-
highlight: {
|
29
|
-
tags_schema: 'styled',
|
30
|
-
fields: {
|
31
|
-
title: { number_of_fragments: 0 },
|
32
|
-
'tracklist.title' => { number_of_fragments: 0 },
|
33
|
-
notes: { fragment_size: 50 }
|
34
|
-
}
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
def suggest
|
39
|
-
render json: Suggester.new(params)
|
40
|
-
end
|
41
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module SearchHelper
|
2
|
-
|
3
|
-
def highlight(object, field)
|
4
|
-
object.try(:hit).try(:highlight).try(field)
|
5
|
-
end
|
6
|
-
|
7
|
-
def highlighted(object, field)
|
8
|
-
if h = object.try(:hit).try(:highlight).try(field).try(:first)
|
9
|
-
h.html_safe
|
10
|
-
else
|
11
|
-
field.to_s.split('.').reduce(object) { |result,item| result.try(item) }
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
data/examples/music/suggester.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
class Suggester
|
2
|
-
attr_reader :response
|
3
|
-
|
4
|
-
def initialize(params={})
|
5
|
-
@term = params[:term]
|
6
|
-
end
|
7
|
-
|
8
|
-
def response
|
9
|
-
@response ||= begin
|
10
|
-
Elasticsearch::Persistence.client.search \
|
11
|
-
index: Artist.index_name,
|
12
|
-
body: {
|
13
|
-
suggest: {
|
14
|
-
artists: {
|
15
|
-
text: @term,
|
16
|
-
completion: { field: 'suggest.name.input', size: 25 }
|
17
|
-
},
|
18
|
-
members: {
|
19
|
-
text: @term,
|
20
|
-
completion: { field: 'suggest.member.input', size: 25 }
|
21
|
-
},
|
22
|
-
albums: {
|
23
|
-
text: @term,
|
24
|
-
completion: { field: 'suggest.title.input', size: 25 }
|
25
|
-
},
|
26
|
-
tracks: {
|
27
|
-
text: @term,
|
28
|
-
completion: { field: 'suggest.track.input', size: 25 }
|
29
|
-
}
|
30
|
-
},
|
31
|
-
_source: ['suggest.*']
|
32
|
-
}
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def as_json(options={})
|
37
|
-
return [] unless response['suggest']
|
38
|
-
|
39
|
-
output = [
|
40
|
-
{ label: 'Bands',
|
41
|
-
value: response['suggest']['artists'][0]['options'].map do |d|
|
42
|
-
{ text: d['_source']['suggest']['name']['output'],
|
43
|
-
url: d['_source']['suggest']['name']['payload']['url'] }
|
44
|
-
end
|
45
|
-
},
|
46
|
-
|
47
|
-
{ label: 'Albums',
|
48
|
-
value: response['suggest']['albums'][0]['options'].map do |d|
|
49
|
-
{ text: d['_source']['suggest']['title']['output'],
|
50
|
-
url: d['_source']['suggest']['title']['payload']['url'] }
|
51
|
-
end
|
52
|
-
},
|
53
|
-
|
54
|
-
{ label: 'Band Members',
|
55
|
-
value: response['suggest']['members'][0]['options'].map do |d|
|
56
|
-
{ text: "#{d['text']} (#{d['_source']['suggest']['member']['output']})",
|
57
|
-
url: d['_source']['suggest']['member']['payload']['url'] }
|
58
|
-
end
|
59
|
-
},
|
60
|
-
|
61
|
-
{ label: 'Album Tracks',
|
62
|
-
value: response['suggest']['tracks'][0]['options'].map do |d|
|
63
|
-
{ text: "#{d['text']} (#{d['_source']['suggest']['track']['output']})",
|
64
|
-
url: d['_source']['suggest']['track']['payload']['url'] }
|
65
|
-
end
|
66
|
-
}
|
67
|
-
]
|
68
|
-
end
|
69
|
-
end
|