Add mappings on crop search

This commit is contained in:
Brenda Wallace
2019-12-20 09:33:23 +13:00
parent c0103a3f42
commit 18cb218807
2 changed files with 20 additions and 15 deletions

View File

@@ -4,12 +4,15 @@ module CropSearch
included do
####################################
# Elastic search configuration
searchkick word_start: %i(name description alternate_names scientific_names),
searchkick word_start: %i(name description alternate_names scientific_names),
case_sensitive: false,
merge_mappings: true,
mappings: {
mappings: {
properties: {
created_at: { type: :integer }
created_at: { type: :integer },
plantings_count: { type: :integer },
harvests_count: { type: :integer },
photos_count: { type: :integer }
}
}
@@ -22,21 +25,21 @@ module CropSearch
def search_data
{
name: name,
description: description,
slug: slug,
alternate_names: alternate_names.pluck(:name),
name: name,
description: description,
slug: slug,
alternate_names: alternate_names.pluck(:name),
scientific_names: scientific_names.pluck(:name),
photos_count: photo_associations_count,
photos_count: photo_associations_count,
# boost the crops that are planted the most
plantings_count: plantings_count,
harvests_count: harvests_count,
plantings_count: plantings_count,
harvests_count: harvests_count,
# boost this crop for these members
planters_ids: plantings.pluck(:owner_id),
has_photos: photos.size.positive?,
thumbnail_url: default_photo&.thumbnail_url,
scientific_name: default_scientific_name&.name,
created_at: created_at.to_i
planters_ids: plantings.pluck(:owner_id),
has_photos: photos.size.positive?,
thumbnail_url: default_photo&.thumbnail_url,
scientific_name: default_scientific_name&.name,
created_at: created_at.to_i
}
end
end

View File

@@ -2,11 +2,13 @@ require 'rails_helper'
describe 'Crops RSS feed' do
it 'The index feed exists' do
Crop.reindex
visit crops_path(format: 'rss')
# expect(page.status_code).to equal 200
end
it 'The index title is what we expect' do
Crop.reindex
visit crops_path(format: 'rss')
expect(page).to have_content "Recently added crops (#{ENV['GROWSTUFF_SITE_NAME']})"
end