Module: GoogleSuggest
- Defined in:
- lib/ruby-google-suggest.rb
Class Method Summary collapse
-
.suggest(query, country, language, negative_keywords = []) ⇒ Object
Main search function.
-
.suggest_deep(query, country, language, negative_keywords) ⇒ Object
Deep search.
-
.suggest_with_action(query, country, language, negative_keywords) ⇒ Object
Search using purchase / call-to-action keywords.
-
.suggest_with_considerations(query, country, language, negative_keywords) ⇒ Object
Search using consideration keywords.
-
.suggest_with_questions(query, country, language, negative_keywords) ⇒ Object
Search using question keywords.
Class Method Details
.suggest(query, country, language, negative_keywords = []) ⇒ Object
Main search function
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/ruby-google-suggest.rb', line 62 def self.suggest(query, country, language, negative_keywords=[]) base_keywords = [] final_keywords = [] response = HTTParty.get("http://suggestqueries.google.com/complete/search?&output=toolbar&hl=#{language}&q=#{query}&gl=#{country}") doc = Nokogiri::XML(response.body) seed_keywords = doc.xpath("//suggestion").map { |xml| xml["data"]} seed_keywords.each do |seed_keyword| response = HTTParty.get("http://suggestqueries.google.com/complete/search?&output=toolbar&hl=#{language}&q=#{seed_keyword}&gl=#{country}") doc = Nokogiri::XML(response.body) base_keywords << doc.xpath("//suggestion").map { |xml| xml["data"]} end final_keywords = base_keywords.flatten.uniq.reject do |base_keyword| states = [] negative_keywords.each do |negative_keyword| states << base_keyword.include?(negative_keyword) end states.any?(true) end final_keywords end |
.suggest_deep(query, country, language, negative_keywords) ⇒ Object
Deep search
22 23 24 25 26 27 28 29 |
# File 'lib/ruby-google-suggest.rb', line 22 def self.suggest_deep(query, country, language, negative_keywords) deep_keywords = [] ALPHA.each do |letter| puts "looking at '#{letter}' variations" deep_keywords << suggest(query + " #{letter}", country, language, negative_keywords) end deep_keywords.flatten.uniq end |
.suggest_with_action(query, country, language, negative_keywords) ⇒ Object
Search using purchase / call-to-action keywords
52 53 54 55 56 57 58 59 |
# File 'lib/ruby-google-suggest.rb', line 52 def self.suggest_with_action(query, country, language, negative_keywords) do_keywords = [] DO.each do |do_keyword| puts "looking at '#{do_keyword}' variations" do_keywords << suggest(query + " #{do_keyword}", country, language, negative_keywords) end do_keywords.flatten.uniq end |
.suggest_with_considerations(query, country, language, negative_keywords) ⇒ Object
Search using consideration keywords
42 43 44 45 46 47 48 49 |
# File 'lib/ruby-google-suggest.rb', line 42 def self.suggest_with_considerations(query, country, language, negative_keywords) considerations_keywords = [] CONSIDERATIONS.each do |consideration| puts "looking at '#{consideration}' variations" considerations_keywords << suggest(query + " #{consideration}", country, language, negative_keywords) end considerations_keywords.flatten.uniq end |
.suggest_with_questions(query, country, language, negative_keywords) ⇒ Object
Search using question keywords
32 33 34 35 36 37 38 39 |
# File 'lib/ruby-google-suggest.rb', line 32 def self.suggest_with_questions(query, country, language, negative_keywords) questions_keywords = [] QUESTIONS.each do |question| puts "looking at '#{question}' variations" questions_keywords << suggest(query + " #{question}", country, language, negative_keywords) end questions_keywords.flatten.uniq end |