Skip to content

Commit

Permalink
Add new publicly_searchable attribute to status index (#6)
Browse files Browse the repository at this point in the history
* Add new publicly_searchable attr. to status index

* get rid of debug line

* Ruby linting

* Try to submit the request to sidekiq instead of doing in on the spot
  • Loading branch information
jsgoldstein committed Jul 12, 2023
1 parent 8d0c695 commit 97e8428
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
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

0 comments on commit 97e8428

Please sign in to comment.