docbrown/app/models/concerns/algolia_searchable/searchable_article.rb
Ben Halpern b3b0eafe76
Implement MVP frontend for Algolia search (#20909)
* Add proper frontend for Algolia search

* Update app/models/concerns/algolia_searchable/searchable_comment.rb

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update app/models/concerns/algolia_searchable/searchable_article.rb

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Fix formatting

* Fix: copy to clipboard message (#20898)

* fix: copy to clipboard message

* chore: deletion of unused imports

* Pick winner in header field test (#20911)

* Updated the twitter icon to X icon - solved icon issue #20356  (#20910)

* changed the twitter icon to X icon in assets/images/twitter.svg

* Changed the twitter icon to X in assets/images/twitter.svg

* Add field test for Digest article list design (#20912)

* Add field test for Digest article list design

* Add check for cached user

* Include cached user in select (#20913)

* Include cached user in select

* Add tags

* update style for new follower email (#20908)

* Fix #19037 (#20917)

* Add alternate returns for html

* Remove console log

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Iasmim Pereira <100351576+IasmimCristina@users.noreply.github.com>
Co-authored-by: Darshan Padia <darshanpadia5@gmail.com>
Co-authored-by: Philip How <philip.j.how@gmail.com>
2024-05-06 15:20:53 -04:00

42 lines
1.3 KiB
Ruby

module AlgoliaSearchable
module SearchableArticle
extend ActiveSupport::Concern
included do
include AlgoliaSearch
algoliasearch(**DEFAULT_ALGOLIA_SETTINGS, if: :indexable) do
attribute :user do
{ name: user.name,
username: user.username,
profile_image: user.profile_image_90,
id: user.id,
profile_image_90: user.profile_image_90 }
end
attribute :title, :tag_list, :reading_time, :score, :featured, :comments_count,
:positive_reactions_count, :path, :main_image, :user_id
add_attribute(:published_at) { published_at.to_i }
add_attribute(:readable_publish_date) { readable_publish_date }
add_attribute(:timestamp) { published_at.to_i }
add_replica("Article_timestamp_desc", per_environment: true) { customRanking ["desc(timestamp)"] }
add_replica("Article_timestamp_asc", per_environment: true) { customRanking ["asc(timestamp)"] }
end
end
class_methods do
def trigger_sidekiq_worker(record, delete)
AlgoliaSearch::SearchIndexWorker.perform_async(record.class.name, record.id, delete)
end
end
def indexable
published && score.positive?
end
def indexable_changed?
published_changed? || score_changed?
end
end
end