dtext links: allow searching for forum posts linking to specific tag.

This commit is contained in:
evazion
2019-10-27 01:05:54 -05:00
parent d946a84480
commit d617b20b49
7 changed files with 55 additions and 20 deletions

View File

@@ -3,7 +3,10 @@ class DtextLink < ApplicationRecord
enum link_type: [:wiki_link, :external_link]
before_validation :normalize_link_target
validates :link_target, uniqueness: { scope: [:model_type, :model_id] }
# validates :link_target, uniqueness: { scope: [:model_type, :model_id] }
scope :wiki_page, -> { where(model_type: "WikiPage") }
scope :forum_post, -> { where(model_type: "ForumPost") }
def self.new_from_dtext(dtext)
links = []
@@ -21,7 +24,7 @@ class DtextLink < ApplicationRecord
def self.model_matches(params)
return all if params.blank?
where(model_id: WikiPage.search(params).reorder(nil))
where(model_type: "WikiPage", model_id: WikiPage.search(params).reorder(nil))
end
def self.linked_wiki_exists(exists = true)
@@ -63,5 +66,9 @@ class DtextLink < ApplicationRecord
if wiki_link?
self.link_target = WikiPage.normalize_title(link_target)
end
# postgres will raise an error if the link is more than 2712 bytes long
# because it can't index values that take up more than 1/3 of an 8kb page.
self.link_target = self.link_target.truncate(2048, omission: "")
end
end