Skip to content

Commit

Permalink
Merge pull request #1654 from danidoni/do-not-crash-when-there-is-no-…
Browse files Browse the repository at this point in the history
…query-param-on-the-search

Do not crash when there is no query param on the search
  • Loading branch information
hennevogel authored Oct 8, 2024
2 parents 955f738 + 5ed644a commit 1173e80
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
class SearchController < ApplicationController
skip_before_action :authenticate_user!, only: [:result]

def result
# First search in morphology mode, if fails — retry in wildcard mode
search_query = ThinkingSphinx::Query.escape(params[:query])
if @episode.to_param == 'all'
@projects = Project.search search_query
@projects = Project.search search_query, star: true if @projects.empty?
else
@projects = Project.search search_query, with: { episode_ids: params[:episode].to_i }
if @projects.empty?
@projects = Project.search search_query, with: { episode_ids: params[:episode].to_i }, star: true
if params[:query]
# First search in morphology mode, if fails — retry in wildcard mode
search_query = ThinkingSphinx::Query.escape(params[:query])
if @episode.to_param == 'all'
@projects = Project.search search_query
@projects = Project.search search_query, star: true if @projects.empty?
else
@projects = Project.search search_query, with: { episode_ids: params[:episode].to_i }
if @projects.empty?
@projects = Project.search search_query, with: { episode_ids: params[:episode].to_i }, star: true
end
end
end

@users = User.search search_query
@users = User.search search_query, star: true if @users.empty?
@users = User.search search_query
@users = User.search search_query, star: true if @users.empty?
else
@projects = []
@users = []
end
end

def keyword
Expand Down

0 comments on commit 1173e80

Please sign in to comment.