| Class | Sitealizer::Parser::Keyword |
| In: |
lib/sitealizer/parser.rb
|
| Parent: | Object |
Process the referrers and returns the referer domain. Host is your site’s url (request.host) but you don’t have to worry about this, it’s all handled by the sitealizer controller
referer = "http://search.msn.com/results.aspx?srch=105&FORM=AS5&q=sitealizer" Sitealizer::Parser::Keyword.get_domain(referer, 'localhost') => "search.msn.com"
# File lib/sitealizer/parser.rb, line 176 def self.get_domain(string, host) return if string.nil? domain = nil domain = URI::split(string)[2] return domain != host ? domain : nil end
Process the referrers and returns the search terms if they’re available:
referer = "http://search.msn.com/results.aspx?srch=105&FORM=AS5&q=sitealizer" Sitealizer::Parser::Keyword.get_terms(referer) => 'sitealizer'
# File lib/sitealizer/parser.rb, line 149 def self.get_terms(string) return if string.nil? begin search_string = nil domain = URI::split(string)[2] if domain =~ /[google|alltheweb|search\.msn|ask|altavista|]\./ && string =~ /[?|&]q=/i search_string = CGI.unescape(string.scan(/[?|&]q=([^&]*)/).flatten.to_s) elsif domain =~ /yahoo\./i && string =~ /[?|&]p=/i search_string = CGI.unescape(string.scan(/[?|&]p=([^&]*)/).flatten.to_s) elsif domain =~ /search\.aol\./i && string =~ /[?|&]query=/i search_string = CGI.unescape(string.scan(/[?|&]query=([^&]*)/).flatten.to_s) end return search_string rescue return nil end end