Fix #5194: AND/OR no longer trigger autocomplete.
Also change the /autocomplete.json API to no longer strip '-' and '~' from the start of the tag. This may be a breaking change if third-party scripts relied on this behavior.
This commit is contained in:
@@ -79,17 +79,12 @@ class AutocompleteService
|
|||||||
#
|
#
|
||||||
# @return [Array<Hash>] the autocomplete results
|
# @return [Array<Hash>] the autocomplete results
|
||||||
def autocomplete_tag_query
|
def autocomplete_tag_query
|
||||||
if parsed_query.tag_names.one?
|
if parsed_query.metatags.one?
|
||||||
tag = parsed_query.tag_names.first
|
|
||||||
autocomplete_tag(tag)
|
|
||||||
elsif parsed_query.wildcards.one?
|
|
||||||
wildcard = parsed_query.wildcards.first
|
|
||||||
autocomplete_tag(wildcard.name)
|
|
||||||
elsif parsed_query.metatags.one?
|
|
||||||
metatag = parsed_query.metatags.first
|
metatag = parsed_query.metatags.first
|
||||||
autocomplete_metatag(metatag.name, metatag.value)
|
autocomplete_metatag(metatag.name, metatag.value)
|
||||||
else
|
else
|
||||||
[]
|
tag = Tag.normalize_name(query)
|
||||||
|
autocomplete_tag(tag)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -351,7 +346,7 @@ class AutocompleteService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def parsed_query
|
def parsed_query
|
||||||
PostQuery.new(query.delete_prefix("-").delete_prefix("~"))
|
PostQuery.new(query)
|
||||||
end
|
end
|
||||||
|
|
||||||
memoize :autocomplete_results, :parsed_query
|
memoize :autocomplete_results, :parsed_query
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ class AutocompleteControllerTest < ActionDispatch::IntegrationTest
|
|||||||
context "index action" do
|
context "index action" do
|
||||||
setup do
|
setup do
|
||||||
create(:tag, name: "azur_lane")
|
create(:tag, name: "azur_lane")
|
||||||
|
create(:tag, name: "android")
|
||||||
|
create(:tag, name: "original")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "work for opensearch queries" do
|
should "work for opensearch queries" do
|
||||||
@@ -27,8 +29,6 @@ class AutocompleteControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
should "work for tag queries" do
|
should "work for tag queries" do
|
||||||
assert_autocomplete_equals(["azur_lane"], "azur", "tag_query")
|
assert_autocomplete_equals(["azur_lane"], "azur", "tag_query")
|
||||||
assert_autocomplete_equals(["azur_lane"], "-azur", "tag_query")
|
|
||||||
assert_autocomplete_equals(["azur_lane"], "~azur", "tag_query")
|
|
||||||
assert_autocomplete_equals(["azur_lane"], "AZUR", "tag_query")
|
assert_autocomplete_equals(["azur_lane"], "AZUR", "tag_query")
|
||||||
|
|
||||||
assert_autocomplete_equals(["rating:sensitive"], "rating:s", "tag_query")
|
assert_autocomplete_equals(["rating:sensitive"], "rating:s", "tag_query")
|
||||||
@@ -42,6 +42,11 @@ class AutocompleteControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_equal([], response.parsed_body)
|
assert_equal([], response.parsed_body)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "work for the AND and OR keywords" do
|
||||||
|
assert_autocomplete_equals(["android"], "and", "tag_query")
|
||||||
|
assert_autocomplete_equals(["original"], "or", "tag_query")
|
||||||
|
end
|
||||||
|
|
||||||
should "not set session cookies when the response is publicly cached" do
|
should "not set session cookies when the response is publicly cached" do
|
||||||
get autocomplete_index_path(search: { query: "azur", type: "tag_query" }), as: :json
|
get autocomplete_index_path(search: { query: "azur", type: "tag_query" }), as: :json
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user