Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Commit

Permalink
[#18] Replace Article#search_tank with guarded #search wrapper.
Browse files Browse the repository at this point in the history
If Searchify is down or otherwise inaccessible, the world ends. This
stops the world ending and returns an empty result set.
  • Loading branch information
Philip Hale committed Sep 1, 2013
1 parent 5e532cc commit 4924b8b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def index
# expand the query
query_final = Article.expand_query( query )
# perform the search
@results = Article.search_tank( query_final)#, :conditions => { :status => 'Published' } )
@results = Article.search(query_final)
# Log the search results
puts "search-request: IP:#{request.env['REMOTE_ADDR']}, params[:query]:#{query}, QUERY:#{query_final}, FIRST_RESULT:#{@results.first.title unless @results.empty?}, RESULTS_N:#{@results.size}"

Expand Down
15 changes: 7 additions & 8 deletions app/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ def self.find_by_friendly_id( friendly_id )
end

def self.search( query )
return Article.all if query == '' or query == ' '
self.search_tank query
end

def self.search_titles( query )
return Article.all if query == '' or query == ' '
self.search_tank( '__type:Article', :conditions => {:title => query })
begin
self.search_tank query
rescue SocketError
logger.error "Could not communicate with IndexTank service"
[]
end
end

def self.find_by_type( content_type )
Expand Down Expand Up @@ -194,7 +193,7 @@ def self.expand_query( query )
def related
Rails.cache.fetch("#{self.id}-related") {
return [] if wordcounts.empty?
(Article.search_tank(self.wordcounts.all(:order => 'count DESC', :limit => 10).map(&:keyword).map(&:name).join(" OR ")) - [self]).first(4)
(Article.search(self.wordcounts.all(:order => 'count DESC', :limit => 10).map(&:keyword).map(&:name).join(" OR ")) - [self]).first(4)
}
end

Expand Down

0 comments on commit 4924b8b

Please sign in to comment.