forked from e621ng/e621ng
[TagQuery] Improve description search
These all works: * description:test * description:"multiple words followed by each other" * description:"multiple words followed by each oth*"
This commit is contained in:
parent
097d7461a1
commit
b2c7b338c0
@ -185,8 +185,8 @@ class ElasticPostQueryBuilder
|
||||
add_array_relation(:rating, :rating)
|
||||
add_array_relation(:filetype, :file_ext)
|
||||
add_array_relation(:delreason, :del_reason, action: :wildcard)
|
||||
add_array_relation(:description, :description, action: :match)
|
||||
add_array_relation(:note, :notes, action: :match)
|
||||
add_array_relation(:description, :description, action: :match_phrase_prefix)
|
||||
add_array_relation(:note, :notes, action: :match_phrase_prefix)
|
||||
add_array_relation(:sources, :source, any_none_key: :source, action: :wildcard)
|
||||
add_array_relation(:deleter, :deleter)
|
||||
add_array_relation(:upvote, :upvotes)
|
||||
|
@ -60,7 +60,7 @@ class TagQuery
|
||||
end
|
||||
|
||||
def self.normalize(query)
|
||||
tags = TagQuery.scan(query.to_s)
|
||||
tags = TagQuery.scan(query)
|
||||
tags = tags.map { |t| Tag.normalize_name(t) }
|
||||
tags = TagAlias.to_aliased(tags)
|
||||
tags.sort.uniq.join(" ")
|
||||
@ -68,8 +68,12 @@ class TagQuery
|
||||
|
||||
def self.scan(query)
|
||||
tagstr = query.to_s.unicode_normalize(:nfc).strip
|
||||
list = tagstr.scan(/-?source:".*?"/) || []
|
||||
list + tagstr.gsub(/-?source:".*?"/, "").scan(/[^[:space:]]+/).uniq
|
||||
quote_delimited = []
|
||||
tagstr = tagstr.gsub(/[-~]?\w*?:".*?"/) do |match|
|
||||
quote_delimited << match
|
||||
""
|
||||
end
|
||||
quote_delimited + tagstr.split.uniq
|
||||
end
|
||||
|
||||
def self.has_metatag?(tags, *)
|
||||
@ -99,6 +103,9 @@ class TagQuery
|
||||
next
|
||||
end
|
||||
|
||||
# Remove quotes from description:"abc def"
|
||||
g2 = g2.delete_prefix('"').delete_suffix('"')
|
||||
|
||||
type = metatag_name.start_with?("-") ? :must_not : :must
|
||||
case metatag_name.downcase
|
||||
when "user", "-user"
|
||||
@ -226,8 +233,7 @@ class TagQuery
|
||||
|
||||
when "source", "-source"
|
||||
add_to_query(type, :sources, any_none_key: :source, value: g2, wildcard: true) do
|
||||
src = g2.gsub(/\A"(.*)"\Z/, '\1')
|
||||
"#{src}*"
|
||||
"#{g2}*"
|
||||
end
|
||||
|
||||
when "date", "-date"
|
||||
|
@ -4,6 +4,7 @@ class TagQueryTest < ActiveSupport::TestCase
|
||||
should "scan a query" do
|
||||
assert_equal(%w[aaa bbb], TagQuery.scan("aaa bbb"))
|
||||
assert_equal(%w[~AAa -BBB* -bbb*], TagQuery.scan("~AAa -BBB* -bbb*"))
|
||||
assert_equal(['test:"with spaces"', "aaa", "def"], TagQuery.scan('aaa test:"with spaces" def'))
|
||||
end
|
||||
|
||||
should "not strip out valid characters when scanning" do
|
||||
|
Loading…
Reference in New Issue
Block a user