wiki pages: fix title normalization.
Fix inconsistent title normalization. Strip whitespace and underscores from the ends of the title and strip consecutive underscores.
This commit is contained in:
@@ -22,7 +22,7 @@ class WikiPage < ApplicationRecord
|
|||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
def titled(title)
|
def titled(title)
|
||||||
where("title = ?", title.mb_chars.downcase.tr(" ", "_"))
|
where(title: normalize_title(title))
|
||||||
end
|
end
|
||||||
|
|
||||||
def active
|
def active
|
||||||
@@ -59,7 +59,7 @@ class WikiPage < ApplicationRecord
|
|||||||
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index, ts_config: "danbooru")
|
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index, ts_config: "danbooru")
|
||||||
|
|
||||||
if params[:title].present?
|
if params[:title].present?
|
||||||
q = q.where("title LIKE ? ESCAPE E'\\\\'", params[:title].mb_chars.downcase.strip.tr(" ", "_").to_escaped_for_sql_like)
|
q = q.where_like(:title, normalize_title(params[:title]))
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:other_names_match].present?
|
if params[:other_names_match].present?
|
||||||
@@ -127,8 +127,12 @@ class WikiPage < ApplicationRecord
|
|||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.normalize_title(title)
|
||||||
|
title.downcase.gsub(/[[:space:]]+/, "_").gsub(/__/, "_").gsub(/\A_|_\z/, "")
|
||||||
|
end
|
||||||
|
|
||||||
def normalize_title
|
def normalize_title
|
||||||
self.title = title.mb_chars.downcase.tr(" ", "_")
|
self.title = WikiPage.normalize_title(title)
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize_other_names
|
def normalize_other_names
|
||||||
|
|||||||
Reference in New Issue
Block a user