Method: Query::Engine::SMobile.query

Defined in:
lib/query/engine/sm_mobile.rb

.query(wd, params = {}) ⇒ Object

基本查询,相当于从搜索框直接输入关键词查询



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/query/engine/sm_mobile.rb', line 11

def self.query(wd, params={})
  q = Array.new
  q << "q=#{URI.encode(wd)}"
  #q << "rn=#{@perpage.to_i}" if @perpage
  # Join arguments
  params.each do |k, v|
    q << "#{k.to_s}=#{v.to_s}"
  end
  uri = URI::HTTP.build(:host=>Host,:path=>'/s',:query=>q.join('&'))
  # begin
    res = HTTParty.get(uri, Options)
    r = Query::Result::SMobile.new(res)
    r.baseuri, r.options = uri, Options  
    r
  # rescue Exception => e
      # warn "#{__FILE__} #{__LINE__} #{uri} fetch error: #{e.to_s}"
      # return false
  # end
end