diff --git a/app/models/crop.rb b/app/models/crop.rb index 0571feecd..89471f90f 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -76,6 +76,7 @@ class Crop < ActiveRecord::Base mappings dynamic: 'false' do indexes :id, type: 'long' indexes :name, type: 'string', analyzer: 'gs_edgeNGram_analyzer' + indexes :approval_status, type: 'string' indexes :scientific_names do indexes :scientific_name, type: 'string', @@ -92,7 +93,7 @@ class Crop < ActiveRecord::Base def as_indexed_json(options={}) self.as_json( - only: [:id, :name], + only: [:id, :name, :approval_status], include: { scientific_names: { only: :scientific_name }, alternate_names: { only: :name } @@ -311,6 +312,9 @@ class Crop < ActiveRecord::Base fields: ["name", "scientific_names.scientific_name", "alternate_names.name"] } }, + filter: { + term: {approval_status: "approved"} + }, size: 50 } ) diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index 9cda818e8..02f3149ae 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -342,6 +342,16 @@ describe Crop do it "searches case insensitively" do Crop.search('mUsH').should include @mushroom end + it "doesn't find 'rejected' crop" do + @mushroom.approval_status = "rejected" + sync_elasticsearch([@mushroom]) + Crop.search('mushroom').should_not include @mushroom + end + it "doesn't find 'pending' crop" do + @mushroom.approval_status = "pending" + sync_elasticsearch([@mushroom]) + Crop.search('mushroom').should_not include @mushroom + end end context "csv loading" do