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:
evazion
2017-03-28 20:44:09 -05:00
parent 641f56dc2a
commit 0b63dd32d1
2 changed files with 16 additions and 7 deletions

View File

@@ -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

View File

@@ -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:".*?"/) || []