Skip to content
This repository has been archived by the owner on Oct 20, 2020. It is now read-only.

Commit

Permalink
removed search functionality since IndexTank shut down
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Apr 27, 2012
1 parent 0f4c2d3 commit 86bef4d
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 115 deletions.
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -12,7 +12,6 @@ gem 'compass'
gem 'activesupport' gem 'activesupport'
gem 'builder' gem 'builder'
gem 'i18n' gem 'i18n'
gem 'indextank'
gem 'will_paginate', '~> 3.0.0' gem 'will_paginate', '~> 3.0.0'
gem 'mingo' gem 'mingo'
gem 'activemodel' gem 'activemodel'
Expand Down
5 changes: 0 additions & 5 deletions Gemfile.lock
Expand Up @@ -26,9 +26,6 @@ GEM
haml (3.0.25) haml (3.0.25)
hashie (1.1.0) hashie (1.1.0)
i18n (0.5.0) i18n (0.5.0)
indextank (1.0.12)
faraday-stack
yajl-ruby (>= 0.7.7)
mingo (0.4.2) mingo (0.4.2)
mongo (>= 1.3) mongo (>= 1.3)
mongo (1.4.0) mongo (1.4.0)
Expand All @@ -53,7 +50,6 @@ GEM
rack (>= 1.0.0) rack (>= 1.0.0)
tilt (1.3.2) tilt (1.3.2)
will_paginate (3.0.0) will_paginate (3.0.0)
yajl-ruby (0.8.2)


PLATFORMS PLATFORMS
ruby ruby
Expand All @@ -69,7 +65,6 @@ DEPENDENCIES
faraday-stack faraday-stack
haml haml
i18n i18n
indextank
mingo mingo
mongo_ext mongo_ext
never-forget never-forget
Expand Down
54 changes: 5 additions & 49 deletions app.rb
Expand Up @@ -32,11 +32,6 @@
cache_location: File.join(ENV['TMPDIR'], 'sass-cache') cache_location: File.join(ENV['TMPDIR'], 'sass-cache')
end 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') } set(:cache_dir) { File.join(ENV['TMPDIR'], 'cache') }


Instagram.configure do |config| Instagram.configure do |config|
Expand Down Expand Up @@ -81,10 +76,6 @@ def record(name)


ActiveSupport::Cache::Store.instrument = true 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] strip_params = %w[access_token client_id client_secret]


ActiveSupport::Notifications.subscribe('request.faraday') do |name, start, ending, _, payload| ActiveSupport::Notifications.subscribe('request.faraday') do |name, start, ending, _, payload|
Expand Down Expand Up @@ -116,24 +107,6 @@ def record(name)
set :logging, false set :logging, false
end 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 helpers do
def instalink(text) def instalink(text)
text.sub(/\b(on instagram)\b/i, '<span>\1</span>'). text.sub(/\b(on instagram)\b/i, '<span>\1</span>').
Expand Down Expand Up @@ -332,14 +305,12 @@ def photos_by_tag(tag)


get '/search' do get '/search' do
@query = params[:q] @query = params[:q]
@title = "“#{@query}” on Instagram" @title = "“#{@query}tags on Instagram"
@tags = tag_search(@query) @tags = tag_search(@query)

@photos = []
@filter_name = FILTERS[params[:filter].to_i]
@photos = IndexedPhoto.paginate(@query, :page => params[:page], :filter => @filter_name)


expires 10.minutes, :public expires 10.minutes, :public
haml(request.xhr? ? :photos : :index) haml :index
end end


get '/tags/:tag' do get '/tags/:tag' do
Expand Down Expand Up @@ -454,11 +425,7 @@ def photos_by_tag(tag)
- if root_path? or search_path? - if root_path? or search_path?
%form{ action: '/search', method: 'get' } %form{ action: '/search', method: 'get' }
%p %p
%input{ type: 'search', name: 'q', placeholder: 'search photos', value: @query } %input{ type: 'search', name: 'q', placeholder: 'search tags', value: @query }
%select{ name: 'filter' }
%option{ value: '' } any filter
- FILTERS.each do |code, name|
%option{ value: code, selected: @filter_name == name }&= name
%input{ type: 'submit', value: 'Search' } %input{ type: 'submit', value: 'Search' }
- elsif @user - elsif @user
%p.stats %p.stats
Expand All @@ -478,19 +445,9 @@ def photos_by_tag(tag)
%a{ href: "/tags/#{tag.name}" }== ##{tag.name} %a{ href: "/tags/#{tag.name}" }== ##{tag.name}
%span== (#{tag.media_count}) %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 %ol#photos
= haml :photos = haml :photos


- if search_path?
%p.footnote
<strong>Note:</strong> search is limited &mdash; not all photos appear in the results.

%footer %footer
%p %p
- unless root_path? - unless root_path?
Expand Down Expand Up @@ -531,9 +488,8 @@ def photos_by_tag(tag)
%a{ href: "#close" } close %a{ href: "#close" } close


- if @photos.respond_to?(:next_page) ? @photos.next_page : (@photos.length >= (@per_page || 20) and not root_path?) - 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 %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 @@ feed
schema_date = 2010 schema_date = 2010
Expand Down
55 changes: 0 additions & 55 deletions models.rb
@@ -1,5 +1,4 @@
require 'mingo' require 'mingo'
require 'indextank'
require 'will_paginate/collection' require 'will_paginate/collection'
require 'hashie/mash' require 'hashie/mash'
require 'net/http' require 'net/http'
Expand Down Expand Up @@ -131,57 +130,3 @@ def get_url(url)
end end
end 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
5 changes: 0 additions & 5 deletions views/help.haml
Expand Up @@ -35,8 +35,3 @@
Instagr.am permalink: Instagr.am permalink:
%input{ type: 'url', name: 'url', placeholder: 'http://instagr.am/p/..../' } %input{ type: 'url', name: 'url', placeholder: 'http://instagr.am/p/..../' }
%input{ type: 'submit', value: 'Lookup' } %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.