diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index e2452dea8..611e66f1c 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -40,29 +40,13 @@ def index search_string = [] search_params = {} [[:username, username, username_operation], [:title, title, title_operation], - [:why, why, why_operation]].each do |si| + [:body, body, body_operation], [:why, why, why_operation]].each do |si| if si[1].present? && si[1] != '%%' search_string << "IFNULL(`posts`.`#{si[0]}`, '') #{si[2]} :#{si[0]}" search_params[si[0]] = si[1] end end - if body.present? - if ['LIKE', 'NOT LIKE'].include?(body_operation) && params[:body_is_like] != '1' - # If the operation would be LIKE, hijack it and use our fulltext index for a search instead. - # UNLESS... params[:body_is_like] is set, in which case the user has explicitly specified a LIKE query. - @results = @results.match_search(body, with_search_score: false, posts: :body) - else - if params[:body_is_like] == '1' && !user_signed_in? - flash[:warning] = 'Unregistered users cannot use LIKE searches on the body field. Please sign in.' - redirect_to(search_path) && return - end - # Otherwise, it's REGEX or NOT REGEX, which fulltext won't do - fall back on search_string and params - search_string << "IFNULL(`posts`.`body`, '') #{body_operation} :body" - search_params[:body] = body.present? ? body : '%%' - end - end - @results = @results.where(search_string.join(params[:or_search].present? ? ' OR ' : ' AND '), **search_params) .paginate(page: params[:page], per_page: per_page) .order(Arel.sql('`posts`.`created_at` DESC')) diff --git a/app/views/search/search.html.erb b/app/views/search/search.html.erb index 17517be50..5e3bdab9b 100644 --- a/app/views/search/search.html.erb +++ b/app/views/search/search.html.erb @@ -11,10 +11,6 @@
<%= label_tag :body %> - <%= check_box_tag :body_is_like, 1, params[:body_is_like] %> - - LIKE (?) - <% if current_user&.can_use_regex_search? %> <%= check_box_tag :body_is_regex, 1, params[:body_is_regex] %> regex <%= check_box_tag :body_is_inverse_regex, 1, params[:body_is_inverse_regex] %> invert diff --git a/db/migrate/20201121023305_drop_fulltext_index_of_posts.rb b/db/migrate/20201121023305_drop_fulltext_index_of_posts.rb new file mode 100644 index 000000000..46b5c6f6e --- /dev/null +++ b/db/migrate/20201121023305_drop_fulltext_index_of_posts.rb @@ -0,0 +1,5 @@ +class DropFulltextIndexOfPosts < ActiveRecord::Migration[5.2] + def change + remove_index :posts, :body + end +end