Skip to content

Commit ffa3e52

Browse files
seurosvagrant
authored and
vagrant
committed
Extract search mapping to concerns #WIP_173
1 parent b91bd81 commit ffa3e52

10 files changed

+287
-267
lines changed

app/models/badge.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Badge < ActiveRecord::Base
2929
validates_uniqueness_of :badge_class_name, scope: :user_id
3030
after_create :generate_event
3131

32-
scope :of_type, lambda { |badge| where(badge_class_name: badge.class.name) }
32+
scope :of_type, ->(badge) { where(badge_class_name: badge.class.name) }
3333

3434
class << self
3535
def rename(old_class_name, new_class_name)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module OpportunityMapping
2+
extend ActiveSupport::Concern
3+
4+
included do
5+
settings analysis: { analyzer: { comma: { 'type' => 'pattern',
6+
'pattern' => ',' } } }
7+
mapping show: { properties: {
8+
public_id: { type: 'string', index: 'not_analyzed' },
9+
name: { type: 'string', boost: 100, analyzer: 'snowball' },
10+
description: { type: 'string', boost: 100, analyzer: 'snowball' },
11+
designation: { type: 'string', index: 'not_analyzed' },
12+
opportunity_type: { type: 'string', index: 'not_analyzed' },
13+
location: { type: 'string', boost: 80, analyzer: 'snowball' },
14+
location_city: { type: 'string', boost: 80, analyzer: 'snowball' },
15+
tags: { type: 'string', boost: 50, analyzer: 'comma' },
16+
link: { type: 'string', index: 'not_analyzed' },
17+
salary: { type: 'integer', boost: 80, index: 'not_analyzed' },
18+
created_at: { type: 'string', index: 'not_analyzed' },
19+
updated_at: { type: 'string', index: 'not_analyzed' },
20+
expires_at: { type: 'string', index: 'not_analyzed' },
21+
url: { type: 'string', index: 'not_analyzed' },
22+
apply: { type: 'boolean', index: 'not_analyzed' },
23+
team: { type: 'multi_field', index: 'not_analyzed', fields: {
24+
name: { type: 'string', index: 'snowball' },
25+
slug: { type: 'string', boost: 50, index: 'snowball' },
26+
id: { type: 'string', index: 'not_analyzed' },
27+
avatar_url: { type: 'string', index: 'not_analyzed' },
28+
featured_banner_image: { type: 'string', index: 'not_analyzed' },
29+
big_image: { type: 'string', index: 'not_analyzed' },
30+
hiring: { type: 'boolean', index: 'not_analyzed' }
31+
} },
32+
} }
33+
end
34+
end

