4 ms·
For anyone interested, this Ruby code will get you started hacking in the HNSearch API right away. Gets JSON response for @query and puts it into an array of su
by mopatches 15y ago
For anyone interested, this Ruby code will get you started hacking in the HNSearch API right away. Gets JSON response for @query and puts it into an array of submission hashes (@results):
require 'net/http'
require 'uri'
require 'json'
@query = “facebook”
url = "http://api.thriftdb.com/api.hnsearch.com/items/_search?q=#{CGI::escape(@query)}&pretty_print=true&limit=30&filter[fields][type][]=submission&sortby=create_ts%20desc&highlight[markup_items]=true&weights[title]=1&weights[text]=0&weights[domain]=0&weights[username]=0.5&weights[type]=0 http://api.thriftdb.com/api.hnsearch.com/items/_search?q=#{C...
doc = Net::HTTP.get URI.parse(url)
jdoc = JSON.parse(doc)
jdoc["results"].each do |result_hash|
@results << result_hash["item"]
end