forked from elastic/elasticsearch-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathartist.rb
50 lines (41 loc) · 1.25 KB
/
artist.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class Artist
include Elasticsearch::Persistence::Model
index_name [Rails.application.engine_name, Rails.env].join('-')
analyzed_and_raw = { fields: {
name: { type: 'string', analyzer: 'snowball' },
raw: { type: 'string', analyzer: 'keyword' }
} }
attribute :name, String, mapping: analyzed_and_raw
attribute :suggest_name, String, default: {}, mapping: { type: 'completion', payloads: true }
attribute :profile
attribute :date, Date
attribute :members, String, default: [], mapping: analyzed_and_raw
attribute :members_combined, String, default: [], mapping: { analyzer: 'snowball' }
attribute :suggest_member, String, default: {}, mapping: { type: 'completion', payloads: true }
attribute :urls, String, default: []
attribute :album_count, Integer, default: 0
validates :name, presence: true
def albums
Album.search(
{ query: {
has_parent: {
type: 'artist',
query: {
filtered: {
filter: {
ids: { values: [ self.id ] }
}
}
}
}
},
sort: 'released',
size: 100
},
{ type: 'album' }
)
end
def to_param
[id, name.parameterize].join('-')
end
end