Class: Baiduserp::Result
- Inherits:
-
Hash
- Object
- Hash
- Baiduserp::Result
- Defined in:
- lib/baiduserp/result.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ Result
constructor
A new instance of Result.
- #sem_sites ⇒ Object
- #sem_urls ⇒ Object
- #seo_sites ⇒ Object
- #seo_urls ⇒ Object
- #weight_of_ads_right(side_rank) ⇒ Object
- #weight_of_ads_top(side_rank) ⇒ Object
- #weight_of_con_ar(side_rank) ⇒ Object
-
#weight_of_ranks(side_rank) ⇒ Object
weight_of_*** functions return a hash array each hash includes: type, name, site, weight.
- #weight_of_zhixin(side_rank) ⇒ Object
- #weights ⇒ Object
Constructor Details
#initialize(*args) ⇒ Result
Returns a new instance of Result.
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 |
# File 'lib/baiduserp/result.rb', line 3 def initialize(*args) @config = { :left_parts => [:ads_top, :zhixin, :ranks ], :right_parts => [:con_ar, :ads_right ], :left_part_weight => 8, :right_part_weight => 2, :zhixin_weight => 3.5, :baiduopen_weight => 3, :rank_special_weight => 2, :con_ar_weight => 2 } super end |
Instance Method Details
#sem_sites ⇒ Object
179 180 181 |
# File 'lib/baiduserp/result.rb', line 179 def sem_sites sem_urls end |
#sem_urls ⇒ Object
169 170 171 172 173 174 175 176 177 |
# File 'lib/baiduserp/result.rb', line 169 def sem_urls result = [] (self[:ads_top] + self[:ads_right]).each do |ad| site = ad[:site].to_s next if site.empty? result << ad[:site] end result end |
#seo_sites ⇒ Object
159 160 161 162 163 164 165 166 167 |
# File 'lib/baiduserp/result.rb', line 159 def seo_sites result = [] self[:ranks].each do |rank| url = rank[:url].to_s next if url.empty? result << Addressable::URI.parse(rank[:url]).host end result end |
#seo_urls ⇒ Object
155 156 157 |
# File 'lib/baiduserp/result.rb', line 155 def seo_urls self[:ranks].reduce([]) {|result,rank| result << rank[:url]} end |
#weight_of_ads_right(side_rank) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/baiduserp/result.rb', line 106 def weight_of_ads_right(side_rank) result = [] self[:ads_right].each do |ad| side_rank += 1 url = ad[:url].to_s url = ad[:site].to_s if url.empty? # patch to compatible with older versions of baiduserp type = 'SEM' name = '' site = Baiduserp::Helper.parse_site(url) subdomain = Baiduserp::Helper.parse_subdomain(url) weight = 1.0/side_rank.to_f result << {type: type, name: name, site: site, subdomain: subdomain, url: url, side_rank: side_rank, weight: weight} end [result, side_rank] end |
#weight_of_ads_top(side_rank) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/baiduserp/result.rb', line 89 def weight_of_ads_top(side_rank) result = [] self[:ads_top].each do |ad| side_rank += 1 url = ad[:url].to_s url = ad[:site].to_s if url.empty? # patch to campatible with older versions of baiduserp type = 'SEM' name = '' site = Baiduserp::Helper.parse_site(url) subdomain = Baiduserp::Helper.parse_subdomain(url) weight = 1.0/side_rank.to_f result << {type: type, name: name, site: site, subdomain: subdomain, url: url, side_rank: side_rank, weight: weight} end [result, side_rank] end |
#weight_of_con_ar(side_rank) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/baiduserp/result.rb', line 123 def weight_of_con_ar(side_rank) result = [] self[:con_ar].each do |con| side_rank += 1 url = con[:data_click]['mu'].to_s type = 'Special' name = con[:tpl] site = Baiduserp::Helper.parse_site(url) subdomain = Baiduserp::Helper.parse_subdomain(url) weight = 1.0 * @config[:con_ar_weight] result << {type: type, name: name, site: site, subdomain: subdomain, url: url, side_rank: side_rank, weight: weight} end [result, side_rank] end |
#weight_of_ranks(side_rank) ⇒ Object
weight_of_*** functions return a hash array each hash includes: type, name, site, weight
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/baiduserp/result.rb', line 54 def weight_of_ranks(side_rank) result = [] self[:ranks].each do |rank| side_rank += 1 url = rank[:url].to_s mu = rank[:mu].to_s type = 'SEO' type = 'Special' if rank[:baiduopen] unless mu.empty? url = mu type = 'Special' end site = Baiduserp::Helper.parse_site(url) subdomain = Baiduserp::Helper.parse_subdomain(url) name = rank[:tpl].to_s weight = 1.0/side_rank.to_f if type == 'Special' if rank[:baiduopen] weight = weight * @config[:baiduopen_weight].to_f else weight = weight * @config[:rank_special_weight].to_f end end result << {type: type, name: name, site: site, subdomain: subdomain, url: url, mu: mu, side_rank: side_rank, weight: weight} end [result, side_rank] end |
#weight_of_zhixin(side_rank) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/baiduserp/result.rb', line 139 def weight_of_zhixin(side_rank) result = [] self[:zhixin].each do |zhixin| side_rank += 1 url = zhixin[:mu].to_s type = 'Special' name = zhixin[:tpl] site = Baiduserp::Helper.parse_site(url) subdomain = Baiduserp::Helper.parse_subdomain(url) weight = 1.0 * @config[:zhixin_weight] result << {type: type, name: name, site: site, subdomain: subdomain, url: url, side_rank: side_rank, weight: weight} end [result, side_rank] end |
#weights ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/baiduserp/result.rb', line 30 def weights result = [] [:left,:right].each do |side| side_rank = 0 @config["#{side}_parts".to_sym].each do |part| rs,side_rank = self.send("weight_of_#{part}",side_rank) rs.each do |r| r[:side] = side.to_s r[:part] = part r[:weight] = r[:weight].to_f * @config["#{side}_part_weight".to_sym].to_f result << r end end end Baiduserp::Helper.normalize(result) end |