diff --git a/app/models/service.rb b/app/models/service.rb index 01269ec5..12497e1f 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -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 @@ -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 @@ -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 diff --git a/db/migrate/20240804222349_add_boosted_category_to_services.rb b/db/migrate/20240804222349_add_boosted_category_to_services.rb new file mode 100644 index 00000000..b9da0c2b --- /dev/null +++ b/db/migrate/20240804222349_add_boosted_category_to_services.rb @@ -0,0 +1,5 @@ +class AddBoostedCategoryToServices < ActiveRecord::Migration[6.1] + def change + add_reference :services, :boosted_category, foreign_key: { to_table: :categories } + end +end diff --git a/db/schema.rb b/db/schema.rb index 79d17df0..5b9029a8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -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" @@ -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"