app/models/concerns/protip_mapping.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
module ProtipMapping
2+
extend ActiveSupport::Concern
3+
4+
included do
5+
settings analysis: {
6+
analyzer: {
7+
comma: {"type" => "pattern",
8+
"pattern" => ",",
9+
"filter" => "keyword"
10+
}
11+
12+
}
13+
}
14+
15+
mapping show: {properties: {
16+
public_id: {type: 'string', index: 'not_analyzed'},
17+
kind: {type: 'string', index: 'not_analyzed'},
18+
title: {type: 'string', boost: 100, analyzer: 'snowball'},
19+
body: {type: 'string', boost: 80, analyzer: 'snowball'},
20+
html: {type: 'string', index: 'not_analyzed'},
21+
tags: {type: 'string', boost: 80, analyzer: 'comma'},
22+
upvotes: {type: 'integer', index: 'not_analyzed'},
23+
url: {type: 'string', index: 'not_analyzed'},
24+
upvote_path: {type: 'string', index: 'not_analyzed'},
25+
popular_score: {type: 'double', index: 'not_analyzed'},
26+
score: {type: 'double', index: 'not_analyzed'},
27+
trending_score: {type: 'double', index: 'not_analyzed'},
28+
only_link: {type: 'string', index: 'not_analyzed'},
29+
link: {type: 'string', index: 'not_analyzed'},
30+
team: {type: 'multi_field', index: 'not_analyzed', fields: {
31+
name: {type: 'string', index: 'snowball'},
32+
slug: {type: 'string', boost: 50, index: 'snowball'},
33+
avatar: {type: 'string', index: 'not_analyzed'},
34+
profile_path: {type: 'string', index: 'not_analyzed'},
35+
hiring: {type: 'boolean', index: 'not_analyzed'}
36+
}},
37+
views_count: {type: 'integer', index: 'not_analyzed'},
38+
comments_count: {type: 'integer', index: 'not_analyzed'},
39+
best_stat: {type: 'multi_field', index: 'not_analyzed', fields: {
40+
name: {type: 'string', index: 'not_analyzed'},
41+
value: {type: 'integer', index: 'not_analyzed'},
42+
}},
43+
comments: {type: 'object', index: 'not_analyzed', properties: {
44+
title: {type: 'string', boost: 100, analyzer: 'snowball'},
45+
body: {type: 'string', boost: 80, analyzer: 'snowball'},
46+
likes: {type: 'integer', index: 'not_analyzed'}
47+
}},
48+
networks: {type: 'string', boost: 50, analyzer: 'comma'},
49+
upvoters: {type: 'integer', boost: 50, index: 'not_analyzed'},
50+
created_at: {type: 'date', boost: 10, index: 'not_analyzed'},
51+
featured: {type: 'boolean', index: 'not_analyzed'},
52+
flagged: {type: 'boolean', index: 'not_analyzed'},
53+
created_automagically: {type: 'boolean', index: 'not_analyzed'},
54+
reviewed: {type: 'boolean', index: 'not_analyzed'},
55+
user: {type: 'multi_field', index: 'not_analyzed', fields: {
56+
username: {type: 'string', boost: 40, index: 'not_analyzed'},
57+
name: {type: 'string', boost: 40, index: 'not_analyzed'},
58+
user_id: {type: 'integer', boost: 40, index: 'not_analyzed'},
59+
profile_path: {type: 'string', index: 'not_analyzed'},
60+
avatar: {type: 'string', index: 'not_analyzed'},
61+
about: {type: 'string', index: 'not_analyzed'},
62+
}}}}
63+
end
64+
end

app/models/concerns/team_mapping.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module TeamMapping
2+
extend ActiveSupport::Concern
3+
4+
included do
5+
mapping team: {
6+
properties: {
7+
id: { type: 'string', index: 'not_analyzed' },
8+
slug: { type: 'string', index: 'not_analyzed' },
9+
name: { type: 'string', boost: 100, analyzer: 'snowball' },
10+
score: { type: 'float', index: 'not_analyzed' },
11+
size: { type: 'integer', index: 'not_analyzed' },
12+
avatar: { type: 'string', index: 'not_analyzed' },
13+
country: { type: 'string', boost: 50, analyzer: 'snowball' },
14+
url: { type: 'string', index: 'not_analyzed' },
15+
follow_path: { type: 'string', index: 'not_analyzed' },
16+
hiring: { type: 'boolean', index: 'not_analyzed' },
17+
total_member_count: { type: 'integer', index: 'not_analyzed' },
18+
completed_sections: { type: 'integer', index: 'not_analyzed' },
19+
team_members: { type: 'multi_field', fields: {
20+
username: { type: 'string', index: 'not_analyzed' },
21+
profile_url: { type: 'string', index: 'not_analyzed' },
22+
avatar: { type: 'string', index: 'not_analyzed' }
23+
} }
24+
}
25+
}
26+
27+
end
28+
end

app/models/like.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Like < ActiveRecord::Base
3535
after_save :liked_callback
3636

3737
scope :protips, where(likable_type: 'Protip')
38-
scope :protips_score, lambda { |protip_ids| protips.where(likable_id: protip_ids).group(:likable_id).select('SUM(likes.value) as like_score') }
38+
scope :protips_score, ->(protip_ids) { protips.where(likable_id: protip_ids).group(:likable_id).select('SUM(likes.value) as like_score') }
3939

4040
def liked_callback
4141
likable.try(:liked, value)

0 commit comments

Comments
 (0)