class Baiduserp::Result
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# 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
Public Instance Methods
sem_sites()
click to toggle source
# File lib/baiduserp/result.rb, line 179 def sem_sites sem_urls end
sem_urls()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
weight_of_*** functions return a hash array each hash includes: type, name, site, weight
# 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)
click to toggle source
# 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()
click to toggle source
# 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