search: apply aliases after parsing searches.

Make PostQueryBuilder apply aliases earlier, immediately after parsing
the search.

On the post index page there are multiple places where we need to apply
aliases:

* When running the search with PostQueryBuilder#build.
* When calculating the search count with PostQueryBuilder#fast_count.
* When calculating the related tags for the sidebar.
* When tracking missed searches and popular searches for Reportbooru.
* When looking up wiki excerpts.

Applying aliases after parsing ensures we only have to apply aliases
once for all of these things.

We also normalize the order of tags in searches and strip repeated tags.
This is so that we have consistent cache keys for fast_count.

* Fixes searches for aliased tags being counted as missed searches (fixes #4433).
* Fixes wiki excerpts not showing up when searching for aliased tags.
This commit is contained in:
evazion
2020-05-07 13:30:04 -05:00
parent f38c38f26e
commit 67aab0236d
13 changed files with 72 additions and 56 deletions

View File

@@ -68,6 +68,17 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
assert_select "#show-excerpt-link", count: 0
end
should "render for an aliased tag" do
create(:tag_alias, antecedent_name: "/lav", consequent_name: "looking_at_viewer")
as(@user) { create(:wiki_page, title: "looking_at_viewer") }
@post = create(:post, tag_string: "looking_at_viewer", rating: "s")
get posts_path, params: { tags: "/lav" }
assert_response :success
assert_select "#post_#{@post.id}", count: 1
assert_select "#excerpt .wiki-link[href='/wiki_pages/looking_at_viewer']", count: 1
end
should "render for a wildcard tag search" do
create(:post, tag_string: "1girl solo")
get posts_path(tags: "*girl*")