Class: Query::Engine::Sogou
- Inherits:
-
Object
- Object
- Query::Engine::Sogou
- Includes:
- Query::Engine
- Defined in:
- lib/query/engine/sogou.rb
Constant Summary collapse
- BaseUri =
'http://www.sogou.com/web?'
- Options =
{ :headers => {"User-Agent" => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.73.11 (KHTML, like Gecko) Version/7.0.1 Safari/537.73.11'} }
Instance Attribute Summary
Attributes included from Query::Engine
Class Method Summary collapse
-
.links(uri) ⇒ Object
domain:xxx.yyy.com/path/file.html.
-
.pages(host) ⇒ Object
site:xxx.yyy.com.
- .query(wd) ⇒ Object
- .suggestions(word) ⇒ Object
Methods included from Query::Engine
Class Method Details
.links(uri) ⇒ Object
domain:xxx.yyy.com/path/file.html
34 35 36 |
# File 'lib/query/engine/sogou.rb', line 34 def links(uri) query("domain:\"#{uri}\"") end |
.pages(host) ⇒ Object
site:xxx.yyy.com
29 30 31 |
# File 'lib/query/engine/sogou.rb', line 29 def pages(host) query("site:#{host}") end |
.query(wd) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/query/engine/sogou.rb', line 10 def query(wd) q = [] q << "query=#{wd}" uri = URI.encode BaseUri+q.join('&') page = HTTParty.get(uri,Options) r = Query::Result::Sogou.new(page) r.baseuri = uri r.perpage = @perpage r.pagenumber = 1 r end |
.suggestions(word) ⇒ Object
22 23 24 25 26 |
# File 'lib/query/engine/sogou.rb', line 22 def suggestions(word) suggestions = HTTParty.get "http://w.sugg.sogou.com/sugg/ajaj_json.jsp?key=#{URI.encode(word)}" suggestions = suggestions.encode('utf-8').scan /#{word}[^"]+/ suggestions end |