forked from e621ng/e621ng
Add a few boolean search tags
This commit is contained in:
parent
512b00d321
commit
c6b1046fc5
@ -251,7 +251,7 @@ module PostIndex
|
||||
rating: rating,
|
||||
file_ext: file_ext,
|
||||
source: source_array,
|
||||
description: description,
|
||||
description: description.present? ? description : nil,
|
||||
|
||||
rating_locked: is_rating_locked,
|
||||
note_locked: is_note_locked,
|
||||
|
@ -412,28 +412,36 @@ class ElasticPostQueryBuilder
|
||||
must.push({term: {status_locked: false}})
|
||||
end
|
||||
|
||||
if q.include?(:ratinglocked)
|
||||
must.push({term: {rating_locked: q[:ratinglocked]}})
|
||||
end
|
||||
|
||||
if q.include?(:notelocked)
|
||||
must.push({term: {note_locked: q[:notelocked]}})
|
||||
end
|
||||
|
||||
if q.include?(:statuslocked)
|
||||
must.push({term: {status_locked: q[:statuslocked]}})
|
||||
end
|
||||
|
||||
if q.include?(:hassource)
|
||||
(q[:hassource] ? must : must_not).push({exists: {field: :source}})
|
||||
end
|
||||
|
||||
if q.include?(:hasdescription)
|
||||
(q[:hasdescription] ? must : must_not).push({exists: {field: :description}})
|
||||
end
|
||||
|
||||
if q.include?(:ischild)
|
||||
(q[:ischild] ? must : must_not).push({exists: {field: :parent}})
|
||||
end
|
||||
|
||||
if q.include?(:isparent)
|
||||
must.push({term: {has_children: q[:isparent]}})
|
||||
end
|
||||
|
||||
add_tag_string_search_relation(q[:tags], must)
|
||||
|
||||
if q[:favgroups_neg].present?
|
||||
q[:favgroups_neg].each do |favgroup_rec|
|
||||
favgroup_id = favgroup_rec.to_i
|
||||
favgroup = FavoriteGroup.where("favorite_groups.id = ?", favgroup_id).first
|
||||
if favgroup
|
||||
must_not.push({terms: {id: favgroup.post_id_array}})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if q[:favgroups].present?
|
||||
q[:favgroups].each do |favgroup_rec|
|
||||
favgroup_id = favgroup_rec.to_i
|
||||
favgroup = FavoriteGroup.where("favorite_groups.id = ?", favgroup_id).first
|
||||
if favgroup
|
||||
must.push({terms: {id: favgroup.post_id_array}})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if q[:upvote].present?
|
||||
must.push({term: {upvotes: q[:upvote].to_i}})
|
||||
end
|
||||
|
@ -1,16 +1,17 @@
|
||||
class Tag < ApplicationRecord
|
||||
COSINE_SIMILARITY_RELATED_TAG_THRESHOLD = 300
|
||||
COUNT_METATAGS = %w[
|
||||
comment_count deleted_comment_count active_comment_count
|
||||
note_count deleted_note_count active_note_count
|
||||
flag_count resolved_flag_count unresolved_flag_count
|
||||
child_count deleted_child_count active_child_count
|
||||
pool_count deleted_pool_count active_pool_count series_pool_count collection_pool_count
|
||||
appeal_count approval_count replacement_count
|
||||
comment_count
|
||||
note_count
|
||||
flag_count
|
||||
child_count
|
||||
pool_count
|
||||
]
|
||||
|
||||
# allow e.g. `deleted_comments` as a synonym for `deleted_comment_count`
|
||||
COUNT_METATAG_SYNONYMS = COUNT_METATAGS.map {|str| str.delete_suffix("_count").pluralize}
|
||||
BOOLEAN_METATAGS = %w[
|
||||
hassource hasdescription ratinglocked notelocked statuslocked
|
||||
tagslocked hideanon hidegoogle isparent ischild
|
||||
]
|
||||
|
||||
METATAGS = %w[
|
||||
-user user -approver approver commenter comm noter noteupdater artcomm
|
||||
@ -21,7 +22,7 @@ class Tag < ApplicationRecord
|
||||
-flagger appealer -appealer disapproval -disapproval set -set randseed -voted
|
||||
-upvote -downvote description -description change -user_id user_id delreason -delreason
|
||||
deletedby -deletedby
|
||||
] + TagCategory.short_name_list.map {|x| "#{x}tags"} + COUNT_METATAGS + COUNT_METATAG_SYNONYMS
|
||||
] + TagCategory.short_name_list.map {|x| "#{x}tags"} + COUNT_METATAGS + BOOLEAN_METATAGS
|
||||
|
||||
SUBQUERY_METATAGS = %w[commenter comm noter noteupdater artcomm flagger -flagger appealer -appealer]
|
||||
|
||||
@ -45,7 +46,6 @@ class Tag < ApplicationRecord
|
||||
custom
|
||||
] +
|
||||
COUNT_METATAGS +
|
||||
COUNT_METATAG_SYNONYMS.flat_map {|str| [str, "#{str}_asc"]} +
|
||||
TagCategory.short_name_list.flat_map {|str| ["#{str}tags", "#{str}tags_asc"]}
|
||||
|
||||
has_one :wiki_page, :foreign_key => "title", :primary_key => "name"
|
||||
@ -550,6 +550,10 @@ class Tag < ApplicationRecord
|
||||
matches
|
||||
end
|
||||
|
||||
def parse_boolean(value)
|
||||
value&.downcase == 'true'
|
||||
end
|
||||
|
||||
def parse_tag(tag, output)
|
||||
if tag[0] == "-" && tag.size > 1
|
||||
if tag =~ /\*/
|
||||
@ -854,9 +858,6 @@ class Tag < ApplicationRecord
|
||||
g2 = g2.downcase
|
||||
|
||||
order, suffix, _ = g2.partition(/_(asc|desc)\z/i)
|
||||
if order.in?(COUNT_METATAG_SYNONYMS)
|
||||
g2 = order.singularize + "_count" + suffix
|
||||
end
|
||||
|
||||
q[:order] = g2
|
||||
|
||||
@ -955,9 +956,8 @@ class Tag < ApplicationRecord
|
||||
when *COUNT_METATAGS
|
||||
q[g1.to_sym] = parse_helper(g2)
|
||||
|
||||
when *COUNT_METATAG_SYNONYMS
|
||||
g1 = "#{g1.singularize}_count"
|
||||
q[g1.to_sym] = parse_helper(g2)
|
||||
when *BOOLEAN_METATAGS
|
||||
q[g1.to_sym] = parse_boolean(g2)
|
||||
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user