autocomplete: recognize Japanese tags in autocomplete.

Allowing typing Japanese tags in autocomplete. For example, typing 東方
in autocomplete will be completed to the touhou tag. Typing ぶくぶ will
complete to the bkub tag.

This works using wiki page and artist other names. Effectively, any name
listed as an other name in a wiki or artist page will be treated like an
alias for autocomplete purposes. This is limited to non-ASCII other names,
to prevent English other names from interfering with regular tag searches.
This commit is contained in:
evazion
2020-12-14 16:48:21 -06:00
parent 23f6b8a46d
commit c02c31b966
3 changed files with 50 additions and 2 deletions

View File

@@ -97,6 +97,33 @@ class AutocompleteServiceTest < ActiveSupport::TestCase
assert_autocomplete_includes("mole_under_eye", "~/mue", :tag_query)
end
should "autocomplete tags from wiki and artist other names" do
create(:tag, name: "touhou")
create(:tag, name: "bkub", category: Tag.categories.artist)
create(:wiki_page, title: "touhou", other_names: %w[東方 东方 동방])
create(:artist, name: "bkub", other_names: %w[大川ぶくぶ フミンバイン])
assert_autocomplete_equals(["touhou"], "", :tag_query)
assert_autocomplete_equals(["touhou"], "", :tag_query)
assert_autocomplete_equals(["touhou"], "", :tag_query)
assert_autocomplete_equals(["touhou"], "*東*", :tag_query)
assert_autocomplete_equals(["touhou"], "東*", :tag_query)
assert_autocomplete_equals([], "*東", :tag_query)
assert_autocomplete_equals(["touhou"], "*方*", :tag_query)
assert_autocomplete_equals(["touhou"], "*方", :tag_query)
assert_autocomplete_equals([], "", :tag_query)
assert_autocomplete_equals(["bkub"], "*大*", :tag_query)
assert_autocomplete_equals(["bkub"], "", :tag_query)
assert_autocomplete_equals([], "*大", :tag_query)
assert_autocomplete_equals(["bkub"], "*川*", :tag_query)
assert_autocomplete_equals([], "*川", :tag_query)
assert_autocomplete_equals([], "", :tag_query)
end
should "autocomplete wildcard searches" do
create(:tag, name: "mole", post_count: 150)
create(:tag, name: "mole_under_eye", post_count: 100)