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

AO3-6541 Update Works search and filters to use "Creator" instead of "Author/Artist" #4553

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions app/models/download_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,19 @@ def get_zip_command
# A hash of the work data calibre needs
def meta
return @metadata if @metadata
# Using ampersands as instructed by Calibre's ebook-convert documentation
# hides all but the first author name in Books (formerly iBooks). The
# other authors cannot be used for searching or sorting. Using commas
# just means Calibre's GUI treats it as one name, e.g. "testy, testy2" is
# like "Fangirl, Suzy Q", for searching and sorting.

# We add "Fanworks" because Books uses the first tag as the category and
# it would otherwise be the work's rating, which is weird.
@metadata = {
title: work.title,
sortable_title: work.sorted_title,
# Using ampersands as instructed by Calibre's ebook-convert documentation
# hides all but the first author name in Books (formerly iBooks). The
# other authors cannot be used for searching or sorting. Using commas
# just means Calibre's GUI treats it as one name, e.g. "testy, testy2" is
# like "Fangirl, Suzy Q", for searching and sorting.
authors: download.authors,
sortable_authors: work.authors_to_sort_on,
# We add "Fanworks" because Books uses the first tag as the category and
# it would otherwise be the work's rating, which is weird.
tags: "Fanworks, " + work.tags.pluck(:name).join(", "),
pubdate: work.revised_at.to_date.to_s,
summary: work.summary.to_s,
Expand Down
12 changes: 6 additions & 6 deletions app/models/search/query_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ class QueryCleaner
attr_reader :params

SORT_OPTIONS = [
['Author', 'authors_to_sort_on'],
['Title', 'title_to_sort_on'],
%w[Creator authors_to_sort_on],
%w[Title title_to_sort_on],
['Date Posted', 'created_at'],
['Date Updated', 'revised_at'],
['Word Count', 'word_count'],
['Hits', 'hits'],
['Kudos', 'kudos_count'],
['Comments', 'comments_count'],
['Bookmarks', 'bookmarks_count']
%w[Hits hits],
%w[Kudos kudos_count],
%w[Comments comments_count],
%w[Bookmarks bookmarks_count]
].freeze

def initialize(params = {})
Expand Down
26 changes: 13 additions & 13 deletions app/models/search/work_search_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class WorkSearchForm
:sort_column,
:sort_direction,
:page
]
].freeze

attr_accessor :options

Expand Down Expand Up @@ -125,7 +125,7 @@ def summary
summary << "Title: #{@options[:title]}"
end
if @options[:creators].present?
summary << "Author/Artist: #{@options[:creators]}"
summary << "Creator: #{@options[:creators]}"
end
tags = @searcher.included_tag_names
all_tag_ids = @searcher.filter_ids
Expand Down Expand Up @@ -181,16 +181,16 @@ def search_results
###############

SORT_OPTIONS = [
['Best Match', '_score'],
['Author', 'authors_to_sort_on'],
['Title', 'title_to_sort_on'],
['Date Posted', 'created_at'],
['Date Updated', 'revised_at'],
['Word Count', 'word_count'],
['Hits', 'hits'],
['Kudos', 'kudos_count'],
['Comments', 'comments_count'],
['Bookmarks', 'bookmarks_count']
["Best Match", "_score"],
%w[Creator authors_to_sort_on],
forceofcalm marked this conversation as resolved.
Show resolved Hide resolved
%w[Title title_to_sort_on],
["Date Posted", "created_at"],
["Date Updated", "revised_at"],
["Word Count", "word_count"],
%w[Hits hits],
%w[Kudos kudos_count],
%w[Comments comments_count],
%w[Bookmarks bookmarks_count]
].freeze

def sort_columns
Expand Down Expand Up @@ -219,7 +219,7 @@ def default_sort_column
end

