Permalink
Browse files

Updated README.textile, commented lib

  • Loading branch information...
1 parent a17b6a1 commit 408d5a814f082ee09d7f3ab3d7dd072bdfd3f2a8 Wynn Netherland committed Jul 18, 2008
Showing with 21 additions and 20 deletions.
  1. +11 −4 README.textile
  2. +10 −16 lib/search_sniffer.rb
View
@@ -18,7 +18,14 @@ h3. Usage
...
end
-The plugin populates the @@referring_search@ variable which can then be passed to a keyword highlighter or internal site search engine to pull related content.
-
-
-Copyright (c) 2008 Wynn Netherland, Squeejee, released under the MIT license
+The plugin populates the @@referring_search@ object containing info that can be passed to a keyword highlighter or internal site search engine to pull related content.
+
+ # http://www.google.com/search?q=ruby+on+rails+houston&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a
+ @referring_search.search_terms
+ => "ruby rails houston"
+ @referring_search.raw
+ => "ruby on rails houston"
+ @referring_search.engine
+ => "google"
+
+Copyright (c) 2008 Squeejee, released under the MIT license
View
@@ -16,26 +16,20 @@ def sniff_referring_search
# uncomment out the line below to test
# request.env["HTTP_REFERER"] = "http://www.google.com/search?q=ruby+on+rails+houston&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a"
referer = request.env["HTTP_REFERER"]
- rs = ReferringSearch.new(referer)
- @referring_search = rs.referring_search
- @referring_search_raw = rs.raw
+ @referring_search = ReferringSearch.new(referer)
true
end # sniff_referring_search
end # Module Controller Methods
class ReferringSearch
- attr_accessor :search_referers
- attr_accessor :stop_words
-
- attr_reader :referring_search
- attr_reader :raw
+ attr_reader :search_terms # sanitized search terms
+ attr_reader :raw # original terms as typed by user
+ attr_reader :engine # search engine
def initialize(referer)
- # stop words is a variable
- # .raw .original as they typed to_s, including blacklisted stuff
- # .ref
+
@search_referers = {
:google => [/^http:\/\/(www\.)?google.*/, 'q'],
:yahoo => [/^http:\/\/search\.yahoo.*/, 'p'],
@@ -64,17 +58,17 @@ def initialize(referer)
# Check if the referrer is a search engine we are targetting
if (reg.match(referer))
- # Highlight the Search Term Keywords on the page
- #@javascripts.push('keyword_highlighter')
+ # 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
- @referring_search = unstopped_keywords.gsub(@stop_words, '').squeeze(' ')
- #logger.info("Referring Search Keywords: #{referring_search}")
+ @search_terms = unstopped_keywords.gsub(@stop_words, '').squeeze(' ')
+ #logger.info("Referring Search Keywords: #{search_terms}")
return true
end
end
@@ -88,7 +82,7 @@ def initialize(referer)
# Return the referring search string instead of the object serialized into a string
def to_s
- return @referring_search
+ @search_terms
end
end # ReferringSearch

0 comments on commit 408d5a8

Please sign in to comment.