Permalink
Browse files

[Fixes #79207690] Fix indexing of photos with "circa" dates

  • Loading branch information...
loren committed Sep 19, 2014
1 parent e71eaff commit f7b577c21daed4ac5b00711a70028602c4117d72
Showing with 20 additions and 1 deletion.
  1. +5 −1 app/workers/flickr_photos_importer.rb
  2. +15 −0 spec/workers/flickr_photos_importer_spec.rb
@@ -54,7 +54,7 @@ def store_photos(photos, profile_type)
def store_photo(photo, profile_type)
tags = photo.tags.try(:split) || []
attributes = { id: photo.id, owner: photo.owner, profile_type: profile_type, tags: strip_irrelevant_tags(tags),
title: photo.title.squish, description: photo.description.squish, taken_at: photo.datetaken,
title: photo.title.squish, description: photo.description.squish, taken_at: normalize_date(photo.datetaken),
popularity: photo.views, url: flickr_url(photo.owner, photo.id), thumbnail_url: photo.url_q }
FlickrPhoto.create(attributes, { op_type: 'create' })
rescue Elasticsearch::Transport::Transport::Errors::Conflict => e
@@ -79,4 +79,8 @@ def strip_irrelevant_tags(tags)
tags.reject { |tag| tag.include?(':') }
end
def normalize_date(datetaken)
datetaken.gsub("-00","-01")
end
end
@@ -85,6 +85,21 @@
end
end
context 'when photo contains datetaken with zero month or day' do
before do
photo1 = Hashie::Mash.new(id: "photo1", owner: "owner1", profile_type: 'user', tags: "tag2", title: "title1", description: "description1", datetaken: "2014-00-00 00:00:00", views: 100, url_o: "http://photo1", url_q: "http://photo_thumbnail1", dateupload: 9.days.ago.to_i)
batch1_photos = [photo1]
allow(batch1_photos).to receive(:pages).and_return(1)
allow(importer).to receive(:get_photos).with("flickr id", "user", { per_page: FlickrPhotosImporter::MAX_PHOTOS_PER_REQUEST, extras: FlickrPhotosImporter::EXTRA_FIELDS, page: 1 }).and_return(batch1_photos)
end
it "should assign zero month as January and zero day as one" do
importer.perform('flickr id', 'user')
first = FlickrPhoto.find("photo1")
expect(first.taken_at).to eq(Date.parse("2014-01-01"))
end
end
context 'when title/desc contain leading/trailing spaces' do
before do
photo1 = Hashie::Mash.new(id: "photo1", owner: "owner1", profile_type: 'user', tags: "tag1 tag2", title: " title1 ", description: " ", datetaken: "2014-07-09 12:34:56", views: 100, url_o: "http://photo1", url_q: "http://photo_thumbnail1", dateupload: 9.days.ago.to_i)

0 comments on commit f7b577c

Please sign in to comment.