def default_sort_direction
if %w(authors_to_sort_on title_to_sort_on).include?(sort_column)
if %w[authors_to_sort_on title_to_sort_on].include?(sort_column)
'asc'
else
'desc'
Expand Down
12 changes: 10 additions & 2 deletions app/views/collection_mailer/item_added_notification.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

<% pseuds = @creation.is_a?(Work) ? @creation.pseuds.map{|p| style_pseud_link(p)}.to_sentence.html_safe : @creation.pseud.name %>

<%= @creation.is_a?(Work) ? @creation.pseuds.length > 0 ? pseuds : style_bold(@creation.authors_to_sort_on) : pseuds %> posted a
<%= @creation.is_a?(Work) ? @creation.backdate ? "backdated " : "new " : "new " %> <%= @creation.is_a?(Work) ? "work" : "bookmark" %> to your collection,
<% if @creation.is_a?(Work) %>
<% if [email protected]? %>
<%= pseuds %>
<% else %>
<%= style_bold(@creation.authors_to_sort_on) %>
<% end %>
<% else %>
<%= pseuds %>
<% end %> posted a
<%= @creation.is_a?(Work) and @creation.backdate ? "backdated " : "new " %> <%= @creation.is_a?(Work) ? "work" : "bookmark" %> to your collection,
<b><%= style_link(@collection.name, collection_url(@collection)) %></b>:

<br>
Expand Down
2 changes: 1 addition & 1 deletion app/views/works/_search_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<%= f.text_field :title %>
</dd>
<dt>
<%= f.label :creators, ts("Author/Artist") %>
<%= f.label :creators, t(".creator") %>
</dt>
<dd>
<%= f.text_field :creators %>
Expand Down
2 changes: 2 additions & 0 deletions config/locales/views/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,8 @@ en:
multiple_works_restricted: Only show to registered users
restricted: Only show your work to registered users
unrestricted: Show to all
search_form:
creator: Creator
show:
unposted_deletion_notice_html: This work is a draft and has not been posted. The draft will be <strong>scheduled for deletion</strong> on %{deletion_date}.
work_approved_children:
Expand Down
14 changes: 7 additions & 7 deletions features/search/works_anonymous.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: Search anonymous works
Then I should see "You searched for: mod1"
And I should see "No results found"
When I search for works by "mod1"
Then I should see "You searched for: creator: mod1"
Then I should see "You searched for: Creator: mod1"
And I should see "No results found"

Scenario: Works that are anonymous should show up in searches for the
Expand All @@ -22,13 +22,13 @@ Feature: Search anonymous works
And I should see "1 Found"
And I should see "Fulfilled Story-thing"
When I search for works by "Anonymous"
Then I should see "You searched for: creator: Anonymous"
Then I should see "You searched for: Creator: Anonymous"
And I should see "1 Found"
And I should see "Fulfilled Story-thing"
When I go to the search works page
And I fill in "Author/Artist" with "Anonymous"
And I fill in "Creator" with "Anonymous"
And I press "Search" within "#new_work_search"
Then I should see "You searched for: Author/Artist: Anonymous"
Then I should see "You searched for: Creator: Anonymous"
And I should see "1 Found"
And I should see "Fulfilled Story-thing"

Expand All @@ -41,12 +41,12 @@ Feature: Search anonymous works
And I should see "1 Found"
And I should see "Fulfilled Story-thing"
When I search for works by "mod1"
Then I should see "You searched for: creator: mod1"
Then I should see "You searched for: Creator: mod1"
And I should see "1 Found"
And I should see "Fulfilled Story-thing"
When I go to the search works page
And I fill in "Author/Artist" with "mod1"
And I fill in "Creator" with "mod1"
And I press "Search" within "#new_work_search"
Then I should see "You searched for: Author/Artist: mod1"
Then I should see "You searched for: Creator: mod1"
And I should see "1 Found"
And I should see "Fulfilled Story-thing"
6 changes: 3 additions & 3 deletions features/search/works_info.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Feature: Search works by work info
Then I should see "You searched for: word count: >15000 revised at: > 2 years ago"
And I should see "No results found"

