Skip to content

Commit

Permalink
AO3-5444 Searches with more results than the max should show the tota…
Browse files Browse the repository at this point in the history
…l number of results. (#3365)

* AO3-5462 Change the per_page function for TagQuery.

* AO3-5444 Search should always show the right count.

Pulls out the "x Found" text at the top of works, bookmarks, tags, and
people search into a single helper function search_results_found, which
uses the unlimited_total_entries field whenever it's available.
  • Loading branch information
tickinginstant authored and sarken committed Jul 6, 2018
1 parent 121346f commit b695d70
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 6 deletions.
10 changes: 10 additions & 0 deletions app/helpers/search_helper.rb
Expand Up @@ -39,6 +39,16 @@ def search_header(collection, search, item_name, parent=nil)
header.html_safe
end

def search_results_found(results)
# ES UPGRADE TRANSITION
# Remove the if statement and results.total_entries
count = if results.respond_to?(:unlimited_total_entries)
results.unlimited_total_entries
else
results.total_entries
end
ts("%{count} Found", count: count)
end

def random_search_tip
ArchiveConfig.SEARCH_TIPS[rand(ArchiveConfig.SEARCH_TIPS.size)]
Expand Down
2 changes: 1 addition & 1 deletion app/views/bookmarks/search_results.html.erb
Expand Up @@ -17,7 +17,7 @@
<% if @bookmarks.blank? %>
<p><%= ts("No results found. You may want to edit your search to make it less specific.") %></p>
<% else %>
<h3 class="heading"><%= @bookmarks.total_entries %> Found <%= link_to_help "bookmark-search-results-help" %></h3>
<h3 class="heading"><%= search_results_found(@bookmarks) %> <%= link_to_help "bookmark-search-results-help" %></h3>

<h3 class="landmark heading">Bookmarks List</h3>
<ol class="bookmark index group">
Expand Down
2 changes: 1 addition & 1 deletion app/views/people/search.html.erb
Expand Up @@ -10,7 +10,7 @@
<% end %>
<% if @people %>
<p><strong><%= @people.total_entries %> Found</strong></p>
<p><strong><%= search_results_found(@people) %></strong></p>
<h3 class="landmark heading">People List</h3>
<ol class="pseud index group">
<% for person in @people %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/tags/search.html.erb
Expand Up @@ -5,7 +5,7 @@
<%= render :partial => 'tags/search_form' %>
<% if @tags %>
<h3 class="heading"><%= @tags.total_entries %> Found <%= link_to_help "tag-search-results-help" %></h3>
<h3 class="heading"><%= search_results_found(@tags) %> <%= link_to_help "tag-search-results-help" %></h3>
<h4 class="landmark heading">Listing Tags</h4>
<ol class="tag index group">
<% for tag in @tags %>
Expand All @@ -15,4 +15,4 @@
<% end %>
</ol>
<%= will_paginate @tags %>
<% end %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/works/search_results.html.erb
Expand Up @@ -17,7 +17,7 @@
<% if @works.blank? %>
<p><%= ts("No results found. You may want to edit your search to make it less specific.") %></p>
<% else %>
<h3 class="heading"><%= @works.total_entries %> Found <%= link_to_help "work-search-results-help" %></h3>
<h3 class="heading"><%= search_results_found(@works) %> <%= link_to_help "work-search-results-help" %></h3>

<h3 class="landmark heading">Works List</h3>
<ol class="work index group">
Expand Down
48 changes: 48 additions & 0 deletions features/search/exceeding_maximum.feature
@@ -0,0 +1,48 @@
Feature: Large searches
As a user
I want to see how many results my search returns if it's more than the max

Scenario: Work search should show the correct number of results
Given a set of Kirk/Spock works for searching
And the max search result count is 2
And 1 item is displayed per page
When I search for works containing "James T. Kirk"
Then I should see "4 Found"

Scenario: Bookmark search should show the correct number of results
Given I have bookmarks to search
And the max search result count is 2
And 1 item is displayed per page
When I am on the search bookmarks page
And I select "Work" from "Type"
And I press "Search Bookmarks"
Then I should see "5 Found"

@new-search
Scenario: People search should show the correct number of results
Given the following activated users exist
| login |
| test_alice |
| test_betsy |
| test_carol |
| test_diana |
And the max search result count is 2
And 1 item is displayed per page
And all indexing jobs have been run
When I go to the search people page
And I fill in "Search all fields" with "test"
And I press "Search People"
Then I should see "4 Found"

@new-search
Scenario: Tag search should show the correct number of results
Given a canonical freeform "Fluff"
And a canonical freeform "Angst"
And a canonical freeform "Smut"
And a canonical freeform "Alternate Universe"
And the max search result count is 2
And 1 tag is displayed per search page
When I go to the search tags page
And I select "Freeform" from "query[type]"
And I press "Search tags"
Then I should see "4 Found"
7 changes: 6 additions & 1 deletion features/step_definitions/search_steps.rb
Expand Up @@ -51,11 +51,16 @@
ArchiveConfig.MAX_SEARCH_RESULTS = max.to_i
end

Given /^(\d+) items are displayed per page$/ do |per_page|
Given /^(\d+) item(?:s)? (?:is|are) displayed per page$/ do |per_page|
stub_const("ArchiveConfig", OpenStruct.new(ArchiveConfig))
ArchiveConfig.ITEMS_PER_PAGE = per_page.to_i
end

Given /^(\d+) tag(?:s)? (?:is|are) displayed per search page$/ do |per_page|
stub_const("ArchiveConfig", OpenStruct.new(ArchiveConfig))
ArchiveConfig.TAGS_PER_SEARCH_PAGE = per_page.to_i
end

When /^(\w+) can use the new search/ do |login|
user = User.find_by(login: login)
$rollout.activate_user(:use_new_search, user)
Expand Down

0 comments on commit b695d70

Please sign in to comment.