search: move query parsing code from tag model to post query builder.

This commit is contained in:
evazion
2020-03-06 21:14:50 -06:00
parent 2e0ad42eca
commit 967d398c8e
13 changed files with 583 additions and 598 deletions

View File

@@ -522,11 +522,11 @@ class Post < ApplicationRecord
module TagMethods
def tag_array
@tag_array ||= Tag.scan_tags(tag_string)
@tag_array ||= PostQueryBuilder.scan_query(tag_string)
end
def tag_array_was
@tag_array_was ||= Tag.scan_tags(tag_string_in_database.presence || tag_string_before_last_save || "")
@tag_array_was ||= PostQueryBuilder.scan_query(tag_string_in_database.presence || tag_string_before_last_save || "")
end
def tags
@@ -590,7 +590,7 @@ class Post < ApplicationRecord
# then try to merge the tag changes together.
current_tags = tag_array_was
new_tags = tag_array
old_tags = Tag.scan_tags(old_tag_string)
old_tags = PostQueryBuilder.scan_query(old_tag_string)
kept_tags = current_tags & new_tags
@removed_tags = old_tags - kept_tags
@@ -627,7 +627,7 @@ class Post < ApplicationRecord
end
def normalize_tags
normalized_tags = Tag.scan_tags(tag_string)
normalized_tags = PostQueryBuilder.scan_query(tag_string)
normalized_tags = apply_casesensitive_metatags(normalized_tags)
normalized_tags = normalized_tags.map(&:downcase)
normalized_tags = filter_metatags(normalized_tags)
@@ -1058,7 +1058,7 @@ class Post < ApplicationRecord
tags = tags.to_s
tags += " rating:s" if CurrentUser.safe_mode?
tags += " -status:deleted" if CurrentUser.hide_deleted_posts? && !Tag.has_metatag?(tags, "status", "-status")
tags = Tag.normalize_query(tags)
tags = PostQueryBuilder.normalize_query(tags)
# Optimize some cases. these are just estimates but at these
# quantities being off by a few hundred doesn't matter much