wiki pages: fix redirects to exact matches during search.
Change wiki page search to redirect to exact matches only when using the quick search bar. Fixes searches sometimes unexpectedly redirecting when doing a regular (non-quick) search that happens to return a single result. Also remove the logic that tries to expand the search when no results are found. This will eventually be replaced with a smarter "did you mean?" search.
This commit is contained in:
@@ -17,16 +17,11 @@ class WikiPagesController < ApplicationController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
@wiki_pages = WikiPage.paginated_search(params)
|
@wiki_pages = WikiPage.paginated_search(params)
|
||||||
respond_with(@wiki_pages) do |format|
|
|
||||||
format.html do
|
if params[:redirect].to_s.truthy? && @wiki_pages.one?
|
||||||
if params[:page].nil? || params[:page].to_i == 1
|
redirect_to @wiki_pages.first
|
||||||
if @wiki_pages.length == 1
|
else
|
||||||
redirect_to(wiki_page_path(@wiki_pages.first))
|
respond_with(@wiki_pages)
|
||||||
elsif @wiki_pages.length == 0 && params[:search][:title].present? && params[:search][:title] !~ /\*/
|
|
||||||
redirect_to(wiki_pages_path(:search => {:title => "*#{params[:search][:title]}*"}))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -164,7 +164,8 @@ module ApplicationHelper
|
|||||||
def quick_search_form_for(attribute, url, name, autocomplete: nil, &block)
|
def quick_search_form_for(attribute, url, name, autocomplete: nil, &block)
|
||||||
tag.li do
|
tag.li do
|
||||||
search_form_for(url, classes: "quick-search-form one-line-form") do |f|
|
search_form_for(url, classes: "quick-search-form one-line-form") do |f|
|
||||||
f.input attribute, label: false, placeholder: "Search #{name}", input_html: { id: nil, "data-autocomplete": autocomplete }
|
out = tag.input type: :hidden, name: :redirect, value: "1"
|
||||||
|
out += f.input attribute, label: false, placeholder: "Search #{name}", input_html: { id: nil, "data-autocomplete": autocomplete }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<%= nav_link_to("Implications", tag_implications_path) %>
|
<%= nav_link_to("Implications", tag_implications_path) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= nav_link_to("Pools", gallery_pools_path) %>
|
<%= nav_link_to("Pools", gallery_pools_path) %>
|
||||||
<%= nav_link_to("Wiki", wiki_pages_path(:title => "help:home")) %>
|
<%= nav_link_to("Wiki", wiki_page_path("help:home")) %>
|
||||||
<%= nav_link_to("Forum", forum_topics_path, :class => (CurrentUser.has_forum_been_updated? ? "forum-updated" : nil)) %>
|
<%= nav_link_to("Forum", forum_topics_path, :class => (CurrentUser.has_forum_been_updated? ? "forum-updated" : nil)) %>
|
||||||
<% if CurrentUser.is_moderator? %>
|
<% if CurrentUser.is_moderator? %>
|
||||||
<%= nav_link_to("Dashboard", moderator_dashboard_path) %>
|
<%= nav_link_to("Dashboard", moderator_dashboard_path) %>
|
||||||
|
|||||||
@@ -22,12 +22,14 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
should "list all wiki_pages (with search)" do
|
should "list all wiki_pages (with search)" do
|
||||||
get wiki_pages_path, params: {:search => {:title => "abc"}}
|
get wiki_pages_path, params: {:search => {:title => "abc"}}
|
||||||
assert_redirected_to(wiki_page_path(@wiki_page_abc))
|
assert_response :success
|
||||||
|
assert_select "tr td:first-child", text: "abc"
|
||||||
end
|
end
|
||||||
|
|
||||||
should "list wiki_pages without tags with order=post_count" do
|
should "list wiki_pages without tags with order=post_count" do
|
||||||
get wiki_pages_path, params: {:search => {:title => "abc", :order => "post_count"}}
|
get wiki_pages_path, params: {:search => {:title => "abc", :order => "post_count"}}
|
||||||
assert_redirected_to(wiki_page_path(@wiki_page_abc))
|
assert_response :success
|
||||||
|
assert_select "tr td:first-child", text: "abc"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user