Scenario: Search with the header search field and then refine by author/artist
Scenario: Search with the header search field and then refine by creator
Given I have the Battle set loaded
When I fill in "site_search" with "testuser2"
And I press "Search"
Expand All @@ -54,9 +54,9 @@ Feature: Search works by work info
Then I should be on the search works page
And the field labeled "Any Field" should contain "testuser2"
When I fill in "Any Field" with ""
And I fill in "Author/Artist" with "testuser2"
And I fill in "Creator" with "testuser2"
And I press "Search" within "#new_work_search"
Then I should see "You searched for: Author/Artist: testuser2"
Then I should see "You searched for: Creator: testuser2"
And I should see "3 Found"
And I should see "fourth"
And I should see "fifth"
Expand Down
2 changes: 1 addition & 1 deletion public/help/work-search-text-help.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ <h4>Work Search: Any Field</h4>

<p>Searches all the fields associated with a work in the database, including summary, notes and tags, but not the full work text.</p>

<p>The characters ":" and "@" have special meanings. Leave them out of your search or you will get unexpected results. Like in the Title and Author/Artist field, you can use the following operators to combine your search terms:</p>
<p>The characters ":" and "@" have special meanings. Leave them out of your search or you will get unexpected results. Like in the Title and Creator field, you can use the following operators to combine your search terms:</p>

<dl>
<dt>*: any characters </dt>
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/works/default_rails_actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def call_with_params(params)
{ query: "sort by: word count", expected: "word_count" },
{ query: "sort by: words", expected: "word_count" },
{ query: "sort by: word", expected: "word_count" },
{ query: "sort by: author", expected: "authors_to_sort_on" },
{ query: "sort by: creator", expected: "authors_to_sort_on" },
{ query: "sort by: title", expected: "title_to_sort_on" },
{ query: "sort by: date", expected: "created_at" },
{ query: "sort by: date posted", expected: "created_at" },
Expand Down
4 changes: 2 additions & 2 deletions spec/models/search/query_cleaner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
expect(clean_params[:sort_direction]).to eq("desc")
end

it "should extract author sorting from a query" do
cleaner = QueryCleaner.new(query: "sorted by:>author")
it "should extract creator sorting from a query" do
cleaner = QueryCleaner.new(query: "sorted by:>creator")
clean_params = cleaner.clean
expect(clean_params[:query]).to eq(nil)
expect(clean_params[:sort_column]).to eq("authors_to_sort_on")
Expand Down
2 changes: 1 addition & 1 deletion spec/models/search/work_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
expect(q.generated_query[:sort]).to eq([{ "_score" => { order: "desc" } }, { id: { order: "desc" } }])
end

it "allows sorting by creator name" do
it "should allow you to sort by creator name" do
q = WorkQuery.new(sort_column: "authors_to_sort_on", sort_direction: "asc")
expect(q.generated_query[:sort]).to eq([{ "authors_to_sort_on" => { order: "asc" } }, { id: { order: "asc" } }])
end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/search/work_search_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -604,14 +604,14 @@

it "returns all works in the correct order of sortable pseud values" do
work_search = WorkSearchForm.new(sort_column: "authors_to_sort_on")
expect(work_search.search_results.map(&:authors_to_sort_on)).to eq ["cioelle", "ruth"]
expect(work_search.search_results.map(&:authors_to_sort_on)).to eq %w[cioelle ruth]

user_1.login = "yabalchoath"
user_1.save!
run_all_indexing_jobs

work_search = WorkSearchForm.new(sort_column: "authors_to_sort_on")
expect(work_search.search_results.map(&:authors_to_sort_on)).to eq ["ruth", "yabalchoath"]
expect(work_search.search_results.map(&:authors_to_sort_on)).to eq %w[ruth yabalchoath]
end
end

Expand Down