Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Index countries.

  • Loading branch information...
commit b9d05e52a7d286923fc47cab1422b002e18a74ac 1 parent 7b7a2f9
@threedaymonk threedaymonk authored
View
8 app/models/country.rb
@@ -53,4 +53,12 @@ def bounding_box_array
bounding_box.try(:split, ',')
end
+ def indexable_content
+ sections = raw_travel_advice && raw_travel_advice["travel_advice_sections"]
+ return "" unless sections
+ sections.inject(missions.map(&:address)) { |acc, advice|
+ acc.concat([advice["title"], advice["body"]["plain"]])
+ }.join(" ")
+ end
+
end
View
8 lib/tasks/rummager.rake
@@ -1,7 +1,13 @@
namespace :rummager do
desc "Reindex search engine"
task :index => :environment do
- documents = []
+ documents = Country.all.map { |country| {
+ "title" => country.name,
+ "description" => "",
+ "format" => "fco",
+ "link" => "/travel-advice/countries/#{country.slug}",
+ "indexable_content" => country.indexable_content
+ }}
Rummageable.index documents
end
end
View
49 test/unit/country_test.rb
@@ -27,4 +27,53 @@ def valid_attributes
assert !Country.new(valid_attributes.except(:iso_3166_1)).valid?
end
+ test 'should include title of advice in indexable_content' do
+ country = Country.new(raw_travel_advice: {
+ "travel_advice_sections" => [{
+ "title" => "SECTION_TITLE_1",
+ "body" => {"plain" => "SECTION_BODY_1"}
+ }, {
+ "title" => "SECTION_TITLE_2",
+ "body" => {"plain" => "SECTION_BODY_2"}
+ }]
+ })
+
+ indexable_content = country.indexable_content
+ assert_match %r{\bSECTION_TITLE_1\b}, indexable_content
+ assert_match %r{\bSECTION_TITLE_2\b}, indexable_content
+ end
+
+ test 'should include plain text of advice in indexable_content' do
+ country = Country.new(raw_travel_advice: {
+ "travel_advice_sections" => [{
+ "title" => "SECTION_TITLE_1",
+ "body" => {"plain" => "SECTION_BODY_1"}
+ }, {
+ "title" => "SECTION_TITLE_2",
+ "body" => {"plain" => "SECTION_BODY_2"}
+ }]
+ })
+
+ indexable_content = country.indexable_content
+ assert_match %r{\bSECTION_BODY_1\b}, indexable_content
+ assert_match %r{\bSECTION_BODY_2\b}, indexable_content
+ end
+
+ test 'should include mission addresses in indexable_content' do
+ country = Country.new(raw_travel_advice: {"travel_advice_sections" => []})
+ country.missions.build(address: "ADDRESS")
+
+ indexable_content = country.indexable_content
+ assert_match %r{\bADDRESS\b}, indexable_content
+ end
+
+ test 'should return empty indexable_content if raw_travel_advice is nil' do
+ country = Country.new(raw_travel_advice: nil)
+ assert_equal "", country.indexable_content
+ end
+
+ test 'should return empty indexable_content if travel_advice_sections is missing' do
+ country = Country.new(raw_travel_advice: {})
+ assert_equal "", country.indexable_content
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.