Skip to content

Commit

Permalink
using a much faster page loading system for correct hits. a little sl…
Browse files Browse the repository at this point in the history
…ower for searches
  • Loading branch information
Hampton Catlin committed Jan 25, 2009
1 parent deb83be commit acf5e1f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
5 changes: 2 additions & 3 deletions app/models/article.rb
Expand Up @@ -50,9 +50,8 @@ def html(device)
end

def fetch!(path = nil)
path ||= @path ||= "/wiki/Special:Search?search=#{escaped_title}"
super(path)
self
@paths ||= ["/wiki/#{escaped_title}", "/wiki/Special:Search?search=#{escaped_title}"]
super(*@paths)
end

end
26 changes: 17 additions & 9 deletions app/models/server.rb
Expand Up @@ -27,19 +27,27 @@ def file(title)
# In the future, this method might use a cache...
#
# paths must start with a /
def fetch(path)
begin
Merb.logger.debug("loading... " + base_url + path)
#
# You can pass in multiple paths, and it will try each one until it gets a 200
def fetch(*paths)
paths.each do |path|
begin
Merb.logger.debug("loading... " + base_url + path)

result = fetch_from_web(base_url, path)
result = fetch_from_web(base_url, path)

Merb.logger.debug("loaded #{result.downloaded_content_length} characters")
{:url => result.last_effective_url, :body => result.body_str}
Merb.logger.debug("loaded #{result.downloaded_content_length} characters")

rescue Curl::Err::HostResolutionError, Curl::Err::GotNothingError
Merb.logger.error("Could not connect to " + base_url + path)
return ""
if result.response_code == 200
return {:url => result.last_effective_url, :body => result.body_str}
end

rescue Curl::Err::HostResolutionError, Curl::Err::GotNothingError
Merb.logger.error("Could not connect to " + base_url + path)
end
end

return {}
end

private
Expand Down
6 changes: 3 additions & 3 deletions app/models/wikipedia_resource.rb
Expand Up @@ -36,9 +36,9 @@ def loaded?
@loaded
end

def fetch!(path = nil)
raise "No path Given" unless path
result = @server.fetch(path)
def fetch!(*paths)
raise "No path Given" unless paths.any?
result = @server.fetch(*paths)
self.path = URI.parse(result[:url]).path
@raw_html = result[:body]
@raw_document = Nokogiri::HTML(@raw_html)
Expand Down

0 comments on commit acf5e1f

Please sign in to comment.