Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new publicly_searchable attribute to status index #6

Merged
merged 4 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions app/chewy/statuses_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ class StatusesIndex < Chewy::Index
end

root date_detection: false do
field :id, type: 'long'
field :account_id, type: 'long'
field(:id, type: 'long')
field(:account_id, type: 'long')

field :text, type: 'text', value: ->(status) { status.searchable_text } do
field :stemmed, type: 'text', analyzer: 'content'
field(:text, type: 'text', value: ->(status) { status.searchable_text }) do
field(:stemmed, type: 'text', analyzer: 'content')
end

field :searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) }
field(:searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) })
field(:publicly_searchable, type: 'boolean', value: ->(status) { status.publicly_searchable? })
end
end
2 changes: 2 additions & 0 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Account < ApplicationRecord
include DomainMaterializable
include AccountMerging
include AccountSearch
include AccountStatusesSearch

enum protocol: { ostatus: 0, activitypub: 1 }
enum suspension_origin: { local: 0, remote: 1 }, _prefix: true
Expand Down Expand Up @@ -124,6 +125,7 @@ class Account < ApplicationRecord
scope :not_domain_blocked_by_account, ->(account) { where(arel_table[:domain].eq(nil).or(arel_table[:domain].not_in(account.excluded_from_timeline_domains))) }

after_update_commit :trigger_update_webhooks
after_update :update_statuses_index!, if: :saved_change_to_discoverable? and Chewy.enabled?

delegate :email,
:unconfirmed_email,
Expand Down
11 changes: 11 additions & 0 deletions app/models/concerns/account_statuses_search.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module AccountStatusesSearch
extend ActiveSupport::Concern

def update_statuses_index!
Chewy.strategy(:sidekiq) do
StatusesIndex.import(query: Status.where(account_id: id))
end
end
end
9 changes: 9 additions & 0 deletions app/models/concerns/status_search.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module StatusSearch
extend ActiveSupport::Concern

def publicly_searchable?
public_visibility? && account.discoverable?
end
end
1 change: 1 addition & 0 deletions app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Status < ApplicationRecord
include StatusSnapshotConcern
include RateLimitable
include StatusSafeReblogInsert
include StatusSearch

rate_limit by: :account, family: :statuses

Expand Down