saved searches: don't change tag ordering within queries.
Normalize queries aside from the tag ordering when they're saved. Normalize queries including ordering when they're sent to listbooru. This way tag ordering within searches is kept in the /saved_searches listing.
This commit is contained in:
@@ -74,14 +74,18 @@ class SavedSearch < ActiveRecord::Base
|
||||
|
||||
def self.queries_for(user_id, label = nil, options = {})
|
||||
if label
|
||||
SavedSearch.where(user_id: user_id).labeled(label).pluck("distinct query")
|
||||
SavedSearch.where(user_id: user_id).labeled(label).map(&:normalized_query).sort.uniq
|
||||
else
|
||||
SavedSearch.where(user_id: user_id).pluck("distinct query")
|
||||
SavedSearch.where(user_id: user_id).map(&:normalized_query).sort.uniq
|
||||
end
|
||||
end
|
||||
|
||||
def normalized_query
|
||||
Tag.normalize_query(query, sort: true)
|
||||
end
|
||||
|
||||
def normalize
|
||||
self.query = query_array.sort.join(" ")
|
||||
self.query = Tag.normalize_query(query, sort: false)
|
||||
self.labels = labels.map {|x| SavedSearch.normalize_label(x)}.reject {|x| x.blank?}
|
||||
end
|
||||
|
||||
@@ -103,10 +107,6 @@ class SavedSearch < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def query_array
|
||||
Tag.scan_tags(query)
|
||||
end
|
||||
|
||||
def label_string
|
||||
labels.join(" ")
|
||||
end
|
||||
|
||||
@@ -236,6 +236,15 @@ class Tag < ActiveRecord::Base
|
||||
query.to_s.gsub(/\u3000/, " ").strip
|
||||
end
|
||||
|
||||
def normalize_query(query, sort: true)
|
||||
tags = Tag.scan_query(query.to_s)
|
||||
tags = tags.map { |t| Tag.normalize_name(t) }
|
||||
tags = TagAlias.to_aliased(tags)
|
||||
tags = tags.sort if sort
|
||||
tags = tags.uniq
|
||||
tags.join(" ")
|
||||
end
|
||||
|
||||
def scan_query(query)
|
||||
tagstr = normalize(query)
|
||||
list = tagstr.scan(/-?source:".*?"/) || []
|
||||
|
||||
Reference in New Issue
Block a user