|
1 |
| -# encoding utf-8 |
2 |
| -require 'search' |
| 1 | +# encodinsnowballg utf-8 |
| 2 | +require 'elasticsearch/model' |
3 | 3 |
|
4 | 4 | class Team < ActiveRecord::Base
|
| 5 | + include SearchModule |
| 6 | + include LeaderboardRedisRank |
| 7 | + include TeamAnalytics |
| 8 | + include TeamMigration |
| 9 | + |
5 | 10 | DEFAULT_HEX_BRAND = '#343131'
|
6 | 11 | LEADERBOARD_KEY = 'teams:leaderboard'
|
7 | 12 | FEATURED_TEAMS_CACHE_KEY = 'featured_teams_results'
|
8 | 13 | MAX_TEAM_SCORE = 400
|
9 | 14 |
|
10 |
| - self.table_name = 'teams' |
11 |
| - |
12 |
| - include SearchModule |
13 | 15 | include TeamSearch
|
14 |
| - include LeaderboardRedisRank |
15 |
| - include TeamAnalytics |
16 |
| - include TeamMigration |
17 | 16 |
|
18 | 17 | mount_uploader :avatar, TeamUploader
|
19 | 18 |
|
20 |
| - mapping team: { |
21 |
| - properties: { |
22 |
| - id: { type: 'string', index: 'not_analyzed' }, |
23 |
| - slug: { type: 'string', index: 'not_analyzed' }, |
24 |
| - name: { type: 'string', boost: 100, analyzer: 'snowball' }, |
25 |
| - score: { type: 'float', index: 'not_analyzed' }, |
26 |
| - size: { type: 'integer', index: 'not_analyzed' }, |
27 |
| - avatar: { type: 'string', index: 'not_analyzed' }, |
28 |
| - country: { type: 'string', boost: 50, analyzer: 'snowball' }, |
29 |
| - url: { type: 'string', index: 'not_analyzed' }, |
30 |
| - follow_path: { type: 'string', index: 'not_analyzed' }, |
31 |
| - hiring: { type: 'boolean', index: 'not_analyzed' }, |
32 |
| - total_member_count: { type: 'integer', index: 'not_analyzed' }, |
33 |
| - completed_sections: { type: 'integer', index: 'not_analyzed' }, |
34 |
| - team_members: { type: 'multi_field', fields: { |
35 |
| - username: { type: 'string', index: 'not_analyzed' }, |
36 |
| - profile_url: { type: 'string', index: 'not_analyzed' }, |
37 |
| - avatar: { type: 'string', index: 'not_analyzed' } |
38 |
| - } } |
39 |
| - } |
40 |
| - } |
41 |
| - |
42 | 19 | scope :featured, ->{ where(premium: true, valid_jobs: true, hide_from_featured: false) }
|
43 | 20 |
|
44 | 21 |
|
@@ -137,7 +114,7 @@ def self.completed_at_least(section_count = 6, page=1, per_page=Team.count, sear
|
137 | 114 |
|
138 | 115 | def self.with_similar_names(name)
|
139 | 116 | name.gsub!(/ \-\./, '.*')
|
140 |
| - teams = Team.any_of({ :name => /#{name}.*/i }).limit(3).to_a |
| 117 | + Team.where('name ilike ?', "#{name}%").limit(3).to_a |
141 | 118 | end
|
142 | 119 |
|
143 | 120 | def self.with_completed_section(section)
|
@@ -727,7 +704,7 @@ def coderwall?
|
727 | 704 | end
|
728 | 705 |
|
729 | 706 | def reindex_search
|
730 |
| - if Rails.env.development? or Rails.env.test? or self.destroyed? |
| 707 | + if %w(development test).include?(Rails.env) || self.destroyed? |
731 | 708 | self.tire.update_index
|
732 | 709 | else
|
733 | 710 | IndexTeamJob.perform_async(id)
|
@@ -827,6 +804,54 @@ def deny_join_request(user)
|
827 | 804 | self.pending_join_requests.delete user.id
|
828 | 805 | end
|
829 | 806 |
|
| 807 | + |
| 808 | + include Elasticsearch::Model |
| 809 | + include Elasticsearch::Model::Callbacks |
| 810 | + |
| 811 | + #mapping team: { |
| 812 | + #properties: { |
| 813 | + #id: { type: 'string', index: 'not_analyzed' }, |
| 814 | + #slug: { type: 'string', index: 'not_analyzed' }, |
| 815 | + #name: { type: 'string', boost: 100, analyzer: 'snowball' }, |
| 816 | + #score: { type: 'float', index: 'not_analyzed' }, |
| 817 | + #size: { type: 'integer', index: 'not_analyzed' }, |
| 818 | + #avatar: { type: 'string', index: 'not_analyzed' }, |
| 819 | + #country: { type: 'string', boost: 50, analyzer: 'snowball' }, |
| 820 | + #url: { type: 'string', index: 'not_analyzed' }, |
| 821 | + #follow_path: { type: 'string', index: 'not_analyzed' }, |
| 822 | + #hiring: { type: 'boolean', index: 'not_analyzed' }, |
| 823 | + #total_member_count: { type: 'integer', index: 'not_analyzed' }, |
| 824 | + #completed_sections: { type: 'integer', index: 'not_analyzed' }, |
| 825 | + #team_members: { type: 'multi_field', fields: { |
| 826 | + #username: { type: 'string', index: 'not_analyzed' }, |
| 827 | + #profile_url: { type: 'string', index: 'not_analyzed' }, |
| 828 | + #avatar: { type: 'string', index: 'not_analyzed' } |
| 829 | + #} } |
| 830 | + #} |
| 831 | + #} |
| 832 | + |
| 833 | + settings do |
| 834 | + mappings dynamic: 'false' do |
| 835 | + indexes :id, type: 'string', index: 'not_analyzed' |
| 836 | + indexes :slug, type: 'string', index: 'not_analyzed' |
| 837 | + indexes :name, type: 'string', boost: 100, analyzer: 'snowball' |
| 838 | + indexes :core, type: 'float', analyzer: 'snowball' |
| 839 | + indexes :size, type: 'integer', analyzer: 'snowball' |
| 840 | + indexes :avatar, type: 'string', analyzer: 'snowball' |
| 841 | + indexes :country, type: 'string', boost: 50, analyzer: 'snowball' |
| 842 | + indexes :url, type: 'string', analyzer: 'snowball' |
| 843 | + indexes :follow_path, type: 'string', analyzer: 'snowball' |
| 844 | + indexes :hiring, type: 'boolean', analyzer: 'snowball' |
| 845 | + indexes :total_member_count, type: 'integer', analyzer: 'snowball' |
| 846 | + indexes :completed_sections, type: 'integer', analyzer: 'snowball' |
| 847 | + #indexes :team_members do #, type: 'multi_field', fields: |
| 848 | + #indexes :username, type: 'string', analyzer: 'snowball' |
| 849 | + #indexes :profile_url, type: 'string', analyzer: 'snowball' |
| 850 | + #indexes :avatar, type: 'string', analyzer: 'snowball' |
| 851 | + #end |
| 852 | + end |
| 853 | + end |
| 854 | + |
830 | 855 | private
|
831 | 856 |
|
832 | 857 | def identify_visitor(visitor_name)
|
@@ -858,6 +883,7 @@ def update_team_size!
|
858 | 883 | end
|
859 | 884 |
|
860 | 885 | def clear_cache_if_premium_team
|
| 886 | + Team |
861 | 887 | Rails.cache.delete(Team::FEATURED_TEAMS_CACHE_KEY) if premium?
|
862 | 888 | end
|
863 | 889 |
|
|
0 commit comments