mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-02-02 13:41:00 -05:00
Add ES mappings for plantings
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user