Fix #4406: Add "commentary:" metasearch.

Add:

* commentary:true (posts with commentary)
* commentary:false (posts without commentary)
* commentary:translated (posts with translated commentary)
* commentary:untranslated (posts with untranslated commentary)
* commentary:"text" (posts where any commentary field matches "text")

Known issues:

* There's no way to escape the true, false, translated, or
  untranslated keywords to do a literal text search for commentaries
  containing one of these keywords.

* Negated searches may be slow. Using a left outer join instead of a
  subquery would be faster in most cases, but negating it is harder.
This commit is contained in:
evazion
2020-04-16 23:53:04 -05:00
parent 9901161bbf
commit e848011080
4 changed files with 72 additions and 10 deletions

View File

@@ -11,6 +11,15 @@ class ArtistCommentary < ApplicationRecord
after_save :create_version
after_commit :tag_post
scope :original_absent, -> { where(original_title: "").where(original_description: "") }
scope :original_present, -> { where.not(original_title: "").or(where.not(original_description: "")) }
scope :translation_absent, -> { where(translated_title: "").where(translated_description: "") }
scope :translation_present, -> { where.not(translated_title: "").or(where.not(translated_description: "")) }
scope :translated, -> { original_present.translation_present }
scope :untranslated, -> { original_present.translation_absent }
scope :deleted, -> { original_absent.translation_absent }
scope :undeleted, -> { original_present.or(translation_present) }
module SearchMethods
def text_matches(query)
query = "*#{query}*" unless query =~ /\*/
@@ -21,14 +30,6 @@ class ArtistCommentary < ApplicationRecord
.or(where_ilike(:translated_description, query))
end
def deleted
where(original_title: "", original_description: "", translated_title: "", translated_description: "")
end
def undeleted
where("original_title != '' OR original_description != '' OR translated_title != '' OR translated_description != ''")
end
def search(params)
q = super