Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search error when ElasticSearch is enabled but not available #11954

Merged
merged 3 commits into from Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions app/services/account_search_service.rb
Expand Up @@ -42,11 +42,9 @@ def search_results
return [] if limit_for_non_exact_results.zero?

@search_results ||= begin
if Chewy.enabled?
from_elasticsearch
else
from_database
end
results = from_elasticsearch if Chewy.enabled?
results ||= from_database
results
end
end

Expand Down Expand Up @@ -92,6 +90,8 @@ def from_elasticsearch
ActiveRecord::Associations::Preloader.new.preload(records, :account_stat)

records
rescue Faraday::ConnectionFailed, Parslet::ParseFailed
Gargron marked this conversation as resolved.
Show resolved Hide resolved
nil
end

def reputation_score_function
Expand Down
11 changes: 6 additions & 5 deletions app/services/tag_search_service.rb
Expand Up @@ -6,11 +6,10 @@ def call(query, options = {})
@offset = options[:offset].to_i
@limit = options[:limit].to_i

if Chewy.enabled?
from_elasticsearch
else
from_database
end
results = from_elasticsearch if Chewy.enabled?
results ||= from_database

results
end

private
Expand Down Expand Up @@ -74,6 +73,8 @@ def from_elasticsearch
}

TagsIndex.query(query).filter(filter).limit(@limit).offset(@offset).objects.compact
rescue Faraday::ConnectionFailed, Parslet::ParseFailed
nil
end

def from_database
Expand Down