Add ES mappings for plantings

This commit is contained in:
Brenda Wallace
2019-12-20 09:44:40 +13:00
parent 0c338e771c
commit 4c91da855c

View File

@@ -2,38 +2,45 @@ module PlantingSearch
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
searchkick searchkick merge_mappings: true,
mappings: {
properties: {
created_at: { type: :integer },
harvests_count: { type: :integer },
photos_count: { type: :integer }
}
}
scope :search_import, -> { includes(:owner, :crop) } scope :search_import, -> { includes(:owner, :crop) }
def search_data def search_data
{ {
slug: slug, slug: slug,
crop_slug: crop.slug, crop_slug: crop.slug,
crop_name: crop.name, crop_name: crop.name,
crop_id: crop_id, crop_id: crop_id,
owner_id: owner_id, owner_id: owner_id,
owner_name: owner.login_name, owner_name: owner.login_name,
owner_slug: owner.slug, owner_slug: owner.slug,
planted_from: planted_from, planted_from: planted_from,
photos_count: photos.size, photos_count: photos.size,
harvests_count: harvests.size, harvests_count: harvests.size,
has_photos: photos.size.positive?, has_photos: photos.size.positive?,
active: active?, active: active?,
thumbnail_url: default_photo&.thumbnail_url, thumbnail_url: default_photo&.thumbnail_url,
percentage_grown: percentage_grown.to_i, percentage_grown: percentage_grown.to_i,
created_at: created_at.to_i created_at: created_at.to_i
} }
end end
def self.homepage_records(limit) def self.homepage_records(limit)
search('*', search('*',
limit: limit, limit: limit,
where: { where: {
photos_count: { gt: 0 } photos_count: { gt: 0 }
}, },
boost_by: [:created_at], boost_by: [:created_at],
load: false) load: false)
end end
end end
end end