Class: Search::Sniffer::ReferringSearch
- Inherits:
-
Object
- Object
- Search::Sniffer::ReferringSearch
- Defined in:
- lib/search-sniffer/search-sniffer.rb
Overview
Module Controller Methods
Instance Attribute Summary collapse
-
#engine ⇒ Object
readonly
search engine.
-
#raw ⇒ Object
readonly
original terms as typed by user.
-
#search_terms ⇒ Object
readonly
sanitized search terms.
Instance Method Summary collapse
-
#initialize(referer) ⇒ ReferringSearch
constructor
A new instance of ReferringSearch.
-
#to_s ⇒ Object
Return the referring search string instead of the object serialized into a string.
Constructor Details
#initialize(referer) ⇒ ReferringSearch
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 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 |
# File 'lib/search-sniffer/search-sniffer.rb', line 31 def initialize(referer) @search_referers = { :google => [/^http:\/\/(www\.)?google.*/, 'q'], :yandex => [/^http:\/\/(www\.)?yandex.*/, 'text'], :mail => [/^http:\/\/go\.mail.*/, 'q'], :nigma => [/^http:\/\/(www\.)?nigma.*/, 's'], :bing => [/^http:\/\/(www\.)?bing.*/, 'q'], :ask => [/^http:\/\/(www\.)?ask.*/, 'q'], :yahoo => [/^http:\/\/search\.yahoo.*/, 'p'], :msn => [/^http:\/\/search\.msn.*/, 'q'], :aol => [/^http:\/\/search\.aol.*/, 'userQuery'], :altavista => [/^http:\/\/(www\.)?altavista.*/, 'q'], :feedster => [/^http:\/\/(www\.)?feedster.*/, 'q'], :lycos => [/^http:\/\/search\.lycos.*/, 'query'], :alltheweb => [/^http:\/\/(www\.)?alltheweb.*/, 'q'] } @stop_words = /\b(\d+|\w|about|after|also|an|and|are|as|at|be|because|before|between|but|by|can|com|de|do|en|for|from|has|how|however|htm|html|if|i|in|into|is|it|la|no|of|on|or|other|out|since|site|such|than|that|the|there|these|this|those|to|under|upon|vs|was|what|when|where|whether|which|who|will|with|within|without|www|you|your)\b/i # Get query args query_args = begin URI.split(referer)[7] rescue URI::InvalidURIError nil end # Determine the referring search that was used unless referer.blank? @search_referers.each do |k, v| reg, query_param_name = v # Check if the referrer is a search engine we are targetting if (reg.match(referer)) # set the search engine @engine = k unless query_args.empty? query_args.split("&").each do |arg| pieces = arg.split('=') if pieces.length == 2 && pieces.first == query_param_name unstopped_keywords = CGI.unescape(pieces.last) @raw = unstopped_keywords @search_terms = unstopped_keywords.gsub(@stop_words, '').squeeze(' ') #logger.info("Referring Search Keywords: #{search_terms}") return true end end end # unless return true # because we found a match end # if end # do end #unless end |
Instance Attribute Details
#engine ⇒ Object (readonly)
search engine
29 30 31 |
# File 'lib/search-sniffer/search-sniffer.rb', line 29 def engine @engine end |
#raw ⇒ Object (readonly)
original terms as typed by user
28 29 30 |
# File 'lib/search-sniffer/search-sniffer.rb', line 28 def raw @raw end |
#search_terms ⇒ Object (readonly)
sanitized search terms
27 28 29 |
# File 'lib/search-sniffer/search-sniffer.rb', line 27 def search_terms @search_terms end |
Instance Method Details
#to_s ⇒ Object
Return the referring search string instead of the object serialized into a string
89 90 91 |
# File 'lib/search-sniffer/search-sniffer.rb', line 89 def to_s @search_terms end |