Standardize it so that all fields of type `text` are searchable with `search[<field>_matches]`. Before, the `<field>_matches` param was handled manually and some fields were left out or handled inconsistently. Now it applies to all columns of type `text`. This does a full-text search on the field, so for example, searching `/artist_commentaries?search[translated_description_matches]=smiling` will match translated commentaries containing either the word "smiling", "smiles", "smiled", or "smile". Note that this only applies to columns defined as type `text`, not to columns defined as `character varying`. The difference is that `text` is used for fields containing free-form natural language, such as comments, notes, forum posts, wiki pages, pool descriptions, etc, while `character varying` is used for short strings not containing free-form language, such as tag names, wiki page titles, urls, status fields, etc. API changes: * Add the `search[original_title_matches]`, `search[original_description_matches]`, `search[translated_title_matches]`, `search[translated_description_matches]` params to /artist_commentaries and /artist_commentary_versions. * Remove the `search[name_matches]` and `search[group_name_matches]` params from /artist_versions. * Remove the `search[title_matches]` param from /wiki_page_versions. * Change the `search[name_matches]` param on /pools, /favorite_groups, and /pool_versions to do a full-text search instead of a substring match.
66 lines
1.4 KiB
Ruby
66 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class NoteVersion < ApplicationRecord
|
|
belongs_to :post
|
|
belongs_to :note
|
|
belongs_to_updater :counter_cache => "note_update_count"
|
|
|
|
def self.search(params)
|
|
q = search_attributes(params, :id, :created_at, :updated_at, :is_active, :x, :y, :width, :height, :body, :version, :updater, :note, :post)
|
|
|
|
q.apply_default_order(params)
|
|
end
|
|
|
|
def previous
|
|
@previous ||= NoteVersion.where("note_id = ? and version < ?", note_id, version).order("updated_at desc").limit(1).to_a
|
|
@previous.first
|
|
end
|
|
|
|
def current
|
|
@current ||= NoteVersion.where(note_id: note_id).order("updated_at desc").limit(1).to_a
|
|
@current.first
|
|
end
|
|
|
|
def self.status_fields
|
|
{
|
|
body: "Body",
|
|
was_moved: "Moved",
|
|
was_resized: "Resized",
|
|
was_deleted: "Deleted",
|
|
was_undeleted: "Undeleted",
|
|
}
|
|
end
|
|
|
|
def was_moved(type)
|
|
other = send(type)
|
|
x != other.x || y != other.y
|
|
end
|
|
|
|
def was_resized(type)
|
|
other = send(type)
|
|
width != other.width || height != other.height
|
|
end
|
|
|
|
def was_deleted(type)
|
|
other = send(type)
|
|
if type == "previous"
|
|
!is_active && other.is_active
|
|
else
|
|
is_active && !other.is_active
|
|
end
|
|
end
|
|
|
|
def was_undeleted(type)
|
|
other = send(type)
|
|
if type == "previous"
|
|
is_active && !other.is_active
|
|
else
|
|
!is_active && other.is_active
|
|
end
|
|
end
|
|
|
|
def self.available_includes
|
|
[:updater, :note, :post]
|
|
end
|
|
end
|