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 boosted_category_id column and add to Algolia index. #748

Merged
merged 1 commit into from
Aug 15, 2024
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: 10 additions & 1 deletion app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Service < ActiveRecord::Base

belongs_to :resource, required: true, touch: true
belongs_to :program
belongs_to :boosted_category, class_name: 'Category'
has_many :notes, dependent: :destroy
has_many :feedbacks, dependent: :destroy
has_many :textings
Expand Down Expand Up @@ -37,7 +38,11 @@ class Service < ActiveRecord::Base
index_name: "#{Rails.configuration.x.algolia.index_prefix}_services_search",
id: :algolia_id do
# specify the list of attributes available for faceting
attributesForFaceting %i[categories open_times eligibilities associated_sites type]
attributesForFaceting %i[categories open_times eligibilities associated_sites type boosted_category]

# Default has "geo" before "filters", but we need it after if we want
# optional filters to have higher priority than distance.
ranking %w[typo words filters geo proximity attribute exact custom]

# Define attributes used to build an Algolia record
add_attribute :status
Expand Down Expand Up @@ -127,6 +132,10 @@ class Service < ActiveRecord::Base
categories.map(&:name)
end

add_attribute :boosted_category do
boosted_category&.name
end

add_attribute :use_resource_schedule

add_attribute :eligibilities do
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240804222349_add_boosted_category_to_services.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddBoostedCategoryToServices < ActiveRecord::Migration[6.1]
def change
add_reference :services, :boosted_category, foreign_key: { to_table: :categories }
end
end
5 changes: 4 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_07_02_155441) do
ActiveRecord::Schema.define(version: 2024_08_04_222349) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -418,6 +418,8 @@
t.integer "source_attribution", default: 0
t.text "internal_note"
t.string "short_description"
t.bigint "boosted_category_id"
t.index ["boosted_category_id"], name: "index_services_on_boosted_category_id"
t.index ["contact_id"], name: "index_services_on_contact_id"
t.index ["funding_id"], name: "index_services_on_funding_id"
t.index ["program_id"], name: "index_services_on_program_id"
Expand Down Expand Up @@ -521,6 +523,7 @@
add_foreign_key "schedule_days", "schedules"
add_foreign_key "schedules", "resources"
add_foreign_key "schedules", "services"
add_foreign_key "services", "categories", column: "boosted_category_id"
add_foreign_key "services", "contacts"
add_foreign_key "services", "fundings"
add_foreign_key "services", "programs"
Expand Down
Loading