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
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) }
def search_data
{
slug: slug,
crop_slug: crop.slug,
crop_name: crop.name,
crop_id: crop_id,
owner_id: owner_id,
owner_name: owner.login_name,
owner_slug: owner.slug,
planted_from: planted_from,
photos_count: photos.size,
harvests_count: harvests.size,
has_photos: photos.size.positive?,
active: active?,
thumbnail_url: default_photo&.thumbnail_url,
slug: slug,
crop_slug: crop.slug,
crop_name: crop.name,
crop_id: crop_id,
owner_id: owner_id,
owner_name: owner.login_name,
owner_slug: owner.slug,
planted_from: planted_from,
photos_count: photos.size,
harvests_count: harvests.size,
has_photos: photos.size.positive?,
active: active?,
thumbnail_url: default_photo&.thumbnail_url,
percentage_grown: percentage_grown.to_i,
created_at: created_at.to_i
created_at: created_at.to_i
}
end
def self.homepage_records(limit)
search('*',
limit: limit,
where: {
limit: limit,
where: {
photos_count: { gt: 0 }
},
boost_by: [:created_at],
load: false)
load: false)
end
end
end