Fix #4406: Add "commentary:" metasearch.
Add: * commentary:true (posts with commentary) * commentary:false (posts without commentary) * commentary:translated (posts with translated commentary) * commentary:untranslated (posts with untranslated commentary) * commentary:"text" (posts where any commentary field matches "text") Known issues: * There's no way to escape the true, false, translated, or untranslated keywords to do a literal text search for commentaries containing one of these keywords. * Negated searches may be slow. Using a left outer join instead of a subquery would be faster in most cases, but negating it is harder.
This commit is contained in:
@@ -27,6 +27,7 @@ class PostQueryBuilder
|
||||
-ordfav ordfav
|
||||
-favgroup favgroup
|
||||
-pool pool ordpool
|
||||
-commentary commentary
|
||||
-id id
|
||||
-rating rating
|
||||
-locked locked
|
||||
@@ -186,6 +187,21 @@ class PostQueryBuilder
|
||||
relation
|
||||
end
|
||||
|
||||
def commentary_matches(query)
|
||||
case query
|
||||
when "none", "false"
|
||||
Post.where.not(artist_commentary: ArtistCommentary.all).or(Post.where(artist_commentary: ArtistCommentary.deleted))
|
||||
when "any", "true"
|
||||
Post.where(artist_commentary: ArtistCommentary.undeleted)
|
||||
when "translated"
|
||||
Post.where(artist_commentary: ArtistCommentary.translated)
|
||||
when "untranslated"
|
||||
Post.where(artist_commentary: ArtistCommentary.untranslated)
|
||||
else
|
||||
Post.where(artist_commentary: ArtistCommentary.text_matches(query))
|
||||
end
|
||||
end
|
||||
|
||||
def table_for_metatag(metatag)
|
||||
if metatag.in?(COUNT_METATAGS)
|
||||
metatag[/(?<table>[a-z]+)_count\z/i, :table]
|
||||
@@ -346,6 +362,14 @@ class PostQueryBuilder
|
||||
end
|
||||
end
|
||||
|
||||
q[:commentary_neg].to_a.each do |query|
|
||||
relation = relation.merge(commentary_matches(query).negate)
|
||||
end
|
||||
|
||||
q[:commentary].to_a.each do |query|
|
||||
relation = relation.merge(commentary_matches(query))
|
||||
end
|
||||
|
||||
if q[:saved_searches]
|
||||
relation = add_saved_search_relation(q[:saved_searches], relation)
|
||||
end
|
||||
@@ -731,8 +755,8 @@ class PostQueryBuilder
|
||||
class_methods do
|
||||
def scan_query(query, strip_metatags: false)
|
||||
tagstr = query.to_s.gsub(/\u3000/, " ").strip
|
||||
list = tagstr.scan(/-?source:".*?"/) || []
|
||||
list += tagstr.gsub(/-?source:".*?"/, "").scan(/[^[:space:]]+/).uniq
|
||||
list = tagstr.scan(/-?(?:source|commentary):".*?"/) || []
|
||||
list += tagstr.gsub(/-?(?:source|commentary):".*?"/, "").scan(/[^[:space:]]+/).uniq
|
||||
list = list.map { |tag| tag.sub(/^[-~]/, "") } if strip_metatags
|
||||
list
|
||||
end
|
||||
@@ -867,6 +891,14 @@ class PostQueryBuilder
|
||||
q[:ordfav] ||= []
|
||||
q[:ordfav] << g2
|
||||
|
||||
when "-commentary"
|
||||
q[:commentary_neg] ||= []
|
||||
q[:commentary_neg] << g2.gsub(/\A"(.*)"\Z/, '\1')
|
||||
|
||||
when "commentary"
|
||||
q[:commentary] ||= []
|
||||
q[:commentary] << g2.gsub(/\A"(.*)"\Z/, '\1')
|
||||
|
||||
when "search"
|
||||
q[:saved_searches] ||= []
|
||||
q[:saved_searches] << g2
|
||||
|
||||
Reference in New Issue
Block a user