Permalink
Browse files

removed search functionality since IndexTank shut down

  • Loading branch information...
1 parent 0f4c2d3 commit 86bef4d65efb41e7e7d6a6ea0e4cd2b9af08af49 @mislav committed Apr 27, 2012
Showing with 5 additions and 115 deletions.
  1. +0 −1 Gemfile
  2. +0 −5 Gemfile.lock
  3. +5 −49 app.rb
  4. +0 −55 models.rb
  5. +0 −5 views/help.haml
View
1 Gemfile
@@ -12,7 +12,6 @@ gem 'compass'
gem 'activesupport'
gem 'builder'
gem 'i18n'
-gem 'indextank'
gem 'will_paginate', '~> 3.0.0'
gem 'mingo'
gem 'activemodel'
View
5 Gemfile.lock
@@ -26,9 +26,6 @@ GEM
haml (3.0.25)
hashie (1.1.0)
i18n (0.5.0)
- indextank (1.0.12)
- faraday-stack
- yajl-ruby (>= 0.7.7)
mingo (0.4.2)
mongo (>= 1.3)
mongo (1.4.0)
@@ -53,7 +50,6 @@ GEM
rack (>= 1.0.0)
tilt (1.3.2)
will_paginate (3.0.0)
- yajl-ruby (0.8.2)
PLATFORMS
ruby
@@ -69,7 +65,6 @@ DEPENDENCIES
faraday-stack
haml
i18n
- indextank
mingo
mongo_ext
never-forget
View
54 app.rb
@@ -32,11 +32,6 @@
cache_location: File.join(ENV['TMPDIR'], 'sass-cache')
end
-set(:search_index) {
- search_client = IndexTank::Client.new(settings.indextank.api_url)
- search_client.indexes('idx')
-}
-
set(:cache_dir) { File.join(ENV['TMPDIR'], 'cache') }
Instagram.configure do |config|
@@ -81,10 +76,6 @@ def record(name)
ActiveSupport::Cache::Store.instrument = true
- ActiveSupport::Notifications.subscribe('search.indextank') do |name, start, ending, _, payload|
- $stderr.puts 'IndexTank search for "%s" (%.3f s)' % [payload[:query], ending - start]
- end
-
strip_params = %w[access_token client_id client_secret]
ActiveSupport::Notifications.subscribe('request.faraday') do |name, start, ending, _, payload|
@@ -116,24 +107,6 @@ def record(name)
set :logging, false
end
-FILTERS = {
- 1 => 'X-Pro II',
- 2 => 'Lomo-fi',
- 3 => 'Earlybird',
- 4 => 'Apollo',
- 5 => 'Poprocket',
- 10 => 'Inkwell',
- 13 => 'Gotham',
- 14 => '1977',
- 15 => 'Nashville',
- 16 => 'Lord Kelvin',
- 17 => 'Lily',
- 18 => 'Sutro',
- 19 => 'Toaster',
- 20 => 'Walden',
- 21 => 'Hefe'
-}
-
helpers do
def instalink(text)
text.sub(/\b(on instagram)\b/i, '<span>\1</span>').
@@ -332,14 +305,12 @@ def photos_by_tag(tag)
get '/search' do
@query = params[:q]
- @title = "#{@query}” on Instagram"
+ @title = "#{@query}tags on Instagram"
@tags = tag_search(@query)
-
- @filter_name = FILTERS[params[:filter].to_i]
- @photos = IndexedPhoto.paginate(@query, :page => params[:page], :filter => @filter_name)
+ @photos = []
expires 10.minutes, :public
- haml(request.xhr? ? :photos : :index)
+ haml :index
end
get '/tags/:tag' do
@@ -454,11 +425,7 @@ def photos_by_tag(tag)
- if root_path? or search_path?
%form{ action: '/search', method: 'get' }
%p
- %input{ type: 'search', name: 'q', placeholder: 'search photos', value: @query }
- %select{ name: 'filter' }
- %option{ value: '' } any filter
- - FILTERS.each do |code, name|
- %option{ value: code, selected: @filter_name == name }&= name
+ %input{ type: 'search', name: 'q', placeholder: 'search tags', value: @query }
%input{ type: 'submit', value: 'Search' }
- elsif @user
%p.stats
@@ -478,19 +445,9 @@ def photos_by_tag(tag)
%a{ href: "/tags/#{tag.name}" }== ##{tag.name}
%span== (#{tag.media_count})
- - if search_path?
- %p.stats
- == Found <b>#{@photos.total_entries}</b> items
- - if @filter_name
- == using the “#{@filter_name}” filter
-
%ol#photos
= haml :photos
-- if search_path?
- %p.footnote
- <strong>Note:</strong> search is limited &mdash; not all photos appear in the results.
-
%footer
%p
- unless root_path?
@@ -531,9 +488,8 @@ def photos_by_tag(tag)
%a{ href: "#close" } close
- if @photos.respond_to?(:next_page) ? @photos.next_page : (@photos.length >= (@per_page || 20) and not root_path?)
- - href = search_path? ? search_page(@photos.next_page) : request.path + "?max_id=#{@photos.last.id}"
%li.pagination
- %a{ href: href } <span>Load more &rarr;</span>
+ %a{ href: request.path + "?max_id=#{@photos.last.id}" } <span>Load more &rarr;</span>
@@ feed
schema_date = 2010
View
55 models.rb
@@ -1,5 +1,4 @@
require 'mingo'
-require 'indextank'
require 'will_paginate/collection'
require 'hashie/mash'
require 'net/http'
@@ -131,57 +130,3 @@ def get_url(url)
end
end
end
-
-# mimics Instagram::Media
-class IndexedPhoto < Struct.new(:id, :caption, :thumbnail_url, :large_url, :username, :taken_at, :filter_name)
- Fields = 'text,thumbnail_url,username,timestamp,big,filter'
-
- extend WillPaginate::PerPage
-
- self.per_page = 32
-
- def self.paginate(query, options)
- options = options.dup
- page = WillPaginate::PageNumber(options.fetch(:page) || 1)
- per_page = options.delete(:per_page) || self.per_page
- filter = options.delete(:filter)
- query = "#{query} AND filter:#{filter}" if filter
-
- WillPaginate::Collection.create(page, per_page) do |col|
- params = {:len => col.per_page, :start => col.offset, :fetch => Fields}.update(options)
- data = ActiveSupport::Notifications.instrument('search.indextank', {:query => query}.update(params)) do
- search_index.search(query, params)
- end
- col.total_entries = data['matches']
- col.replace data['results'].map { |item| new item }
- end
- end
-
- def self.search_index
- Sinatra::Application.settings.search_index
- end
-
- def initialize(hash)
- super hash['docid'], hash['text'], hash['thumbnail_url'], hash['big'],
- hash['username'], Time.at(hash['timestamp'].to_i), hash['filter']
- end
-
- User = Struct.new(:id, :full_name, :username)
- Caption = Struct.new(:text)
-
- def user
- @user ||= User.new(nil, nil, username)
- end
-
- def caption
- if text = super
- @caption ||= Caption.new(text)
- end
- end
-
- def images
- @images ||= Hashie::Mash.new \
- thumbnail: { url: thumbnail_url, width: 150, height: 150 },
- standard_resolution: { url: large_url, width: 612, height: 612 }
- end
-end
View
5 views/help.haml
@@ -35,8 +35,3 @@
Instagr.am permalink:
%input{ type: 'url', name: 'url', placeholder: 'http://instagr.am/p/..../' }
%input{ type: 'submit', value: 'Lookup' }
-
- %section
- %h2 Why don't some photos appear in search results?
-
- %p The search index is maintained by <a href="http://twitter.com/dbasch">Diego Basch</a> and includes only a subset of all media on Instagram because of technical limitations.

0 comments on commit 86bef4d

Please sign in to comment.